environment.etc: add user/group option

fixes #27546

Volth faac0186 6f2715e4

Changed files
+31 -9
nixos
modules
+1 -1
nixos/modules/config/users-groups.nix
···
input.gid = ids.gids.input;
};
-
system.activationScripts.users = stringAfter [ "etc" ]
+
system.activationScripts.users = stringAfter [ "stdio" ]
''
${pkgs.perl}/bin/perl -w \
-I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl \
+23 -3
nixos/modules/system/etc/etc.nix
···
sources = map (x: x.source) etc';
targets = map (x: x.target) etc';
modes = map (x: x.mode) etc';
-
uids = map (x: x.uid) etc';
-
gids = map (x: x.gid) etc';
+
users = map (x: x.user) etc';
+
groups = map (x: x.group) etc';
};
in
···
'';
};
+
user = mkOption {
+
default = "+${toString config.uid}";
+
type = types.str;
+
description = ''
+
User name of created file.
+
Only takes affect when the file is copied (that is, the mode is not 'symlink').
+
Changing this option takes precedence over <literal>uid</literal>.
+
'';
+
};
+
+
group = mkOption {
+
default = "+${toString config.gid}";
+
type = types.str;
+
description = ''
+
Group name of created file.
+
Only takes affect when the file is copied (that is, the mode is not 'symlink').
+
Changing this option takes precedence over <literal>gid</literal>.
+
'';
+
};
+
};
config = {
···
system.build.etc = etc;
-
system.activationScripts.etc = stringAfter [ "stdio" ]
+
system.activationScripts.etc = stringAfter [ "users" "groups" ]
''
# Set up the statically computed bits of /etc.
echo "setting up /etc..."
+5 -5
nixos/modules/system/etc/make-etc.sh
···
sources_=($sources)
targets_=($targets)
modes_=($modes)
-
uids_=($uids)
-
gids_=($gids)
+
users_=($users)
+
groups_=($groups)
set +f
for ((i = 0; i < ${#targets_[@]}; i++)); do
···
fi
if test "${modes_[$i]}" != symlink; then
-
echo "${modes_[$i]}" > $out/etc/$target.mode
-
echo "${uids_[$i]}" > $out/etc/$target.uid
-
echo "${gids_[$i]}" > $out/etc/$target.gid
+
echo "${modes_[$i]}" > $out/etc/$target.mode
+
echo "${users_[$i]}" > $out/etc/$target.uid
+
echo "${groups_[$i]}" > $out/etc/$target.gid
fi
fi
+2
nixos/modules/system/etc/setup-etc.pl
···
my $uid = read_file("$_.uid"); chomp $uid;
my $gid = read_file("$_.gid"); chomp $gid;
copy "$static/$fn", "$target.tmp" or warn;
+
$uid = getpwnam $uid unless $uid =~ /^\+/;
+
$gid = getgrnam $gid unless $gid =~ /^\+/;
chown int($uid), int($gid), "$target.tmp" or warn;
chmod oct($mode), "$target.tmp" or warn;
rename "$target.tmp", $target or warn;