LinuxCommandLibrary

nixos-rebuild

reconfigures a NixOS system by building a new configuration

TLDR

Build and switch to new configuration (make boot default)

$ sudo nixos-rebuild switch
copy
Build and switch with custom profile name
$ sudo nixos-rebuild switch -p [name]
copy
Build, switch, and install updates
$ sudo nixos-rebuild switch --upgrade
copy
Rollback to previous generation
$ sudo nixos-rebuild switch --rollback
copy
Build and make boot default without activating
$ sudo nixos-rebuild boot
copy
Build and test without making boot entry
$ sudo nixos-rebuild test
copy
Build configuration and run in virtual machine
$ sudo nixos-rebuild build-vm
copy
List available generations
$ nixos-rebuild list-generations
copy

SYNOPSIS

nixos-rebuild [switch|boot|test|build|build-vm] [--upgrade] [--rollback] [-p name]

DESCRIPTION

nixos-rebuild reconfigures a NixOS system by building a new configuration from /etc/nixos/configuration.nix and optionally activating it. NixOS uses a declarative configuration model where the entire system is described in Nix expressions.
Each build creates a new generation that can be selected at boot time. This allows safe rollback to previous working configurations if problems occur.

PARAMETERS

--upgrade

Update nixpkgs channel before building
--rollback
Roll back to previous generation
-p, --profile-name _name_
Name for the boot entry
--flake _uri_
Build from flake reference
--no-build-nix
Don't rebuild Nix during switch
--fast
Skip rebuilding Nix and documentation
--show-trace
Show detailed error traces

COMMANDS

switch

Build, activate, and make boot default
boot
Build and make boot default without activating
test
Build and activate without making boot entry
build
Build configuration without activating
build-vm
Build and open configuration in virtual machine
dry-build
Show what would be built
dry-activate
Show what would change on activation
list-generations
List available system generations

CAVEATS

Requires root privileges for most operations. Configuration errors prevent build completion. Large changes may require significant download and build time. The switch command restarts services that changed.

HISTORY

nixos-rebuild is part of NixOS, the Linux distribution based on the Nix package manager. NixOS was created by Eelco Dolstra and first released in 2003. It pioneered declarative system configuration and atomic upgrades with rollback capability.

SEE ALSO

nix(1), nix-env(1), nix-channel(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community