diff --git a/nixos/modules/system/etc/etc.nix b/nixos/modules/system/etc/etc.nix index a8f0a59b6fa9..e9c03df2ba34 100644 --- a/nixos/modules/system/etc/etc.nix +++ b/nixos/modules/system/etc/etc.nix @@ -19,6 +19,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'; }; in @@ -87,6 +89,24 @@ in ''; }; + uid = mkOption { + default = 0; + type = types.int; + description = '' + UID of created file. Only takes affect when the file is + copied (that is, the mode is not 'symlink'). + ''; + }; + + gid = mkOption { + default = 0; + type = types.int; + description = '' + GID of created file. Only takes affect when the file is + copied (that is, the mode is not 'symlink'). + ''; + }; + }; config = { diff --git a/nixos/modules/system/etc/make-etc.sh b/nixos/modules/system/etc/make-etc.sh index 7cf68db9ddce..60d4ba1301a3 100644 --- a/nixos/modules/system/etc/make-etc.sh +++ b/nixos/modules/system/etc/make-etc.sh @@ -6,6 +6,8 @@ set -f sources_=($sources) targets_=($targets) modes_=($modes) +uids_=($uids) +gids_=($gids) set +f for ((i = 0; i < ${#targets_[@]}; i++)); do @@ -35,6 +37,8 @@ for ((i = 0; i < ${#targets_[@]}; i++)); do 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 fi fi diff --git a/nixos/modules/system/etc/setup-etc.pl b/nixos/modules/system/etc/setup-etc.pl index 4b79dbaab89e..8ba9a370b27a 100644 --- a/nixos/modules/system/etc/setup-etc.pl +++ b/nixos/modules/system/etc/setup-etc.pl @@ -60,7 +60,15 @@ sub link { if ($mode eq "direct-symlink") { atomicSymlink readlink("$static/$fn"), $target or warn; } else { + open UID, "<$_.uid"; + my $uid = ; chomp $uid; + close UID; + open GID, "<$_.gid"; + my $gid = ; chomp $gid; + close GID; + copy "$static/$fn", "$target.tmp" or warn; + chown int($uid), int($gid), "$target.tmp" or warn; chmod oct($mode), "$target.tmp" or warn; rename "$target.tmp", $target or warn; }