Skip to content

nixos-rebuild NixOS Rebuild

man nixos-rebuild

VM

nixos-rebuild build-vm --flake .#test1

Local

nixos-rebuild switch --flake .#myhostname

Or, historically: Edit /etc/nixos/configuration.nix and sudo nixos-rebuild switch.

Remote

See also nixos-anywhere.

Images

nixos-rebuild build-image --flake .#myhostname

Troubleshooting

It lacks a signature by a trusted key

copying path '/nix/store/0ffsqaf744z1mdv0w0ind94ipk4mm71r-nix.conf' to 'ssh://ixo'...
error: cannot add path '/nix/store/0ffsqaf744z1mdv0w0ind94ipk4mm71r-nix.conf' because it lacks a
signature by a trusted key

This happens when your user is not in nix.settings.trusted-users at first.

Read-only file system

/etc/nix/nix.conf: Read-only file system

This initial problem can be worked around by using --build-host $HOSTNEW --use-remote-sudo --ask-sudo-password.

sudo: a password is required

sudo: a terminal is required to read the password; either use ssh's -t option or configure an askpass helper
sudo: a password is required
error: while running command with remote sudo, did you forget to use --ask-sudo-password?

This can be worked around by adding --use-remote-sudo --ask-sudo-password (and then entering the password when prompted).

Alternatives