mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 12:53:59 +03:00
etc: uid/gid support for copied files
Signed-off-by: Austin Seipp <aseipp@pobox.com>
This commit is contained in:
parent
f6aba32af3
commit
dc700e0925
@ -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 = {
|
||||
|
@ -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
|
||||
|
@ -60,7 +60,15 @@ sub link {
|
||||
if ($mode eq "direct-symlink") {
|
||||
atomicSymlink readlink("$static/$fn"), $target or warn;
|
||||
} else {
|
||||
open UID, "<$_.uid";
|
||||
my $uid = <UID>; chomp $uid;
|
||||
close UID;
|
||||
open GID, "<$_.gid";
|
||||
my $gid = <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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user