@@ -61,6 +61,7 @@ trap 'rm -rf "$sshKeyDir"' EXIT
61
61
mkdir -p " $sshKeyDir "
62
62
63
63
declare -A diskEncryptionKeys=()
64
+ declare -A extraFilesOwnership=()
64
65
declare -a nixCopyOptions=()
65
66
declare -a sshArgs=()
66
67
@@ -103,7 +104,10 @@ Options:
103
104
copy over existing /etc/ssh/ssh_host_* host keys to the installation
104
105
* --extra-files <path>
105
106
contents of local <path> are recursively copied to the root (/) of the new NixOS installation. Existing files are overwritten
106
- Copied files will be owned by root. See documentation for details.
107
+ Copied files will be owned by root unless specified by --chown option. See documentation for details.
108
+ * --chown <path> <ownership>
109
+ change ownership of <path> recursively. Recommended to use uid:gid as opposed to username:groupname for ownership.
110
+ Option can be specified more than once.
107
111
* --disk-encryption-keys <remote_path> <local_path>
108
112
copy the contents of the file or pipe in local_path to remote_path in the installer environment,
109
113
after kexec but before installation. Can be repeated.
@@ -267,6 +271,11 @@ parseArgs() {
267
271
extraFiles=$2
268
272
shift
269
273
;;
274
+ --chown)
275
+ extraFilesOwnership[" $2 " ]=" $3 "
276
+ shift
277
+ shift
278
+ ;;
270
279
--disk-encryption-keys)
271
280
diskEncryptionKeys[" $2 " ]=" $3 "
272
281
shift
@@ -678,9 +687,15 @@ nixosInstall() {
678
687
if [[ -n ${extraFiles} ]]; then
679
688
step Copying extra files
680
689
tar -C " $extraFiles " -cpf- . | runSsh " tar -C /mnt -xf- --no-same-owner"
690
+
681
691
runSsh " chmod 755 /mnt" # tar also changes permissions of /mnt
682
692
fi
683
693
694
+ if [[ ${# extraFilesOwnership[@]} -gt 0 ]]; then
695
+ # shellcheck disable=SC2016
696
+ printf " %s\n" " ${! extraFilesOwnership[@]} " " ${extraFilesOwnership[@]} " | pr -2t | runSsh ' while read file ownership; do chown -R "$ownership" "/mnt/$file"; done'
697
+ fi
698
+
684
699
step Installing NixOS
685
700
runSsh sh << SSH
686
701
set -eu ${enableDebug}
0 commit comments