Skip to content

Commit faac018

Browse files
VolthMic92
Volth
authored andcommittedJul 29, 2017
environment.etc: add user/group option
fixes #27546
1 parent 6f2715e commit faac018

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed
 

‎nixos/modules/config/users-groups.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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

2727
in
@@ -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
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ set -f
66
sources_=($sources)
77
targets_=($targets)
88
modes_=($modes)
9-
uids_=($uids)
10-
gids_=($gids)
9+
users_=($users)
10+
groups_=($groups)
1111
set +f
1212

1313
for ((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
Original file line numberDiff line numberDiff line change
@@ -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;

0 commit comments

Comments
 (0)
Please sign in to comment.