Skip to content

Commit

Permalink
environment.etc: add user/group option
Browse files Browse the repository at this point in the history
fixes #27546
  • Loading branch information
Volth authored and Mic92 committed Jul 29, 2017
1 parent 6f2715e commit faac018
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion nixos/modules/config/users-groups.nix
Expand Up @@ -527,7 +527,7 @@ in {
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 \
Expand Down
26 changes: 23 additions & 3 deletions nixos/modules/system/etc/etc.nix
Expand Up @@ -20,8 +20,8 @@ let
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
Expand Down Expand Up @@ -108,6 +108,26 @@ 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 = {
Expand All @@ -130,7 +150,7 @@ in

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..."
Expand Down
10 changes: 5 additions & 5 deletions nixos/modules/system/etc/make-etc.sh
Expand Up @@ -6,8 +6,8 @@ set -f
sources_=($sources)
targets_=($targets)
modes_=($modes)
uids_=($uids)
gids_=($gids)
users_=($users)
groups_=($groups)
set +f

for ((i = 0; i < ${#targets_[@]}; i++)); do
Expand Down Expand Up @@ -36,9 +36,9 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions nixos/modules/system/etc/setup-etc.pl
Expand Up @@ -108,6 +108,8 @@ sub link {
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;
Expand Down

0 comments on commit faac018

Please sign in to comment.