From 7a8597cdefe157eaf105110e11711a90b3598d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20K=C3=A4nner?= Date: Sat, 28 Dec 2024 23:32:52 +0100 Subject: [PATCH] create qemu module --- hosts/MaxNixosLaptop/configuration.nix | 21 ---------------- modules/nixos/default.nix | 5 +++- modules/nixos/qemu.nix | 35 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 modules/nixos/qemu.nix diff --git a/hosts/MaxNixosLaptop/configuration.nix b/hosts/MaxNixosLaptop/configuration.nix index 7a67eb6..5cf30c5 100644 --- a/hosts/MaxNixosLaptop/configuration.nix +++ b/hosts/MaxNixosLaptop/configuration.nix @@ -86,27 +86,6 @@ security.polkit.enable = true; environment.sessionVariables.NIXOS_OZONE_WL = "1"; - virtualisation = { - libvirtd = { - enable = true; - qemu = { - package = pkgs.qemu_kvm; - runAsRoot = true; - swtpm.enable = true; - ovmf = { - enable = true; - packages = [ - (pkgs.OVMF.override { - secureBoot = true; - tpmSupport = true; - }) - .fd - ]; - }; - }; - }; - }; - # List services that you want to enable: # fingerprint unlock diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index fe36a3d..0902f2c 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -1,11 +1,12 @@ { lib, config, + system, ... }: let cfg = config.myConfig; in { - imports = [./bootloader.nix ./locale.nix ./greetd.nix ./rebuild.nix ./sops.nix ./sway.nix ./wifi.nix ./music.nix ./cups.nix ./gpu/amd.nix ./touch.nix ./cache.nix ./nix.nix ./update.nix ./podman.nix]; + imports = [./bootloader.nix ./locale.nix ./greetd.nix ./rebuild.nix ./sops.nix ./sway.nix ./wifi.nix ./music.nix ./cups.nix ./gpu/amd.nix ./touch.nix ./cache.nix ./nix.nix ./update.nix ./podman.nix ./qemu.nix]; options.myConfig = { enable = lib.mkEnableOption "my custom config"; @@ -27,6 +28,8 @@ in { cache.enable = true; autoUpdate.enable = true; podman.enable = true; + qemu.enable = true; + qemu.kvm = lib.mkIf (system == "x86_64-linux") true; greetd.enable = lib.mkIf cfg.desktop true; sway.enable = lib.mkIf cfg.desktop true; diff --git a/modules/nixos/qemu.nix b/modules/nixos/qemu.nix new file mode 100644 index 0000000..2542084 --- /dev/null +++ b/modules/nixos/qemu.nix @@ -0,0 +1,35 @@ +{ + lib, + config, + pkgs, + ... +}: let + cfg = config.myConfig.qemu; +in { + options.myConfig.qemu = { + enable = lib.mkEnableOption "qemu"; + kvm = lib.mkEnableOption "kvm for faster emulation of x86"; + }; + + config = lib.mkIf cfg.enable { + virtualisation. + libvirtd = { + enable = true; + qemu = { + package = lib.mkIf cfg.kvm pkgs.qemu_kvm; + runAsRoot = true; + swtpm.enable = true; + ovmf = { + enable = true; + packages = [ + (pkgs.OVMF.override { + secureBoot = true; + tpmSupport = true; + }) + .fd + ]; + }; + }; + }; + }; +}