@@ -198,10 +198,24 @@ main() {
198198 flakeAttr=" ${BASH_REMATCH[2]} "
199199 fi
200200
201- if [[ -e " $flake " ]]; then
202- flake=$( realpath " $flake " )
201+ # Resolve flake to nix store path to respect git tracking
202+ if ! flake_metadata=$( nix flake metadata --json " ${nix_args[@]} " " $flake " 2>&1 ) ; then
203+ echo " Failed to resolve flake metadata for: $flake " >&2
204+ echo " $flake_metadata " >&2
205+ exit 1
206+ fi
207+
208+ # Extract the "path" field from JSON using sed
209+ flake_path=$( echo " $flake_metadata " | sed -nE ' s/.*"path": ?"([^"]+)".*/\1/p' )
210+
211+ if [[ -z " $flake_path " ]]; then
212+ echo " Failed to get store path from flake metadata" >&2
213+ echo " $flake_metadata " >&2
214+ exit 1
203215 fi
204216
217+ flake=" $flake_path "
218+
205219 if [[ -z ${flakeAttr-} ]]; then
206220 echo " Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri." >&2
207221 echo ' For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.' >&2
@@ -215,7 +229,7 @@ main() {
215229 trap cleanupMountPoint EXIT
216230 fi
217231
218- outputs=$( nixBuild " ${libexec_dir} " /install-cli.nix \
232+ if ! outputs=$( nixBuild " ${libexec_dir} " /install-cli.nix \
219233 " ${nix_args[@]} " \
220234 --no-out-link \
221235 --impure \
@@ -227,9 +241,20 @@ main() {
227241 --argstr extraSystemConfig " $extraSystemConfig " \
228242 -A installToplevel \
229243 -A closureInfo \
230- -A " $diskoAttr " )
244+ -A " $diskoAttr " ) ; then
245+ echo " Failed to build NixOS configuration" >&2
246+ exit 1
247+ fi
231248
232249 IFS=$' \n ' mapfile -t artifacts <<< " $outputs"
250+
251+ if [[ ${# artifacts[@]} -ne 3 ]]; then
252+ echo " Expected 3 build outputs, got ${# artifacts[@]} " >&2
253+ echo " Outputs received:" >&2
254+ printf ' %s\n' " ${artifacts[@]} " >&2
255+ exit 1
256+ fi
257+
233258 nixos_system=${artifacts[0]}
234259 closure_info=${artifacts[1]}
235260 disko_script=${artifacts[2]}
0 commit comments