NixOS Commands

nixos-enter, nixos-generate-config, and nixos-install all accept a --root <path> argument to change the path to the NixOS installation. By default, nixos-generate-config acts on /, and the others act on /mnt.

nixos-enter

Chroots into a NixOS installation.

Without a command, enters an interactive shell.

  • {--command | -c} <cmd> executes a command in the shell,
  • -- <args...> executes a command not in the shell.

nixos-generate-config

Generates configuration.nix if it doesn't already exist, and generates or updates hardware-configuration.nix.

nixos-install

Installs NixOS from an existing configuration.nix.

  • --no-root-passwd do not ask for a root password. Disables root login unless otherwise specified in configuration.nix.

nixos-option

Lists the properties of the specified option.

nixos-rebuild

Builds a system from the current configuration.

The following need root:

  • boot builds the new configuration and makes it the default boot target,
  • test builds the new configuration and modifies the currently running system to match it,
  • switch builds the new configuration, makes it the default boot target, and modifies the currently running system to match it.

While the following can be run as non-root:

  • build builds the new configuration and makes a symlink result,
  • dry-build shows what would be performed by build or boot but otherwise does nothing,
  • dry-activate shows what would be performed by test or switch but otherwise does nothing,
  • build-vm builds the new configuration and makes a symlink result, with a script result/bin/run-<hostname>-vm which runs a qemu virtual machine for the resulting system,
  • build-vm-with-bootloader does the same as build-vm but for testing purposes uses the normal configured bootloader inside the virtual machine.

see also NixOS Manual: Chapter 3. Changing the Configuration

nixos-version

Prints the version.