From faac018630b8d3f89c633c1235ae649498c938e8 Mon Sep 17 00:00:00 2001 From: Volth Date: Fri, 21 Jul 2017 14:41:19 +0000 Subject: environment.etc: add user/group option fixes #27546 --- nixos/modules/config/users-groups.nix | 2 +- nixos/modules/system/etc/etc.nix | 26 +++++++++++++++++++++++--- nixos/modules/system/etc/make-etc.sh | 10 +++++----- nixos/modules/system/etc/setup-etc.pl | 2 ++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix index 0e7ffbd3c2e..a4715175cc9 100644 --- a/nixos/modules/config/users-groups.nix +++ b/nixos/modules/config/users-groups.nix @@ -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 \ diff --git a/nixos/modules/system/etc/etc.nix b/nixos/modules/system/etc/etc.nix index fd6e58cd5b4..7d43ba07ca5 100644 --- a/nixos/modules/system/etc/etc.nix +++ b/nixos/modules/system/etc/etc.nix @@ -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 uid. + ''; + }; + + 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 gid. + ''; + }; + }; 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..." diff --git a/nixos/modules/system/etc/make-etc.sh b/nixos/modules/system/etc/make-etc.sh index 60d4ba1301a..1ca4c3046f0 100644 --- a/nixos/modules/system/etc/make-etc.sh +++ b/nixos/modules/system/etc/make-etc.sh @@ -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 diff --git a/nixos/modules/system/etc/setup-etc.pl b/nixos/modules/system/etc/setup-etc.pl index efda74161ff..eed20065087 100644 --- a/nixos/modules/system/etc/setup-etc.pl +++ b/nixos/modules/system/etc/setup-etc.pl @@ -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; -- cgit 1.4.1