Skip to content

Commit

Permalink
nixos/update-users-groups: fix cross compilation
Browse files Browse the repository at this point in the history
Since #246772, cross compiled NixOS is broken because the DateTime perl
package that was used in the update-users-groups.pl script depends on
Testutf8 which does not cross compile (see #198548).

This PR drops the DateTime dependency in favour of TimePiece, which has
less dependencies and whose closure does cross compile.
  • Loading branch information
r-vdp authored and Mic92 committed Sep 3, 2023
1 parent 0b39810 commit d560a5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
15 changes: 3 additions & 12 deletions nixos/modules/config/update-users-groups.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use File::Slurp;
use Getopt::Long;
use JSON;
use DateTime;
use Time::Piece;

# Keep track of deleted uids and gids.
my $uidMapFile = "/var/lib/nixos/uid-map";
Expand All @@ -26,17 +26,8 @@ sub updateFile {
# Converts an ISO date to number of days since 1970-01-01
sub dateToDays {
my ($date) = @_;
my ($year, $month, $day) = split('-', $date, -3);
my $dt = DateTime->new(
year => $year,
month => $month,
day => $day,
hour => 0,
minute => 0,
second => 0,
time_zone => 'UTC',
);
return $dt->epoch / 86400;
my $time = Time::Piece->strptime($date, "%Y-%m-%d");
return $time->epoch / 60 / 60 / 24;
}

sub nscdInvalidate {
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/config/users-groups.nix
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ in {
install -m 0700 -d /root
install -m 0755 -d /home
${pkgs.perl.withPackages (p: [ p.FileSlurp p.JSON p.DateTime ])}/bin/perl \
${pkgs.perl.withPackages (p: [ p.FileSlurp p.JSON p.TimePiece ])}/bin/perl \
-w ${./update-users-groups.pl} ${spec}
'';
};
Expand Down

0 comments on commit d560a5e

Please sign in to comment.