about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
Diffstat (limited to 'nixos')
-rw-r--r--nixos/doc/manual/man-nixos-rebuild.xml25
-rw-r--r--nixos/modules/installer/tools/nixos-rebuild.sh32
2 files changed, 20 insertions, 37 deletions
diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml
index 4341b8918df85..f4f663b84f056 100644
--- a/nixos/doc/manual/man-nixos-rebuild.xml
+++ b/nixos/doc/manual/man-nixos-rebuild.xml
@@ -83,10 +83,6 @@
     <option>--flake</option> <replaceable>flake-uri</replaceable>
    </arg>
 
-   <arg>
-    <option>--config</option> <replaceable>name</replaceable>
-   </arg>
-
    <sbr />
 
    <arg>
@@ -525,7 +521,7 @@
 
    <varlistentry>
     <term>
-     <option>--flake</option> <replaceable>flake-uri</replaceable>
+     <option>--flake</option> <replaceable>flake-uri</replaceable>[<replaceable>name</replaceable>]
     </term>
     <listitem>
      <para>
@@ -533,22 +529,9 @@
       the directory containing the target of the symlink
       <filename>/etc/nixos/flake.nix</filename>, if it exists. The
       flake must contain an output named
-      <literal>nixosConfigurations.<replaceable>name</replaceable></literal>,
-      where <replaceable>name</replaceable> denotes the name of the
-      configuration and can be specified using the
-      <option>--config</option> option.
-     </para>
-    </listitem>
-   </varlistentry>
-
-   <varlistentry>
-    <term>
-     <option>--config</option> <replaceable>name</replaceable>
-    </term>
-    <listitem>
-     <para>
-      Specifies which NixOS configuration to use from the
-      flake. Defaults to the current hostname.
+      <literal>nixosConfigurations.<replaceable>name</replaceable></literal>. If
+      <replaceable>name</replaceable> is omitted, it default to the
+      current host name.
      </para>
     </listitem>
    </varlistentry>
diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh
index 18088e4f9ea41..b681a170b6bd3 100644
--- a/nixos/modules/installer/tools/nixos-rebuild.sh
+++ b/nixos/modules/installer/tools/nixos-rebuild.sh
@@ -100,10 +100,6 @@ while [ "$#" -gt 0 ]; do
         flake="$1"
         shift 1
         ;;
-      --config)
-        flakeAttr="nixosConfigurations.$1"
-        shift 1
-        ;;
       *)
         echo "$0: unknown option \`$i'"
         exit 1
@@ -254,12 +250,20 @@ fi
 
 # For convenience, use the hostname as the default configuration to
 # build from the flake.
-if [[ -n $flake && -z $flakeAttr ]]; then
-    hostname=$(cat /proc/sys/kernel/hostname)
-    if [[ -z $hostname ]]; then
-        hostname=default
+if [[ -n $flake ]]; then
+    if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
+       flake="${BASH_REMATCH[1]}"
+       flakeAttr="${BASH_REMATCH[2]}"
+    fi
+    if [[ -z $flakeAttr ]]; then
+        hostname=$(cat /proc/sys/kernel/hostname)
+        if [[ -z $hostname ]]; then
+            hostname=default
+        fi
+        flakeAttr="nixosConfigurations.\"$hostname\""
+    else
+        flakeAttr="nixosConfigurations.\"$flakeAttr\""
     fi
-    flakeAttr="nixosConfigurations.\"$hostname\""
 fi
 
 # Resolve the flake.
@@ -391,17 +395,13 @@ fi
 # or "boot"), or just build it and create a symlink "result" in the
 # current directory (for "build" and "test").
 if [ -z "$rollback" ]; then
-    if [[ -z $flake ]]; then
-        echo "building the system configuration..." >&2
-    else
-        echo "building the system configuration '$flake:$flakeAttr'..." >&2
-    fi
+    echo "building the system configuration..." >&2
     if [ "$action" = switch -o "$action" = boot ]; then
         if [[ -z $flake ]]; then
             pathToConfig="$(nixBuild '<nixpkgs/nixos>' --no-out-link -A system "${extraBuildFlags[@]}")"
         else
             outLink=$tmpDir/result
-            nix build "$flake:$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" --out-link $outLink
+            nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" --out-link $outLink
             pathToConfig="$(readlink -f $outLink)"
         fi
         copyToTarget "$pathToConfig"
@@ -410,7 +410,7 @@ if [ -z "$rollback" ]; then
         if [[ -z $flake ]]; then
             pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A system -k "${extraBuildFlags[@]}")"
         else
-            nix build "$flake:$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}"
+            nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}"
             pathToConfig="$(readlink -f ./result)"
         fi
     elif [ "$action" = build-vm ]; then