{ pkgs, config, lib, microvm, disko, agenix, machine, machines, dns, nixos-hardware, ... }: { imports = [ microvm.nixosModules.host ] ++ lib.lists.optional (machine.isRaspberryPi) nixos-hardware.nixosModules.raspberry-pi-4; config = { boot = lib.mkIf (machine.isHypervisor) { kernelModules = [ "kvm-intel" ]; extraModulePackages = [ ]; initrd = { availableKernelModules = [ "ahci" "xhci_pci" "nvme" "usbhid" "usb_storage" "sd_mod" "sdhci_pci" ]; kernelModules = [ ]; }; loader = { systemd-boot.enable = true; efi.canTouchEfiVariables = true; }; }; nixpkgs = { config.allowUnfree = true; # TODO: do we need this? # hostPlatform = machine.arch; }; hardware.cpu.intel.updateMicrocode = lib.mkIf (machine.isHypervisor) config.hardware.enableRedistributableFirmware; age.identityPaths = [ "/etc/age_ed25519" ]; nix = { package = pkgs.nixFlakes; extraOptions = '' experimental-features = nix-command flakes ''; }; system = { stateVersion = "23.05"; activationScripts.diff = '' if [[ -e /run/current-system ]]; then ${pkgs.nix}/bin/nix store diff-closures /run/current-system "$systemConfig" fi ''; }; microvm.vms = let vmsForHypervisor = lib.filterAttrs (n: v: v.kind == "virtual" && v.hypervisorName == config.networking.hostName) machines; in builtins.mapAttrs (name: vm: { # Do not restart virtual machines to apply configuration changes. # While conceptually this seems useful, it could result in annoying situations. # For example, changing the default VM configuration will restart ALL VMs simultaneously, causing a lot of stress on the servers. # Downside of not restarting, is that we may need to do this manually now to apply changes. restartIfChanged = false; specialArgs = { inherit agenix disko pkgs lib microvm dns; machine = vm; hypervisorConfig = config; }; config.imports = [ ./. { networking.hostName = name; } ]; } ) vmsForHypervisor; }; }