0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

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; input.gid = ids.gids.input;
}; };
system.activationScripts.users = stringAfter [ "etc" ] system.activationScripts.users = stringAfter [ "stdio" ]
'' ''
${pkgs.perl}/bin/perl -w \ ${pkgs.perl}/bin/perl -w \
-I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl \ -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl \

View file

@ -20,8 +20,8 @@ let
sources = map (x: x.source) etc'; sources = map (x: x.source) etc';
targets = map (x: x.target) etc'; targets = map (x: x.target) etc';
modes = map (x: x.mode) etc'; modes = map (x: x.mode) etc';
uids = map (x: x.uid) etc'; users = map (x: x.user) etc';
gids = map (x: x.gid) etc'; groups = map (x: x.group) etc';
}; };
in 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 = { config = {
@ -130,7 +150,7 @@ in
system.build.etc = etc; system.build.etc = etc;
system.activationScripts.etc = stringAfter [ "stdio" ] system.activationScripts.etc = stringAfter [ "users" "groups" ]
'' ''
# Set up the statically computed bits of /etc. # Set up the statically computed bits of /etc.
echo "setting up /etc..." echo "setting up /etc..."

View file

@ -6,8 +6,8 @@ set -f
sources_=($sources) sources_=($sources)
targets_=($targets) targets_=($targets)
modes_=($modes) modes_=($modes)
uids_=($uids) users_=($users)
gids_=($gids) groups_=($groups)
set +f set +f
for ((i = 0; i < ${#targets_[@]}; i++)); do for ((i = 0; i < ${#targets_[@]}; i++)); do
@ -36,9 +36,9 @@ for ((i = 0; i < ${#targets_[@]}; i++)); do
fi fi
if test "${modes_[$i]}" != symlink; then if test "${modes_[$i]}" != symlink; then
echo "${modes_[$i]}" > $out/etc/$target.mode echo "${modes_[$i]}" > $out/etc/$target.mode
echo "${uids_[$i]}" > $out/etc/$target.uid echo "${users_[$i]}" > $out/etc/$target.uid
echo "${gids_[$i]}" > $out/etc/$target.gid echo "${groups_[$i]}" > $out/etc/$target.gid
fi fi
fi fi

View file

@ -108,6 +108,8 @@ sub link {
my $uid = read_file("$_.uid"); chomp $uid; my $uid = read_file("$_.uid"); chomp $uid;
my $gid = read_file("$_.gid"); chomp $gid; my $gid = read_file("$_.gid"); chomp $gid;
copy "$static/$fn", "$target.tmp" or warn; 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; chown int($uid), int($gid), "$target.tmp" or warn;
chmod oct($mode), "$target.tmp" or warn; chmod oct($mode), "$target.tmp" or warn;
rename "$target.tmp", $target or warn; rename "$target.tmp", $target or warn;