diff --git a/nix/nixos-module/default.nix b/nix/nixos-module/default.nix index 61aace0..dfd1910 100644 --- a/nix/nixos-module/default.nix +++ b/nix/nixos-module/default.nix @@ -18,6 +18,7 @@ in { optionals (hostConfig.role == "server") [ ./server/lxc-containers.nix ./server/network.nix + ./server/qemu.nix ] ++ optionals (hostName == "server2") [ ./server/server2.nix diff --git a/nix/nixos-module/defaults.nix b/nix/nixos-module/defaults.nix index 85b619b..969e183 100644 --- a/nix/nixos-module/defaults.nix +++ b/nix/nixos-module/defaults.nix @@ -33,20 +33,5 @@ users.users.root.initialHashedPassword = ""; - # for vm-packages - virtualisation = lib.optionalAttrs (builtins.hasAttr "qemu" options.virtualisation) { - # larger than the defaults - memorySize = 8192; - cores = 2; - diskSize = 8192; - # 9P performance optimization that quelches a qemu warning - msize = 65536; - # allow building packages - writableStore = true; - # keep the store paths built inside the VM across reboots - writableStoreUseTmpfs = false; - qemu.options = [ "-enable-kvm" ]; - }; - system.stateVersion = "20.09"; } diff --git a/nix/nixos-module/server/network.nix b/nix/nixos-module/server/network.nix index 271cf8a..f91feef 100644 --- a/nix/nixos-module/server/network.nix +++ b/nix/nixos-module/server/network.nix @@ -70,10 +70,6 @@ in ); networks = { - eth = { - matchConfig.Name = "eth*"; - networkConfig.Bond = "bond0"; - }; en = { # physical ethernet ports matchConfig.Name = "en*"; diff --git a/nix/nixos-module/server/qemu.nix b/nix/nixos-module/server/qemu.nix new file mode 100644 index 000000000..5b650f0 --- /dev/null +++ b/nix/nixos-module/server/qemu.nix @@ -0,0 +1,33 @@ +# Options for running under qemu (vm-packages) +{ inputs, lib, options, ... }: +{ + # Get internet from qemu user networking + systemd.network = lib.optionalAttrs (options.virtualisation ? qemu) { + networks."00-qemu" = { + matchConfig.Name = "en*"; + networkConfig.DHCP = "yes"; + }; + netdevs.bond0.bondConfig.MinLinks = 0; + }; + + # for vm-packages + virtualisation = lib.optionalAttrs (options.virtualisation ? qemu) { + # larger than the defaults + memorySize = 8192; + cores = 2; + diskSize = 8192; + # 9P performance optimization that quelches a qemu warning + msize = 65536; + # allow building packages + writableStore = true; + # keep the store paths built inside the VM across reboots + writableStoreUseTmpfs = false; + qemu.options = [ "-enable-kvm" ]; + }; + + # Let the nix registry point to the state of your local checkout + # when running the virtual machine. + nix.registry = lib.optionalAttrs (options.virtualisation ? qemu) { + zentralwerk-network.flake = inputs.self; + }; +}