git.iko.soy/typeable/nixpkgs
on master help sign in
environment.etc: add user/group option

fixes #27546

commitfaac018630b8d3f89c633c1235ae649498c938e8 authorVolth <volth@webmaster.ms> dateFri 21 Jul 2017, 14:41 (9 years ago) parent6f2715e
4 files changed+31−9
nixos/modules/config/users-groups.nix+1−1 nixos/modules/system/etc/etc.nix+23−3 nixos/modules/system/etc/make-etc.sh+5−5 nixos/modules/system/etc/setup-etc.pl+2
nixos/modules/config/users-groups.nix+1−1
@@ -527,7 +527,7 @@ in {
527527 input.gid = ids.gids.input;
528528 };
529529
530− system.activationScripts.users = stringAfter [ "etc" ]
530+ system.activationScripts.users = stringAfter [ "stdio" ]
531531 ''
532532 ${pkgs.perl}/bin/perl -w \
533533 -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl \
nixos/modules/system/etc/etc.nix+23−3
@@ -20,8 +20,8 @@ let
2020 sources = map (x: x.source) etc';
2121 targets = map (x: x.target) etc';
2222 modes = map (x: x.mode) etc';
23− uids = map (x: x.uid) etc';
24− gids = map (x: x.gid) etc';
23+ users = map (x: x.user) etc';
24+ groups = map (x: x.group) etc';
2525 };
2626
2727in
@@ -108,6 +108,26 @@ in
108108 '';
109109 };
110110
111+ user = mkOption {
112+ default = "+${toString config.uid}";
113+ type = types.str;
114+ description = ''
115+ User name of created file.
116+ Only takes affect when the file is copied (that is, the mode is not 'symlink').
117+ Changing this option takes precedence over <literal>uid</literal>.
118+ '';
119+ };
120+
121+ group = mkOption {
122+ default = "+${toString config.gid}";
123+ type = types.str;
124+ description = ''
125+ Group name of created file.
126+ Only takes affect when the file is copied (that is, the mode is not 'symlink').
127+ Changing this option takes precedence over <literal>gid</literal>.
128+ '';
129+ };
130+
111131 };
112132
113133 config = {
@@ -130,7 +150,7 @@ in
130150
131151 system.build.etc = etc;
132152
133− system.activationScripts.etc = stringAfter [ "stdio" ]
153+ system.activationScripts.etc = stringAfter [ "users" "groups" ]
134154 ''
135155 # Set up the statically computed bits of /etc.
136156 echo "setting up /etc..."
nixos/modules/system/etc/make-etc.sh+5−5
@@ -6,8 +6,8 @@ set -f
66sources_=($sources)
77targets_=($targets)
88modes_=($modes)
9−uids_=($uids)
10−gids_=($gids)
9+users_=($users)
10+groups_=($groups)
1111set +f
1212
1313for ((i = 0; i < ${#targets_[@]}; i++)); do
@@ -36,9 +36,9 @@ for ((i = 0; i < ${#targets_[@]}; i++)); do
3636 fi
3737
3838 if test "${modes_[$i]}" != symlink; then
39− echo "${modes_[$i]}" > $out/etc/$target.mode
40− echo "${uids_[$i]}" > $out/etc/$target.uid
41− echo "${gids_[$i]}" > $out/etc/$target.gid
39+ echo "${modes_[$i]}" > $out/etc/$target.mode
40+ echo "${users_[$i]}" > $out/etc/$target.uid
41+ echo "${groups_[$i]}" > $out/etc/$target.gid
4242 fi
4343
4444 fi
nixos/modules/system/etc/setup-etc.pl+2
@@ -108,6 +108,8 @@ sub link {
108108 my $uid = read_file("$_.uid"); chomp $uid;
109109 my $gid = read_file("$_.gid"); chomp $gid;
110110 copy "$static/$fn", "$target.tmp" or warn;
111+ $uid = getpwnam $uid unless $uid =~ /^\+/;
112+ $gid = getgrnam $gid unless $gid =~ /^\+/;
111113 chown int($uid), int($gid), "$target.tmp" or warn;
112114 chmod oct($mode), "$target.tmp" or warn;
113115 rename "$target.tmp", $target or warn;