1 diff --git a/nixos/modules/installer/tools/nixos-install.sh b/nixos/modules/installer/tools/nixos-install.sh
2 index 0b62bca8367..b27edd22655 100644
3 --- a/nixos/modules/installer/tools/nixos-install.sh
4 +++ b/nixos/modules/installer/tools/nixos-install.sh
5 @@ -34,6 +34,22 @@ while [ "$#" -gt 0 ]; do
13 + --recreate-lock-file|--no-update-lock-file|--no-write-lock-file|--no-registries|--commit-lock-file)
18 + lockFlags+=("$i" "$j")
23 + lockFlags+=("$i" "$j" "$k")
26 channelPath="$1"; shift 1
28 @@ -92,7 +108,20 @@ if [[ ${NIXOS_CONFIG:0:1} != / ]]; then
32 -if [[ ! -e $NIXOS_CONFIG && -z $system ]]; then
33 +if [[ -n $flake ]]; then
34 + if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
35 + flake="${BASH_REMATCH[1]}"
36 + flakeAttr="${BASH_REMATCH[2]}"
38 + flakeAttr="nixosConfigurations.\"$flakeAttr\""
42 +if [[ -n $flake ]]; then
43 + flake=$(nix flake info --json "${extraBuildFlags[@]}" "${lockFlags[@]}" -- "$flake" | jq -r .url)
46 +if [[ ! -e $NIXOS_CONFIG && -z $system && -z $flake ]]; then
47 echo "configuration file $NIXOS_CONFIG doesn't exist"
50 @@ -108,11 +137,18 @@ sub="auto?trusted=1"
52 # Build the system configuration in the target filesystem.
53 if [[ -z $system ]]; then
54 - echo "building the configuration in $NIXOS_CONFIG..."
55 outLink="$tmpdir/system"
56 - nix-build --out-link "$outLink" --store "$mountPoint" "${extraBuildFlags[@]}" \
57 - --extra-substituters "$sub" \
58 - '<nixpkgs/nixos>' -A system -I "nixos-config=$NIXOS_CONFIG" ${verbosity[@]}
59 + if [[ -z $flake ]]; then
60 + echo "building the configuration in $NIXOS_CONFIG..."
61 + nix-build --out-link "$outLink" --store "$mountPoint" "${extraBuildFlags[@]}" \
62 + --extra-substituters "$sub" \
63 + '<nixpkgs/nixos>' -A system -I "nixos-config=$NIXOS_CONFIG" ${verbosity[@]}
65 + echo "building the flake in $flake..."
66 + nix build "$flake#$flakeAttr.config.system.build.toplevel" \
67 + --extra-substituters "$sub" ${verbosity[@]} \
68 + "${extraBuildFlags[@]}" "${lockFlags[@]}" --out-link "$outLink"
70 system=$(readlink -f $outLink)