6 .Nd reconfigure a NixOS machine
13 .Cm switch | boot | test | build | dry-build | dry-activate | edit | repl | build-vm | build-vm-with-bootloader | list-generations Op Fl -json
16 .Op Fl -upgrade | -upgrade-all
17 .Op Fl -install-bootloader
22 .Op Fl -file | f Ar path
23 .Op Fl -attr | A Ar attrPath
24 .Op Fl -flake Ar flake-uri
26 .Op Fl -recreate-lock-file
27 .Op Fl -no-update-lock-file
28 .Op Fl -no-write-lock-file
30 .Op Fl -commit-lock-file
31 .Op Fl -update-input Ar input-path
32 .Op Fl -override-input Ar input-path flake-url
34 .Op Fl -profile-name | p Ar name
35 .Op Fl -specialisation | c Ar name
37 .Op Fl -build-host Va host
38 .Op Fl -target-host Va host
39 .Op Fl -use-remote-sudo
44 .Op Fl -log-format Ar format
45 .Op Fl -no-build-output | Q
46 .Op Fl -max-jobs | j Va number
47 .Op Fl -cores Va number
48 .Op Fl -keep-going | k
49 .Op Fl -keep-failed | K
52 .Op Fl -option Ar name value
54 .Op Fl -builders Va builder-spec
55 .Op Fl -accept-flake-config
56 .Op Fl -print-build-logs | L
66 This command updates the system so that it corresponds to the
67 configuration specified in
68 .Pa /etc/nixos/configuration.nix Ns
70 .Pa /etc/nixos/flake.nix
71 or the file and attribute specified by the
75 options. Thus, every time you modify the configuration or any other NixOS
78 to make the changes take effect. It builds the new system in
80 , runs its activation script, and stop and (re)starts any system services if
81 needed. Please note that user services need to be started manually as they
82 aren't detected by the activation script at the moment.
85 This command has one required argument, which specifies the desired
86 operation. It must be one of the following:
87 .Bl -tag -width indent
89 Build and activate the new configuration, and make it the boot default. That
90 is, the configuration is added to the GRUB boot menu as the default
91 menu entry, so that subsequent reboots will boot the system into the new
92 configuration. Previous configurations activated with
93 .Ic nixos-rebuild switch
95 .Ic nixos-rebuild boot
96 remain available in the GRUB menu.
98 Note that if you are using specializations, running just
99 .Ic nixos-rebuild switch
100 will switch you back to the unspecialized, base system \(em in that case, you
101 might want to use this instead:
102 .Bd -literal -offset indent
103 $ nixos-rebuild switch --specialisation your-specialisation-name
106 This command will build all specialisations and make them bootable just
108 .Ic nixos-rebuild switch
109 does \(em the only thing different is that it will switch to given
110 specialisation instead of the base system; it can be also used to switch from
111 the base system into a specialised one, or to switch between specialisations.
114 Build the new configuration and make it the boot default (as with
115 .Ic nixos-rebuild switch Ns
116 ), but do not activate it. That is, the system continues to run the previous
117 configuration until the next reboot.
120 Build and activate the new configuration, but do not add it to the GRUB
121 boot menu. Thus, if you reboot the system (or if it crashes), you will
122 automatically revert to the default configuration (i.e. the
123 configuration resulting from the last call to
124 .Ic nixos-rebuild switch
126 .Ic nixos-rebuild boot Ns
129 Note that if you are using specialisations, running just
130 .Ic nixos-rebuild test
131 will activate the unspecialised, base system \(em in that case, you might want
133 .Bd -literal -offset indent
134 $ nixos-rebuild test --specialisation your-specialisation-name
137 This command can be also used to switch from the base system into a
138 specialised one, or to switch between specialisations.
141 Build the new configuration, but neither activate it nor add it to the
142 GRUB boot menu. It leaves a symlink named
144 in the current directory, which points to the output of the top-level
146 derivation. This is essentially the same as doing
147 .Bd -literal -offset indent
148 $ nix-build /path/to/nixpkgs/nixos -A system
151 Note that you do not need to be root to run
152 .Ic nixos-rebuild build Ns
156 Show what store paths would be built or downloaded by any of the
157 operations above, but otherwise do nothing.
160 Build the new configuration, but instead of activating it, show what
161 changes would be performed by the activation (i.e. by
162 .Ic nixos-rebuild test Ns
163 ). For instance, this command will print which systemd units would be restarted.
164 The list of changes is not guaranteed to be complete.
168 .Pa configuration.nix
169 in the default editor.
172 Opens the configuration in
176 Build a script that starts a NixOS virtual machine with the desired
177 configuration. It leaves a symlink
179 in the current directory that points (under
180 .Ql result/bin/run\- Ns Va hostname Ns \-vm Ns
182 at the script that starts the VM. Thus, to test a NixOS configuration in
183 a virtual machine, you should do the following:
184 .Bd -literal -offset indent
185 $ nixos-rebuild build-vm
186 $ ./result/bin/run-*-vm
189 The VM is implemented using the
191 package. For best performance, you should load the
195 kernel modules to get hardware virtualisation.
197 The VM mounts the Nix store of the host through the 9P file system. The
198 host Nix store is read-only, so Nix commands that modify the Nix store
199 will not work in the VM. This includes commands such as
201 ; to change the VM’s configuration, you must halt the VM and re-run the commands
204 The VM has its own ext3 root file system, which is automatically created when
205 the VM is first started, and is persistent across reboots of the VM. It is
207 .Ql ./ Ns Va hostname Ns .qcow2 Ns
209 .\" The entire file system hierarchy of the host is available in
214 .It Cm build-vm-with-bootloader
217 , but boots using the regular boot loader of your configuration (e.g. GRUB 1 or
218 2), rather than booting directly into the kernel and initial ramdisk of the
219 system. This allows you to test whether the boot loader works correctly. \
220 However, it does not guarantee that your NixOS configuration will boot
221 successfully on the host hardware (i.e., after running
222 .Ic nixos-rebuild switch Ns
223 ), because the hardware and boot loader configuration in the VM are different.
224 The boot loader is installed on an automatically generated virtual disk
229 .It Cm list-generations Op Fl -json
230 List the available generations in a similar manner to the boot loader
231 menu. It shows the generation number, build date and time, NixOS version,
232 kernel version and the configuration revision.
233 There is also a json version of output available.
239 .Bl -tag -width indent
240 .It Fl -upgrade , -upgrade-all
241 Update the root user's channel named
243 before rebuilding the system.
247 channel, the root user's channels which have a file named
248 .Ql .update-on-nixos-rebuild
249 in their base directory will also be updated.
253 updates all of the root user's channels.
255 .It Fl -install-bootloader
256 Causes the boot loader to be (re)installed on the device specified by the
257 relevant configuration options.
264 attribute in Nixpkgs, and uses the resulting instance of the Nix package manager
265 to build the new system configuration. This is necessary if the NixOS modules
266 use features not provided by the currently installed version of Nix. This option
267 disables building a new Nix.
272 \&. This option is useful if you call
274 frequently (e.g. if you’re hacking on a NixOS module).
277 Instead of building a new configuration as specified by
278 .Pa /etc/nixos/configuration.nix Ns
279 , roll back to the previous configuration. (The previous configuration is
280 defined as the one before the “current” generation of the Nix profile
281 .Pa /nix/var/nix/profiles/system Ns
284 .It Fl -builders Ar builder-spec
285 Allow ad-hoc remote builders for building the new system. This requires
288 (usually root) to be configured as a trusted user in the Nix daemon. This can be
289 achieved by using the
290 .Va nix.settings.trusted-users
291 NixOS option. Examples values for that option are described in the
293 chapter in the Nix manual, (i.e.
294 .Ql --builders \(dqssh://bigbrother x86_64-linux\(dq Ns
295 ). By specifying an empty string existing builders specified in
296 .Pa /etc/nix/machines
298 .Ql --builders \(dq\(dq
299 for example when they are not reachable due to network connectivity.
301 .It Fl -profile-name Ar name , Fl p Ar name
302 Instead of using the Nix profile
303 .Pa /nix/var/nix/profiles/system
304 to keep track of the current and previous system configurations, use
305 .Pa /nix/var/nix/profiles/system-profiles/ Ns Va name Ns
306 \&. When you use GRUB 2, for every system profile created with this flag, NixOS
307 will create a submenu named
308 .Dq NixOS - Profile Va name
309 in GRUB’s boot menu, containing the current and previous configurations of this profile.
311 For instance, if you want to test a configuration file named
313 without affecting the default system profile, you would do:
314 .Bd -literal -offset indent
315 $ nixos-rebuild switch -p test -I nixos-config=./test.nix
318 The new configuration will appear in the GRUB 2 submenu
319 .Dq NixOS - Profile 'test' Ns
322 .It Fl -specialisation Ar name , Fl c Ar name
323 Activates given specialisation; when not specified, switching and testing
324 will activate the base, unspecialised system.
326 .It Fl -build-host Ar host
327 Instead of building the new configuration locally, use the specified host
328 to perform the build. The host needs to be accessible with
330 and must be able to perform Nix builds. If the option
332 is not set, the build will be copied back to the local machine when done.
336 is not specified, Nix will be built both locally and remotely. This is because
337 the configuration will always be evaluated locally even though the building
338 might be performed remotely.
340 You can include a remote user name in the host name
341 .Ns ( Va user@host Ns
342 ). You can also set ssh options by defining the
344 environment variable.
346 .It Fl -target-host Ar host
347 Specifies the NixOS target host. By setting this to something other than an
348 empty string, the system activation will happen on the remote host instead of
349 the local machine. The remote host needs to be accessible over
357 you need root access.
361 is not explicitly specified or empty, building will take place locally.
363 You can include a remote user name in the host name
364 .Ns ( Va user@host Ns
365 ). You can also set ssh options by defining the
367 environment variable.
372 .Va nixpkgs.crossSystem
373 setting of the given configuration but disregards the true architecture of the
374 target host. Hence the
375 .Va nixpkgs.crossSystem
376 setting has to match the target platform or else activation will fail.
378 .It Fl -use-substitutes
379 When set, nixos-rebuild will add
381 to each invocation of nix-copy-closure. This will only affect the behavior of
386 is also set. This is useful when the target-host connection to cache.nixos.org
387 is faster than the connection between hosts.
389 .It Fl -use-remote-sudo
390 When set, nixos-rebuild prefixes activation commands that run on the
394 \&. Setting this option allows deploying as a non-root user.
397 When set, nixos-rebuild will not request a tty when executing commands on the
401 \&. This may help avoid corrupted terminal output when running multiple
402 nixos-rebuild commands in parallel, but may also prevent the remote
404 from working properly.
406 .It Fl -file Ar path , Fl f Ar path
407 Enable and build the NixOS system from the specified file. The file must
408 evaluate to an attribute set, and it must contain a valid NixOS configuration
411 \&. This is useful for building a NixOS system from a nix file that is not
412 a flake or a NixOS configuration module. Attribute set a with valid NixOS
413 configuration can be made using
415 function in nixpkgs or importing and calling
416 .Pa nixos/lib/eval-config.nix
417 from nixpkgs. If specified without
419 option, builds the configuration from the top-level
420 attribute of the file.
422 .It Fl -attr Ar attrPath , Fl A Ar attrPath
423 Enable and build the NixOS system from nix file and use the specified attribute
424 path from file specified by the
426 option. If specified without
430 in current directory.
432 .It Fl -flake Va flake-uri Ns Op Va #name
433 Build the NixOS system from the specified flake. It defaults to the directory
434 containing the target of the symlink
435 .Pa /etc/nixos/flake.nix Ns
436 , if it exists. The flake must contain an output named
437 .Ql nixosConfigurations. Ns Va name Ns
440 is omitted, it default to the current host name.
446 .Pa /etc/nixos/flake.nix
447 exists. With this option, it is possible to build non-flake NixOS configurations
448 even if the current NixOS systems uses flakes.
453 accepts following options from nix commands that the tool calls:
456 flake-related options:
458 .Fl -recreate-lock-file Ns ,
459 .Fl -no-update-lock-file Ns ,
460 .Fl -no-write-lock-file Ns ,
461 .Fl -no-registries Ns ,
462 .Fl -commit-lock-file Ns ,
463 .Fl -update-input Ar input-path Ns ,
464 .Fl -override-input Ar input-path flake-url Ns
474 .Fl -no-build-output Ns ,
481 .Fl -keep-failed Ns ,
488 .Fl -accept-flake-config Ns ,
489 .Fl -print-build-logs Ns ,
500 .Ic nix flake lock --help
508 .Bl -tag -width indent
510 Path to the main NixOS configuration module. Defaults to
511 .Pa /etc/nixos/configuration.nix Ns
515 A colon-separated list of directories used to look up Nix expressions enclosed
516 in angle brackets (e.g. <nixpkgs>). Example:
517 .Bd -literal -offset indent
522 Additional options to be passed to
527 .It Ev NIXOS_SWITCH_USE_DIRTY_ENV
528 Expose the the current environment variables to post activation scripts. Will
531 during system activation. Possibly dangerous, specially in remote environments
532 (e.g.: via SSH). Will be removed in the future.
538 .Bl -tag -width indent
539 .It Pa /etc/nixos/flake.nix
540 If this file exists, then
542 will use it as if the
544 option was given. This file may be a symlink to a
546 in an actual flake; thus
550 .It Pa /run/current-system
551 A symlink to the currently active system configuration in the Nix store.
553 .It Pa /nix/var/nix/profiles/system
554 The Nix profile that contains the current and previous system
555 configurations. Used to generate the GRUB boot menu.
561 This command should be renamed to something more descriptive.
569 .An the Nixpkgs/NixOS contributors