3
0
Fork 0
forked from mirrors/nixpkgs

environment.etc: add user/group option

fixes #27546
This commit is contained in:
Volth 2017-07-21 14:41:19 +00:00 committed by Jörg Thalheim
parent 6f2715e47d
commit faac018630
4 changed files with 31 additions and 9 deletions

View file

@ -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 \

View file

@ -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
@ -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 = {
@ -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..."

View file

@ -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
@ -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

View file

@ -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;