← 返回命令列表

Linux command

nixos-rebuild 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

Build and switch

sudo nixos-rebuild switch

Example

sudo nixos-rebuild switch -p [name]

Example

sudo nixos-rebuild switch --upgrade

Rollback

sudo nixos-rebuild switch --rollback

Example

sudo nixos-rebuild boot

Example

sudo nixos-rebuild test

Example

sudo nixos-rebuild build-vm

List

nixos-rebuild list-generations

说明

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.

参数

--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

FAQ

What is the nixos-rebuild command used for?

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.

How do I run a basic nixos-rebuild example?

Run `sudo nixos-rebuild switch` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --upgrade do in nixos-rebuild?

Update nixpkgs channel before building