HOSTNAME := env_var_or_default("HOSTNAME", "")

# Build system and switch it
switch:
  sudo nixos-rebuild switch

# Build the ISO image
[no-cd]
build-iso:
  nix build .#nixosConfigurations.iso.config.system.build.isoImage
  nix eval --raw .#nixosConfigurations.iso.config.system.build.isoImage
  @echo

# Build a virtual machine
[no-cd]
build-vm hostname=HOSTNAME:
	nixos-rebuild build-vm --flake .#{{hostname}}

# Launch the virtual machine. Expects result to be in /etc/nixos.
[no-cd]
start-vm hostname=HOSTNAME:
  rm {{hostname}}.qcow2 || true
  ./result/bin/run-{{hostname}}-vm

# Build and start virtual machine
[no-cd]
run-vm hostname=HOSTNAME: (build-vm hostname) (start-vm hostname)
