diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml index 81e2f8bb279e..4341b8918df8 100644 --- a/nixos/doc/manual/man-nixos-rebuild.xml +++ b/nixos/doc/manual/man-nixos-rebuild.xml @@ -140,14 +140,17 @@ Description - This command updates the system so that it corresponds to the configuration - specified in /etc/nixos/configuration.nix. Thus, every - time you modify /etc/nixos/configuration.nix or any - NixOS module, you must run nixos-rebuild to make the - changes take effect. It builds the new system in - /nix/store, runs its activation script, and stop and - (re)starts any system services if needed. Please note that user services need - to be started manually as they aren't detected by the activation script at the moment. + This command updates the system so that it corresponds to the + configuration specified in + /etc/nixos/configuration.nix or + /etc/nixos/flake.nix. Thus, every time you + modify the configuration or any other NixOS module, you must run + nixos-rebuild to make the changes take + effect. It builds the new system in + /nix/store, runs its activation script, and + stop and (re)starts any system services if needed. Please note that + user services need to be started manually as they aren't detected + by the activation script at the moment. @@ -526,8 +529,10 @@ - Build the NixOS system from the specified flake. The flake must - contain an output named + Build the NixOS system from the specified flake. It defaults to + the directory containing the target of the symlink + /etc/nixos/flake.nix, if it exists. The + flake must contain an output named nixosConfigurations.name, where name denotes the name of the configuration and can be specified using the @@ -594,6 +599,21 @@ + + + /etc/nixos/flake.nix + + + + If this file exists, then nixos-rebuild will + use it as if the option was given. This + file may be a symlink to a flake.nix in an + actual flake; thus /etc/nixos need not be a + flake. + + + + /run/current-system diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 949cd8691465..18088e4f9ea4 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -236,6 +236,12 @@ if [ -z "$_NIXOS_REBUILD_REEXEC" ]; then export PATH=@nix@/bin:$PATH 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 + flake="$(dirname "$(readlink -f /etc/nixos/flake.nix)")" +fi + # Re-execute nixos-rebuild from the Nixpkgs tree. # FIXME: get nixos-rebuild from $flake. if [[ -z $_NIXOS_REBUILD_REEXEC && -n $canRun && -z $fast && -z $flake ]]; then