nixos-rebuild(8)
β¨ NAME β¨
nixos-rebuild β the command that reconfigures a NixOS machine π
(straight out of the System Manager's Manual, section 8, iykyk)
π SYNOPSIS π
okay so here's the whole vibe, every flag, no cap:
nixos-rebuild [--verbose] [--quiet] [--max-jobs MAX_JOBS] [--cores
CORES] [--log-format LOG_FORMAT] [--keep-going] [--keep-failed]
[--fallback] [--repair] [--option OPTION OPTION] [--builders BUILDERS]
[--include INCLUDE]
[--print-build-logs] [--show-trace] [--accept-flake-config] [--refresh]
[--impure] [--offline] [--no-net] [--recreate-lock-file]
[--no-update-lock-file] [--no-write-lock-file] [--no-registries]
[--commit-lock-file]
[--update-input UPDATE_INPUT] [--override-input OVERRIDE_INPUT
OVERRIDE_INPUT] [--no-build-output] [--use-substitutes] [--help]
[--debug] [--file FILE] [--attr ATTR] [--flake [FLAKE]] [--no-flake]
[--install-bootloader]
[--profile-name PROFILE_NAME] [--specialisation SPECIALISATION]
[--rollback] [--store-path STORE_PATH] [--upgrade] [--upgrade-all]
[--json] [--elevate {none,sudo,run0}] [--ask-elevate-password]
[--no-reexec]
[--build-host BUILD_HOST] [--target-host TARGET_HOST] [--no-build-nix]
[--image-variant IMAGE_VARIANT]
[{switch,boot,test,build,edit,repl,dry-build,dry-run,dry-activate,build-image,build-vm,build-vm-with-bootloader,list-generations}]
πΈ DESCRIPTION πΈ
okay bestie, here's the whole thing π«Ά This command updates the system so that it corresponds to the configuration specified in /etc/nixos/configuration.nix, /etc/nixos/flake.nix, /etc/nixos/system.nix β or whatever file and attribute you point at with the --file, --attr or --flake options. So basically every single time you touch the config or any other NixOS module, you have to run nixos-rebuild to make those changes actually take effect. That's the whole gig β¨
What it does under the hood: it builds the new system in /nix/store, runs its activation script, then stops and (re)starts any system services if needed. Iconic. But heads up: user services need to be started manually, because the activation script doesn't detect them at the moment π
This command has one required argument, and it specifies the desired operation. It must be one of the following:
π₯ switch
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 nixos-rebuild switch or nixos-rebuild boot remain available in the GRUB menu. slay π
β οΈ Important vibe check: if you're using specialisations, running just nixos-rebuild switch will switch you back to the unspecialized, base system β in that case, you might want to use this instead:
$ nixos-rebuild switch --specialisation your-specialisation-name
This command will build all specialisations and make them bootable just like a regular nixos-rebuild switch does β the only thing different is that it will switch to the given specialisation instead of the base system; it can also be used to switch from the base system into a specialised one, or to switch between specialisations. so versatile, honestly π
π₯Ύ boot
Build the new configuration and make it the boot default (as with nixos-rebuild switch), but do not activate it. That is, the system continues to run the previous configuration until the next reboot. it's giving "I'll deal with it later" energy π
π§ͺ test
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 nixos-rebuild switch or nixos-rebuild boot. cute little safety net πΈ
β οΈ Same specialisation warning as before: if you're using specialisations, running just nixos-rebuild test will activate the unspecialised, base system β in that case, you might want to use this instead:
$ nixos-rebuild test --specialisation your-specialisation-name
This command can also be used to switch from the base system into a specialised one, or to switch between specialisations. yes bestie, the flexibility π
π οΈ build
Build the new configuration, but neither activate it nor add it to the GRUB boot menu. It leaves a symlink named result in the current directory, which points to the output of the top-level "system" derivation. This is essentially the same as doing:
$ nix-build /path/to/nixpkgs/nixos -A system
π ngl the best part: you do not need to be root to run nixos-rebuild build. no sudo, no stress, we love to see it π«Ά
π«§ dry-build
Show what store paths would be built or downloaded by any of the operations above β but otherwise do nothing. it's the window-shopping of builds π
π dry-activate
Build the new configuration, but instead of activating it, show what changes would be performed by the activation (i.e. by nixos-rebuild test). For instance, this command will print which systemd units would be restarted. The list of changes is not guaranteed to be complete β so like, it's a preview, not a contract, k? π
βοΈ edit
Opens configuration.nix in the default editor. simple. elegant. main character energy π
π§ repl
Opens the configuration in nix repl. yes queen, live in the repl π¦
πΏ build-image
Build a disk-image variant, pre-configured for the given platform/provider. Select a variant with the --image-variant option, or run without any options to get a list of available variants:
$ nixos-rebuild build-image --image-variant proxmox
π₯οΈ build-vm
Build a script that starts a NixOS virtual machine with the desired configuration. It leaves a symlink result in the current directory that points (under result/bin/run-_hostname_-vm) at the script that starts the VM. So to test a NixOS configuration in a virtual machine, you should do the following:
$ nixos-rebuild build-vm && ./result/bin/run-*-vm
The VM is implemented using the qemu package. For best performance, you should load the kvm-intel or kvm-amd kernel modules to get hardware virtualisation π₯ (fr fr, do this, the difference is real)
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 nixos-rebuild β to change the VM's configuration, you must halt the VM and re-run the commands above. annoying? yes. the rules? the rules. π
The VM has its own ext3 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 ./hostname.qcow2 πΎ
π₯Ώ build-vm-with-bootloader
Like build-vm, 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 π
β οΈ but bestie, caveat time: it does not guarantee that your NixOS configuration will boot successfully on the host hardware (i.e., after runningnixos-rebuild switch), 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/bootpartition.
π list-generations [--json]
List the available generations in a similar manner to the boot loader menu. It shows the generation number, build date and time, NixOS version, kernel version and the configuration revision. There is also a json version of output available β¨ (iykyk, --json is the move for scripting)
--upgrade,--upgrade-allβ updates the root user's channel namednixosbefore rebuilding the system. π
And like, it's not just that one channel bestie β any of root's channels that have a file named .update-on-nixos-rebuild sitting in their base directory get updated too.
Passing --upgrade-all updates all of the root user's channels. periodt.
--install-bootloaderβ makes the boot loader get (re)installed onto the device that the relevant configuration options point at. β¨--no-reexecβ okay so normallynixos-rebuildis extra and first finds + builds itself from theconfig.system.build.nixos-rebuildattribute of the current user channel or flake, then execs into that copy so you're running with the latest bug-fixes. This flag turns that whole glow-up off and just uses thenixos-rebuildinstance you already have. π--rollbackβ instead of building a shiny new configuration as specified by/etc/nixos/configuration.nix, you roll back to the previous configuration. (And "previous" means the one before the current generation of the Nix profile/nix/var/nix/profiles/system.) lowkey the undo button π«Ά--store-pathpath β use a pre-built NixOS system store path at path instead of evaluating and building from the configuration. This skips the evaluation and build phases entirely, no cap. The path must be a valid NixOS system closure β like, it has to containnixos-versionandbin/switch-to-configuration. π
This is the move for deploying closures that were built elsewhere, e.g. in CI systems or on remote build machines. iconic.
Can only be used with switch, boot, test, and dry-activate actions. Mutually exclusive with --rollback, --flake, --file, and --attr. And the --build-host option is ignored when --store-path is specified. π
--buildersbuilder-spec β allow ad-hoc remote builders for building the new system. This requires the user executingnixos-rebuild(usually root) to be configured as a trusted user in the Nix daemon β you do that with thenix.settings.trusted-usersNixOS option. Example values for that option live in the "Remote builds" chapter of the Nix manual, i.e.--builders "ssh://bigbrother x86_64-linux". π
And if you pass an empty string, existing builders specified in /etc/nix/machines get ignored: --builders "" β chef's kiss for when they're not reachable due to network connectivity. β¨
--profile-namename,-pname β instead of using the Nix profile/nix/var/nix/profiles/systemto keep track of the current and previous system configurations, use/nix/var/nix/profiles/system-profiles/name. When you're on GRUB 2, every system profile you create with this flag gets its own submenu named "NixOS - Profile name" in GRUB's boot menu, containing the current and previous configurations of that profile. π
For instance, if you want to test a configuration file named test.nix without affecting the default system profile, you would do:
$ nixos-rebuild switch -p test -I nixos-config=./test.nix
The new configuration will appear in the GRUB 2 submenu "NixOS - Profile 'test'". πΈ
--specialisationname,-cname β activates the given specialisation; when it's not specified, switching and testing will activate the base, unspecialised system. π¦--image-variantvariant β selects an image variant to build from theconfig.system.build.imagesattribute of the given configuration. A list of variants gets printed if this option remains unset. π--build-hosthost β instead of building the new configuration locally, use the specified host to do the build. The host needs to be accessible withssh, and it must be able to perform Nix builds. If the--target-hostoption isn't set, the build gets copied back to the local machine when it's done. π₯
You can include a remote user name in the host name (user@host). You can also set ssh options by defining the NIX_SSHOPTS environment variable. π
--target-hosthost β specifies the NixOS target host. By setting this to anything other than an empty string, system activation happens on the remote host instead of the local machine. The remote host needs to be accessible overssh, and for the commandsswitch,bootandtestyou need root access. π
If --build-host isn't explicitly specified or is empty, building takes place locally.
You can include a remote user name in the host name (user@host). You can also set ssh options by defining the NIX_SSHOPTS environment variable.
β οΈ Heads up:nixos-rebuildhonors thenixpkgs.crossSystemsetting of the given configuration but disregards the true architecture of the target host. So thatnixpkgs.crossSystemsetting has to match the target platform or else activation will fail. π fr fr, no cap.
--use-substitutesβ when set,nixos-rebuildadds--use-substitutesto each invocation ofnix copy. This only affectsnixos-rebuild's behavior if--target-hostor--build-hostis also set. It's the moment when the target-host connection tocache.nixos.orgis faster than the connection between hosts β we love a bandwidth shortcut. β‘--elevate {none,sudo,run0}β privilege-elevation method used for activation commands. Setting this option allows deploying as a non-root user. π
sudo prefixes commands with sudo. Additional sudo options can be passed via the NIX_SUDOOPTS environment variable.
run0 uses systemd's polkit-based elevation. Locally this runs run0 directly so the user's normal polkit agent handles any prompts. With --target-host the equivalent systemd-run --uid=0 --pipe form is used (no remote TTY is allocated). Unless --ask-elevate-password is also passed, the deploying user must be granted the polkit action org.freedesktop.systemd1.manage-units on the target host without authentication, e.g. via security.polkit.extraConfig. π
--ask-elevate-password,-Sβ prompt locally for a password and feed it to the elevation method. Implies--elevate=sudoif--elevateisn't given. π
For sudo this uses sudo --stdin. For run0 the command gets wrapped in polkit-stdin-agent, which registers a per-process polkit agent and answers the PAM conversation from the supplied password. The machine performing the elevation (the local host, or the target host with --target-host) must set system.tools.nixos-rebuild.enableRun0Elevation = true. --elevate=run0 --ask-elevate-password is not usable otherwise. π
--sudoβ alias for--elevate=sudo. π--ask-sudo-passwordβ alias for--elevate=sudo --ask-elevate-password. π--use-remote-sudoβ deprecated, use--elevate=sudoinstead. she's retired β¨--filepath,-fpath β build the NixOS system from the specified file. The file must evaluate to an attribute set, and it must contain a valid NixOS configuration at attribute attrPath. This is useful for building a NixOS system from a nix file that isn't a flake or a NixOS configuration module. π¦
An attribute set with a valid NixOS configuration can be made using the nixos function in nixpkgs, or by importing and calling nixos/lib/eval-config.nix from nixpkgs. If specified without the --attr option, it builds the configuration from the top-level attribute set of the file. Using this option disables automatic flake detection, same as --no-flake. π
--attrattrPath,-AattrPath β build the NixOS system from a nix file and use the specified attribute path from the file specified by the--fileoption. If specified without the--fileoption, it usessystem.nixin the current directory, the system-wide<nixos-system>file, or finally,/etc/nixos/system.nix. Using this option disables automatic flake detection, same as--no-flake. β--flakeflake-uri[#name],-Fflake-uri[#name] β build the NixOS system from the specified flake. It defaults to the directory containing the target of the symlink/etc/nixos/flake.nix, if that exists. The flake must contain an output namednixosConfigurations.name. If name is omitted, it defaults to the current host name. π--no-flakeβ do not imply--flakeif/etc/nixos/flake.nixexists. With this option it's possible to build non-flake NixOS configurations even if the current NixOS system uses flakes. π--diffβ show the diff between the system closure in/run/current-systemand the newly built system closure. (available for actions:build,boot,test,switch) π
This is similar to running nix store diff-closures /run/current-system result after build. obsessed with seeing the receipts honestly.
π Flake-related options
In addition, nixos-rebuild accepts the following options from the nix commands that the tool calls. First up, the flake ones:
--accept-flake-config--refresh--impure--offline--no-net--recreate-lock-file--no-update-lock-file--no-write-lock-file--no-registries--commit-lock-file--update-inputinput-path--override-inputinput-path flake-url
π¨ Builder options
And these builder besties:
--verbose,-v--quiet--log-format--no-build-output,-Q--no-link--max-jobs,-j--cores--keep-going,-k--keep-failed,-K--fallback--include,-I--option--repair--builders--print-build-logs,-L--show-trace
See the Nix manual, nix flake lock --help or nix-build --help for the details. iykyk π
πΈ ENVIRONMENT πΈ
NIXOS_CONFIGβ path to the main NixOS configuration module. Defaults to/etc/nixos/configuration.nix. πNIX_PATHβ a colon-separated list of directories used to look up Nix expressions enclosed in angle brackets (e.g.<nixpkgs>). Example:
nixpkgs=./my-nixpkgs
NIX_SSHOPTSβ additional options to be passed tosshon the command line. π¦NIXOS_REBUILD_SSH_DEFAULT_OPTSβ replaces the built-in default ssh options (connection sharing via a privateControlMasterthat is closed on exit). If empty, no default options are added. β¨NIX_SUDOOPTSβ additional options to be passed tosudoon the command line. πNIXOS_REBUILD_NO_SYSTEMD_RUNβ if set, thennixos-rebuildwill run without thesystemd-runwrapper. π«Ά
π FILES π
okay so before we get into the actual files, quick vibe check β these are the paths nixos-rebuild lowkey keeps an eye on, and knowing them is chef's kiss for understanding why it does what it does π
/etc/nixos/system.nixβ if this file exists, thennixos-rebuildwill use it as if the--fileoption was given. This allows to build a self-contained system configuration, without requiring βnixosβ channel. literally the "i brought my own config, thanks" energy β¨/etc/nixos/flake.nixβ if this file exists, thennixos-rebuildwill use it as if the--flakeoption was given. This file may be a symlink to aflake.nixin an actual flake; thus/etc/nixosneed not be a flake. no cap, you can just point it at your real flake and it's fine π«Ά/run/current-systemβ a symlink to the currently active system configuration in the Nix store. that's the system you're living in right now, bestie π/nix/var/nix/profiles/systemβ the Nix profile that contains the current and previous system configurations. Used to generate the GRUB boot menu. so like, this is the reason you can pick an older gen at boot and save yourself ππ₯
ngl these four paths are the whole plot.system.nixandflake.nixare the "autodetect my config" girlies πΈ, and the other two are the "this is what's live and this is the history" girlies π
π AUTHORS π
Nixpkgs/NixOS contributors β iconic collective behaviour, we love a whole community serving π«Άβ¨
and that's a wrap on nixos-rebuild(8), bestie!! this page came to you from nixpkgs and its date stamp is the absolutely legendary 1980-01-02 ππ go forth and rebuild responsibly, mwah ππ¦π
π¦ where this page comes from
- nixpkgs unstable: nixos-rebuild-ng 26.11
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms