···
, # The files and directories to be placed in the target file system.
21
-
# This is a list of attribute sets {source, target} where `source'
22
-
# is the file system object (regular file or directory) to be
23
-
# grafted in the file system at path `target'.
21
+
# This is a list of attribute sets {source, target, mode, user, group} where
22
+
# `source' is the file system object (regular file or directory) to be
23
+
# grafted in the file system at path `target', `mode' is a string containing
24
+
# the permissions that will be set (ex. "755"), `user' and `group' are the
25
+
# user and group name that will be set as owner of the files.
26
+
# `mode', `user', and `group' are optional.
27
+
# When setting one of `user' or `group', the other needs to be set too.
, # Type of partition table to use; either "legacy", "efi", or "none".
···
assert partitionTableType == "legacy" || partitionTableType == "legacy+gpt" || partitionTableType == "efi" || partitionTableType == "hybrid" || partitionTableType == "none";
# We use -E offset=X below, which is only supported by e2fsprogs
assert partitionTableType != "none" -> fsType == "ext4";
67
+
# Either both or none of {user,group} need to be set
69
+
(attrs: ((attrs.user or null) == null)
70
+
== ((attrs.group or null) == null))
···
sources = map (x: x.source) contents;
targets = map (x: x.target) contents;
160
+
modes = map (x: x.mode or "''") contents;
161
+
users = map (x: x.user or "''") contents;
162
+
groups = map (x: x.group or "''") contents;
closureInfo = pkgs.closureInfo { rootPaths = [ config.system.build.toplevel channelSources ]; };
···
sources_=(${concatStringsSep " " sources})
targets_=(${concatStringsSep " " targets})
189
+
modes_=(${concatStringsSep " " modes})
for ((i = 0; i < ''${#targets_[@]}; i++)); do
source="''${sources_[$i]}"
target="''${targets_[$i]}"
195
+
mode="''${modes_[$i]}"
197
+
if [ -n "$mode" ]; then
198
+
rsync_chmod_flags="--chmod=$mode"
200
+
rsync_chmod_flags=""
202
+
# Unfortunately cptofs only supports modes, not ownership, so we can't use
203
+
# rsync's --chown option. Instead, we change the ownerships in the
204
+
# VM script with chown.
205
+
rsync_flags="-a --no-o --no-g $rsync_chmod_flags"
if [[ "$source" =~ '*' ]]; then
# If the source name contains '*', perform globbing.
187
-
rsync -a --no-o --no-g "$fn" $root/$target/
210
+
rsync $rsync_flags "$fn" $root/$target/
mkdir -p $root/$(dirname $target)
if ! [ -e $root/$target ]; then
192
-
rsync -a --no-o --no-g $source $root/$target
215
+
rsync $rsync_flags $source $root/$target
echo "duplicate entry $target -> $source"
···
# The above scripts will generate a random machine-id and we don't want to bake a single ID into all our images
rm -f $mountPoint/etc/machine-id
310
+
# Set the ownerships of the contents. The modes are set in preVM.
311
+
# No globbing on targets, so no need to set -f
312
+
targets_=(${concatStringsSep " " targets})
313
+
users_=(${concatStringsSep " " users})
314
+
groups_=(${concatStringsSep " " groups})
315
+
for ((i = 0; i < ''${#targets_[@]}; i++)); do
316
+
target="''${targets_[$i]}"
317
+
user="''${users_[$i]}"
318
+
group="''${groups_[$i]}"
319
+
if [ -n "$user$group" ]; then
320
+
# We have to nixos-enter since we need to use the user and group of the VM
321
+
nixos-enter --root $mountPoint -- chown -R "$user:$group" "$target"