Nixos-rebuild: Difference between revisions

DoggoBit (talk | contribs)
Minor formatting changes, add {{cleanup}} and section about deploying on different target arch
Mightyiam (talk | contribs)
Correct position of references and categories
 
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:


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


== Usage ==
== Usage ==
Line 29: Line 31:
# nixos-rebuild --build-host user@example.com switch
# nixos-rebuild --build-host user@example.com switch
</syntaxHighlight>
</syntaxHighlight>
Add the flag <code>--use-substitutes</code> to make the remote host use substitutes instead of copying from your host to the remote host.
To build the system locally and deploy it on a remote host, use:
To build the system locally and deploy it on a remote host, use:
<syntaxHighlight lang=console>
<syntaxHighlight lang=console>
Line 41: Line 45:
</syntaxHighlight>
</syntaxHighlight>


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


{{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:
Line 117: 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 ==
* [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]
== References ==
<references />


[[Category:NixOS]]
[[Category:NixOS]]