about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichal Sojka <michal.sojka@cvut.cz>2022-03-04 18:53:07 +0100
committerProfpatsch <mail@profpatsch.de>2022-03-22 19:03:10 +0100
commit611e9302f9b33ca72cfce239445444aad3653b47 (patch)
tree62dbd8c0c879183a3e8fd404b0238d05f71e85da
parent6396adbdfa8cef5d59025d855e5872facd2c6ea8 (diff)
downloadnixlib-611e9302f9b33ca72cfce239445444aad3653b47.tar
nixlib-611e9302f9b33ca72cfce239445444aad3653b47.tar.gz
nixlib-611e9302f9b33ca72cfce239445444aad3653b47.tar.bz2
nixlib-611e9302f9b33ca72cfce239445444aad3653b47.tar.lz
nixlib-611e9302f9b33ca72cfce239445444aad3653b47.tar.xz
nixlib-611e9302f9b33ca72cfce239445444aad3653b47.tar.zst
nixlib-611e9302f9b33ca72cfce239445444aad3653b47.zip
nixos-rebuild: add --no-flake switch
When a NixOS system uses flakes, i.e., /etc/nixos/flake.nix exists, it
is impossible to use nixos-rebuild to build a pre-flake
configuration.nix. Of course, one can directly use nix command to
build the configuration, but not everybody remembers the correct nix
options to do that.

With the new option, it is possible to build a pre-flake configuration
with command like this:

    nixos-rebuild build-vm -I nixos-config=./vm.nix --no-flake

The option might be useful for people following older pre-flake
tutorials on a flake-based system.
-rw-r--r--nixos/doc/manual/man-nixos-rebuild.xml18
-rwxr-xr-xpkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh6
2 files changed, 23 insertions, 1 deletions
diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml
index ab2a5d83a089..b2ca9f457a2b 100644
--- a/nixos/doc/manual/man-nixos-rebuild.xml
+++ b/nixos/doc/manual/man-nixos-rebuild.xml
@@ -92,6 +92,10 @@
    </arg>
 
    <arg>
+    <option>--no-flake</option>
+   </arg>
+
+   <arg>
     <option>--override-input</option> <replaceable>input-name</replaceable> <replaceable>flake-uri</replaceable>
    </arg>
 
@@ -594,6 +598,20 @@
     </listitem>
    </varlistentry>
 
+   <varlistentry>
+    <term>
+     <option>--no-flake</option>
+    </term>
+    <listitem>
+     <para>
+      Do not imply <option>--flake</option> if
+      <filename>/etc/nixos/flake.nix</filename> exists. With this
+      option, it is possible to build non-flake NixOS configurations
+      even if the current NixOS systems uses flakes.
+     </para>
+    </listitem>
+   </varlistentry>
+
   </variablelist>
 
   <para>
diff --git a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
index 2ec30c24f2d3..0c3d64ace9c4 100755
--- a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
+++ b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
@@ -32,6 +32,7 @@ buildHost=localhost
 targetHost=
 remoteSudo=
 verboseScript=
+noFlake=
 # comma separated list of vars to preserve when using sudo
 preservedSudoVars=NIXOS_INSTALL_BOOTLOADER
 
@@ -115,6 +116,9 @@ while [ "$#" -gt 0 ]; do
         flakeFlags=(--extra-experimental-features 'nix-command flakes')
         shift 1
         ;;
+      --no-flake)
+        noFlake=1
+        ;;
       --recreate-lock-file|--no-update-lock-file|--no-write-lock-file|--no-registries|--commit-lock-file)
         lockFlags+=("$i")
         ;;
@@ -339,7 +343,7 @@ fi
 
 # Use /etc/nixos/flake.nix if it exists. It can be a symlink to the
 # actual flake.
-if [[ -z $flake && -e /etc/nixos/flake.nix ]]; then
+if [[ -z $flake && -e /etc/nixos/flake.nix && -z $noFlake ]]; then
     flake="$(dirname "$(readlink -f /etc/nixos/flake.nix)")"
 fi