Nixos-rebuild: Difference between revisions
Links to Nixcademy blog posts on nixos-rebuild |
nixos-rebuild-ng is the new default |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
'''nixos-rebuild''' is the NixOS command used to apply changes made to the system configuration. It can also be used for a variety of other tasks related to managing the state of a NixOS system. | '''nixos-rebuild''' is the NixOS command used to apply changes made to the system configuration. It can also be used for a variety of other tasks related to managing the state of a NixOS system. | ||
<code>nixos-rebuild-ng</code> is a rewrite of <code>nixos-rebuild</code> in Python instead of Bash which has better performance and more features, and | <code>nixos-rebuild-ng</code> is a rewrite of <code>nixos-rebuild</code> in Python instead of Bash which has better performance and more features, and is the default in NixOS 25.11. | ||
== Usage == | == Usage == | ||
| Line 40: | Line 40: | ||
<code>--build-host</code> and <code>--target-host</code> can be used simultaneously, even with different hosts. | <code>--build-host</code> and <code>--target-host</code> can be used simultaneously, even with different hosts. | ||
If you are rebuilding a remote host as a non-root user, use the <code>- | If you are rebuilding a remote host as a non-root user, use the <code>--sudo</code> option to elevate on the remote machine during the rebuilding process: | ||
< | <syntaxhighlight lang="console"> | ||
$ nixos-rebuild --target-host user@example.com - | $ nixos-rebuild --target-host user@example.com --sudo switch | ||
</ | </syntaxhighlight> | ||
To enter a password while using remote sudo, | To enter a password while using remote sudo, add the flag <code>--ask-sudo-password</code>. | ||
{{Note|When rebuilding a remote host, you may see similar errors to the following: | {{Note|When rebuilding a remote host, you may see similar errors to the following: | ||
<blockquote>error: cannot add path '/nix/store/...' because it lacks a signature by a trusted key</blockquote> | <blockquote>error: cannot add path '/nix/store/...' because it lacks a signature by a trusted key</blockquote> | ||
If this occurs, add your non-root user or group to the <code>trusted-users</code> list in <code>/etc/nix/nix.conf</code>, which is the <code>nix.settings.trusted-users</code> option in NixOS.}} | If this occurs, add your non-root user or group to the <code>trusted-users</code> list in <code>/etc/nix/nix.conf</code>, which is the <code>nix.settings.trusted-users</code> option in NixOS. Please note that this is equivalent to having root access, [https://nix.dev/manual/nix/2.34/command-ref/conf-file.html#conf-trusted-users as described in the Nix manual].}} | ||
For a full list of sub-commands and options, see the <code>nixos-rebuild</code> man page. | For a full list of sub-commands and options, see the <code>nixos-rebuild</code> man page. | ||
| Line 121: | Line 121: | ||
* Add the resulting derivation to the system profile in <code>/nix/var/nix/profiles</code>, i. e. create a new generation in the system profile. | * Add the resulting derivation to the system profile in <code>/nix/var/nix/profiles</code>, i. e. create a new generation in the system profile. | ||
* Add the new generation to the bootloader menu as the new default and activate it. If you've manually built the system derivation, this can also be done with <code>result/bin/switch-to-configuration switch</code>. | * Add the new generation to the bootloader menu as the new default and activate it. If you've manually built the system derivation, this can also be done with <code>result/bin/switch-to-configuration switch</code>. | ||
== See also == | == See also == | ||
| Line 129: | Line 126: | ||
* [https://nixcademy.com/posts/nixos-rebuild/ Magic Deployments with nixos-rebuild, Nixcademy] | * [https://nixcademy.com/posts/nixos-rebuild/ Magic Deployments with nixos-rebuild, Nixcademy] | ||
* [https://nixcademy.com/posts/nixos-rebuild-remote-deployment/ Remote Deployments with nixos-rebuild, Nixcademy] | * [https://nixcademy.com/posts/nixos-rebuild-remote-deployment/ Remote Deployments with nixos-rebuild, Nixcademy] | ||
== References == | |||
<references /> | |||
[[Category:NixOS]] | |||