This command updates the system so that it corresponds to the configuration specified in <filename>/etc/nixos/configuration.nix</filename>. Thus, every time you modify <filename>/etc/nixos/configuration.nix</filename> or any NixOS module, you must run <command>nixos-rebuild</command> to make the changes take effect. It builds the new system in <filename>/nix/store</filename>, 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.
Build and activate the new configuration, and make it the boot default. That is, the configuration is added to the GRUB boot menu as the default menu entry, so that subsequent reboots will boot the system into the new configuration. Previous configurations activated with <command>nixos-rebuild switch</command> or <command>nixos-rebuild boot</command> remain available in the GRUB menu.
Build the new configuration and make it the boot default (as with <command>nixos-rebuild switch</command>), but do not activate it. That is, the system continues to run the previous configuration until the next reboot.
Build and activate the new configuration, but do not add it to the GRUB boot menu. Thus, if you reboot the system (or if it crashes), you will automatically revert to the default configuration (i.e. the configuration resulting from the last call to <command>nixos-rebuild switch</command> or <command>nixos-rebuild boot</command>).
Build the new configuration, but neither activate it nor add it to the GRUB boot menu. It leaves a symlink named <filename>result</filename> in the current directory, which points to the output of the top-level “system” derivation. This is essentially the same as doing
Build the new configuration, but instead of activating it, show what changes would be performed by the activation (i.e. by <command>nixos-rebuild test</command>). For instance, this command will print which systemd units would be restarted. The list of changes is not guaranteed to be complete.
Build a script that starts a NixOS virtual machine with the desired configuration. It leaves a symlink <filename>result</filename> in the current directory that points (under <filename>result/bin/run-<replaceable>hostname</replaceable>-vm</filename>) at the script that starts the VM. Thus, to test a NixOS configuration in a virtual machine, you should do the following:
The VM is implemented using the <literal>qemu</literal> package. For best performance, you should load the <literal>kvm-intel</literal> or <literal>kvm-amd</literal> kernel modules to get hardware virtualisation.
The VM mounts the Nix store of the host through the 9P file system. The host Nix store is read-only, so Nix commands that modify the Nix store will not work in the VM. This includes commands such as <command>nixos-rebuild</command>; to change the VM’s configuration, you must halt the VM and re-run the commands above.
The VM has its own <literal>ext3</literal> root file system, which is automatically created when the VM is first started, and is persistent across reboots of the VM. It is stored in <literal>./<replaceable>hostname</replaceable>.qcow2</literal>.
Like <option>build-vm</option>, but boots using the regular boot loader of your configuration (e.g., GRUB 1 or 2), rather than booting directly into the kernel and initial ramdisk of the system. This allows you to test whether the boot loader works correctly. However, it does not guarantee that your NixOS configuration will boot successfully on the host hardware (i.e., after running <command>nixos-rebuild switch</command>), because the hardware and boot loader configuration in the VM are different. The boot loader is installed on an automatically generated virtual disk containing a <filename>/boot</filename> partition, which is mounted read-only in the VM.
Normally, <command>nixos-rebuild</command> first builds the <varname>nixUnstable</varname> attribute in Nixpkgs, and uses the resulting instance of the Nix package manager to build the new system configuration. This is necessary if the NixOS modules use features not provided by the currently installed version of Nix. This option disables building a new Nix.
Equivalent to <option>--no-build-nix</option><option>--show-trace</option>. This option is useful if you call <command>nixos-rebuild</command> frequently (e.g. if you’re hacking on a NixOS module).
Instead of building a new configuration as specified by <filename>/etc/nixos/configuration.nix</filename>, roll back to the previous configuration. (The previous configuration is defined as the one before the “current” generation of the Nix profile <filename>/nix/var/nix/profiles/system</filename>.)
Allow ad-hoc remote builders for building the new system. This requires the user executing <command>nixos-rebuild</command> (usually root) to be configured as a trusted user in the Nix daemon. This can be achieved by using the <literal>nix.trustedUsers</literal> NixOS option. Examples values for that option are described in the <literal>Remote builds chapter</literal> in the Nix manual, (i.e. <command>--builders "ssh://bigbrother x86_64-linux"</command>). By specifying an empty string existing builders specified in <filename>/etc/nix/machines</filename> can be ignored: <command>--builders ""</command> for example when they are not reachable due to network connectivity.
Instead of using the Nix profile <filename>/nix/var/nix/profiles/system</filename> to keep track of the current and previous system configurations, use <filename>/nix/var/nix/profiles/system-profiles/<replaceable>name</replaceable></filename>. When you use GRUB 2, for every system profile created with this flag, NixOS will create a submenu named “NixOS - Profile '<replaceable>name</replaceable>'” in GRUB’s boot menu, containing the current and previous configurations of this profile.
Instead of building the new configuration locally, use the specified host to perform the build. The host needs to be accessible with ssh, and must be able to perform Nix builds. If the option <option>--target-host</option> is not set, the build will be copied back to the local machine when done.
Note that, if <option>--no-build-nix</option> is not specified, Nix will be built both locally and remotely. This is because the configuration will always be evaluated locally even though the building might be performed remotely.
You can include a remote user name in the host name (<replaceable>user@host</replaceable>). You can also set ssh options by defining the <envar>NIX_SSHOPTS</envar> environment variable.
Specifies the NixOS target host. By setting this to something other than <replaceable>localhost</replaceable>, the system activation will happen on the remote host instead of the local machine. The remote host needs to be accessible over ssh, and for the commands <option>switch</option>, <option>boot</option> and <option>test</option> you need root access.
If <option>--build-host</option> is not explicitly specified, <option>--build-host</option> will implicitly be set to the same value as <option>--target-host</option>. So, if you only specify <option>--target-host</option> both building and activation will take place remotely (and no build artifacts will be copied to the local machine).
You can include a remote user name in the host name (<replaceable>user@host</replaceable>). You can also set ssh options by defining the <envar>NIX_SSHOPTS</envar> environment variable.
In addition, <command>nixos-rebuild</command> accepts various Nix-related flags, including <option>--max-jobs</option> / <option>-j</option>, <option>--show-trace</option>, <option>--keep-failed</option>, <option>--keep-going</option> and <option>--verbose</option> / <option>-v</option>. See the Nix manual for details.