From 27b26d8dcca11af05a7eddf001602569c0472735 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Fri, 3 Jan 2025 15:43:55 +0100 Subject: [PATCH] feat: test config in a vm --- README.md | 15 +++++++++++++++ modules/base.nix | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/README.md b/README.md index ab0b82f..c1102a0 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ See also: * [Default configuration](#default-configuration) * [Apply modified configuration](#apply-modified-configuration) * [ARM: Vanilla UEFI bootloader for the Raspberry Pi 3B+](#arm-vanilla-uefi-bootloader-for-the-raspberry-pi-3b) + * [Test config changes in a VM](#test-config-changes-in-a-vm) * [Update, build and switch](#update-build-and-switch) * [tldr](#tldr) * [Update](#update) @@ -158,6 +159,20 @@ Then install NixOS the way you prefer, but don't touch/modify the partition tabl See https://nixos.wiki/wiki/NixOS_on_ARM/UEFI#Installing +## Test config changes in a VM + +https://nix.dev/tutorials/nixos/nixos-configuration-on-vm.html + +- See `base.nix` -> `virtualisation.vmVariant` for build-vm specific options +- Import of `./hardware-configuration.nix` + - As build-vm uses `mkVMOverride` we can just leave the import + - If in doubt, remove/uncomment it + +```shell +nix-build '' -A vm -I nixos-config=./hosts/yodaTux/configuration.nix +./result/bin/run-yodaTux-vm && rm yodaTux.qcow2 +``` + ## Update, build and switch ### tldr diff --git a/modules/base.nix b/modules/base.nix index f3d856f..e57cf62 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -88,4 +88,15 @@ # https://nixos.wiki/wiki/Firewall # Note: Firewall rules may be bypassed/overwritten by Docker, as per https://github.com/NixOS/nixpkgs/issues/111852 networking.firewall.enable = true; + + # Options only for build.system.vm - they won’t get applied when building build.system.toplevel aka the normal system config. + # https://discourse.nixos.org/t/wayland-compositors-an-build-vm-not-working/46486/2 + virtualisation.vmVariant = { + users.users.yoda.initialPassword = "asdf"; + virtualisation.qemu.options = [ + "-device virtio-vga-gl" + "-display sdl,gl=on,show-cursor=off" + "-m 8G" + ]; + }; }