The file <filename>/etc/nixos/configuration.nix</filename> contains the current configuration of your machine. Whenever you’ve <linklinkend="ch-configuration">changed something</link> in that file, you should do
to build the new configuration, make it the default configuration for booting, and try to realise the configuration in the running system (e.g., by restarting system services).
This command doesn't start/stop <linklinkend="opt-systemd.user.services">user services</link> automatically. <command>nixos-rebuild</command> only runs a <literal>daemon-reload</literal> for each user with running user services.
to build the configuration and switch the running system to it, but without making it the boot default. So if (say) the configuration locks up your machine, you can just reboot to get back to a working configuration.
You can make your configuration show up in a different submenu of the GRUB 2 boot screen by giving it a different <emphasis>profile name</emphasis>, e.g.
which causes the new configuration (and previous ones created using <literal>-p test</literal>) to show up in the GRUB submenu “NixOS - Profile 'test'”. This can be useful to separate test configurations from “stable” configurations.
If you have a machine that supports hardware virtualisation, you can also test the new configuration in a sandbox by building and running a QEMU <emphasis>virtual machine</emphasis> that contains the desired configuration. Just do
The VM does not have any data from your host system, so your existing user accounts and home directories will not be available unless you have set <literal>mutableUsers = false</literal>. Another way is to temporarily add the following to your configuration:
<emphasis>Important:</emphasis> delete the $hostname.qcow2 file if you have started the virtual machine at least once without the right users, otherwise the changes will not get picked up. You can forward ports on the host to the guest. For instance, the following will forward host port 2222 to guest port 22 (SSH):