Nixos-rebuild: Difference between revisions

Mightyiam (talk | contribs)
Correct position of references and categories
Axka (talk | contribs)
nixos-rebuild-ng is the new default
 
(One intermediate revision by one other user 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 will become the default in NixOS 25.11.
<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>--use-remote-sudo</code> option to elevate on the remote machine during the rebuilding process:
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>
<syntaxhighlight lang="console">
$ nixos-rebuild --target-host user@example.com --use-remote-sudo switch
$ nixos-rebuild --target-host user@example.com --sudo switch
</syntaxHighlight>
</syntaxhighlight>


To enter a password while using remote sudo, prefix the command with <code>NIX_SSHOPTS="-o RequestTTY=force"</code>, or add <code>--ask-sudo-password</code> with <code>nixos-rebuild-ng</code>.
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.