diff --git a/modules/components/default.nix b/modules/components/default.nix index ee9ab9d..1e2acba 100644 --- a/modules/components/default.nix +++ b/modules/components/default.nix @@ -10,6 +10,6 @@ # ./pipewire ./theming # ./users - # ./virtualization + ./virtualization ]; } diff --git a/modules/components/virtualization/default.nix b/modules/components/virtualization/default.nix new file mode 100644 index 0000000..32e911a --- /dev/null +++ b/modules/components/virtualization/default.nix @@ -0,0 +1,89 @@ +{ + lib, + config, + pkgs, + username, + vars, + ... +}: +let + cfg = config.virtualization; +in +{ + options = { + virtualization = { + enable = lib.mkEnableOption "Enable virtualization in NixOS & home-manager"; + }; + }; + config = lib.mkIf cfg.enable { + environment = { + systemPackages = with pkgs; [ + docker-compose + podlet + quickemu + spice + spice-protocol + virt-manager + virtiofsd + virtio-win + win-spice + ]; + }; + services = { + spice-vdagentd.enable = true; + }; + virtualisation = { + docker = { + enable = true; + enableOnBoot = true; + autoPrune = { + enable = true; + dates = "weekly"; + }; + defaultNetwork.settings.dns_enabled = true; + + enableNvidia = if vars.nvidia then true else false; + }; + libvirtd = { + # Make sure you run this once: "sudo virsh net-autostart default" + enable = true; + qemu = { + swtpm.enable = true; + ovmf.enable = true; + ovmf.packages = [ pkgs.OVMFFull.fd ]; + }; + }; + spiceUSBRedirection.enable = true; + vmVariant = { + virtualisation = { + memorySize = 4096; + cores = 3; + }; + }; + }; + + users = { + users = { + ${username} = { + extraGroups = [ + "docker" + "libvirtd" + "podman" + ]; + # quadlets + autoSubUidGidRange = true; + linger = true; + }; + }; + }; + + home-manager.users.${username} = { + dconf.settings = { + "org/virt-manager/virt-manager/connections" = { + autoconnect = [ "qemu:///system" ]; + uris = [ "qemu:///system" ]; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/modules/profiles/base.nix b/modules/profiles/base.nix index 4e20c67..7b40c25 100644 --- a/modules/profiles/base.nix +++ b/modules/profiles/base.nix @@ -68,7 +68,7 @@ in secrets.enable = true; syncthing.enable = true; # users.enable = true; - # virtualization.enable = true; + virtualization.enable = false; console = { earlySetup = true; diff --git a/modules/profiles/server.nix b/modules/profiles/server.nix index 060d31f..34d5715 100644 --- a/modules/profiles/server.nix +++ b/modules/profiles/server.nix @@ -18,6 +18,7 @@ in config = lib.mkIf cfg.enable { # Custom modules base.enable = true; + virtualization.enable = true; catppuccinTheming.enable = lib.mkForce false; packages.enable = lib.mkForce false;