@@ -143,6 +143,23 @@ export TMPDIR=${TMPDIR:-$tmpdir}
143143
144144sub="auto?trusted=1"
145145
146+# Copy the NixOS/Nixpkgs sources to the target as the initial contents
147+# of the NixOS channel.
148+if [[ -z $noChannelCopy ]]; then
149+ if [[ -z $channelPath ]]; then
150+ channelPath="$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")"
151+ fi
152+ if [[ -n $channelPath ]]; then
153+ echo "copying channel..."
154+ mkdir -p "$mountPoint"/nix/var/nix/profiles/per-user/root
155+ nix-env --store "$mountPoint" "${extraBuildFlags[@]}" --extra-substituters "$sub" \
156+ -p "$mountPoint"/nix/var/nix/profiles/per-user/root/channels --set "$channelPath" --quiet \
157+ "${verbosity[@]}"
158+ install -m 0700 -d "$mountPoint"/root/.nix-defexpr
159+ ln -sfn /nix/var/nix/profiles/per-user/root/channels "$mountPoint"/root/.nix-defexpr/channels
160+ fi
161+fi
162+
146163# Build the system configuration in the target filesystem.
147164if [[ -z $system ]]; then
148165 outLink="$tmpdir/system"
@@ -167,23 +184,6 @@ nix-env --store "$mountPoint" "${extraBuildFlags[@]}" \
167184 --extra-substituters "$sub" \
168185 -p "$mountPoint"/nix/var/nix/profiles/system --set "$system" "${verbosity[@]}"
169186
170−# Copy the NixOS/Nixpkgs sources to the target as the initial contents
171−# of the NixOS channel.
172−if [[ -z $noChannelCopy ]]; then
173− if [[ -z $channelPath ]]; then
174− channelPath="$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")"
175− fi
176− if [[ -n $channelPath ]]; then
177− echo "copying channel..."
178− mkdir -p "$mountPoint"/nix/var/nix/profiles/per-user/root
179− nix-env --store "$mountPoint" "${extraBuildFlags[@]}" --extra-substituters "$sub" \
180− -p "$mountPoint"/nix/var/nix/profiles/per-user/root/channels --set "$channelPath" --quiet \
181− "${verbosity[@]}"
182− install -m 0700 -d "$mountPoint"/root/.nix-defexpr
183− ln -sfn /nix/var/nix/profiles/per-user/root/channels "$mountPoint"/root/.nix-defexpr/channels
184− fi
185−fi
186−
187187# Mark the target as a NixOS installation, otherwise switch-to-configuration will chicken out.
188188mkdir -m 0755 -p "$mountPoint/etc"
189189touch "$mountPoint/etc/NIXOS"