Hello, I’m converting my NixOS configuration to a flake and refactoring it, and I discovered how useful nixos-rebuild build-vm
can be to test out my config in a VM before committing it to my machine.
However, I need some settings to be different when I’m in a VM. What’s the best way to detect that the system is being built by build-vm
?
I’ve come accross this question, sadly without answer: Is there a way to determine if the config is used to build a vm?
I found out that running build-vm
includes https://github.com/NixOS/nixpkgs/blob/2a93ea177c3d7700b934bf95adfe00c435f696b8/nixos/modules/virtualisation/qemu-vm.nix which sets services.qemuGuest.enable
to true. So I can use this value to detect that a VM is being built, but it feels dirty. Is there a better way?
PS: I discovered that you can build and run the VM in one step with nix run '.#nixosConfigurations.HOSTNAME.config.system.build.vm'
. Might be obvious but maybe this can be useful for someone.