This is very much inspired by (at least) the following configurations:
-
Download the latest NixOS minimal install ISO In a terminal window run:
make nixos/download
-
Create and start the virtual machine In a terminal window run:
make vm/create
This will create and start the VM. The default name for the VM is
devbox
, to use a different name you can provide the name in theNIX_NAME
environment variable:NIX_NAME=my-awesome-box make vm/create
Wait for the VM to start (this might take a while as it downloads the ISO and boots the installer). If you want to save some time, you can also give the path to the installer ISO using the environment variable
NIX_ISO
:NIX_ISO=/tmp/nixos-minimal.iso make vm/create
-
Change the root password In the VM, switch to root user:
sudo su
and change the password:passwd
(the new password must be root) -
Install NixOS
VM_IP=xxx.xxx.xxx.xxx make nixos/install
You can find out the IP address of the VM either by running
ip a
in the VM or from your hosts terminal by running:virsh net-dhcp-leases default | grep nixos | awk '{ print $5 }' | sed 's/\/.\*//'
This will end up in an error:
make: *** [Makefile:39: nixos/install] Error 255
but you can safely ignore this, it's just because the VM is rebooting. -
Take a snapshot of the VM (optional) At this point you can take a snapshot of the VM if you want, just so you have a good base to return to in case you mess something up. See: snapshot management
-
Bootstrap the nix configuration
VM_IP=xxx.xxx.xxx.xxx make nixos/bootstrap
This will by default create a user
tuomo
, but if you want to change that, you can provide the username in the environment variableNIX_USER
:NIX_USER=johndoe make nixos/bootstrap
-
Change your user's password Login as the normal user (password is
password
) and change the password to whatever you want.You might also want to change the root password and disable ssh for root.
-
Finalize the user setup
VM_IP=xxx.xxx.xxx.xxx make nixos/usersetup
This will install Home Manager and apply user configurations.
-
Enjoy! After making any changes to the
home-manager
configs, (in the nix-config repo folder) run:home-manager switch --flake .#tuomo
And after any system wide changes, (in the nix-config repo folder) run:
sudo nixos-rebuild switch --flake .#
-
Create snapshot
virsh shutdown --domain devbox virsh snapshot-create-as --domain devbox --name "pre-bootstrap" virsh start devbox
replace
devbox
with the name of your VM if you changed it. -
Reverting back to the snapshot
virsh shutdown --domain devbox virsh snapshot-revert --domain devbox --snapshotname "pre-bootstrap" --running
-
Listing snapshots
virsh snapshot-list devbox
-
Deleting a snapshot
virsh snapshot-delete --domain devbox --snapshotname "pre-bootstrap"
-
Find out the MAC address of the VM:
virsh dumpxml devbox |grep -i '<mac'
-
Edit the default network:
virsh net-edit default
-
Find the following section:
<dhcp> <range start='xxx.xxx.xxx.xxx' end='xxx.xxx.xxx.xxx' />
And append the static IP after the range:
<dhcp> <range start='xxx.xxx.xxx.xxx' end='xxx.xxx.xxx.xxx' /> <host mac='XX:XX:XX:XX:XX:XX' name='devbox' ip='xxx.xxx.xxx.xxx' />
-
Restart the DHCP service:
virsh net-destroy default virsh net-start default
virt-viewer --connect qemu:///system --wait devbox
virsh --connect qemu:///system console devbox
- Stop the VM with
virsh destroy devbox
- Remove the domain with
virsh undefine devbox --nvram
(deletes the VM) - Remove the disk image