From fb4b56a6fd34e6926ddb1875e6f7e1b2f4f55801 Mon Sep 17 00:00:00 2001 From: GHOSCHT <31184695+GHOSCHT@users.noreply.github.com> Date: Sat, 14 Oct 2023 13:24:01 +0200 Subject: [PATCH] Add virtualization capabilities --- hosts/desktop/default.nix | 2 ++ modules/virtualization/docker.nix | 18 +++++++++++++ modules/virtualization/qemu.nix | 42 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 modules/virtualization/docker.nix create mode 100644 modules/virtualization/qemu.nix diff --git a/hosts/desktop/default.nix b/hosts/desktop/default.nix index d3d2330..32d2d59 100644 --- a/hosts/desktop/default.nix +++ b/hosts/desktop/default.nix @@ -11,6 +11,8 @@ ./hardware-configuration.nix ../../modules/hardware/nvidia.nix ../../modules/services/avahi.nix + ../../modules/virtualization/docker.nix + ../../modules/virtualization/qemu.nix ]; boot = { diff --git a/modules/virtualization/docker.nix b/modules/virtualization/docker.nix new file mode 100644 index 0000000..3e010c4 --- /dev/null +++ b/modules/virtualization/docker.nix @@ -0,0 +1,18 @@ +{ + config, + pkgs, + vars, + ... +}: { + virtualisation = { + docker.enable = true; + }; + + users.groups.docker.members = ["${vars.user}"]; + + environment.systemPackages = with pkgs; [ + docker # Containers + docker-compose # Multi-Container + lazydocker + ]; +} diff --git a/modules/virtualization/qemu.nix b/modules/virtualization/qemu.nix new file mode 100644 index 0000000..9ec2e53 --- /dev/null +++ b/modules/virtualization/qemu.nix @@ -0,0 +1,42 @@ +{ + config, + pkgs, + vars, + ... +}: { + boot.extraModprobeConfig = '' + options kvm_intel nested=1 + ''; + + users.groups.libvirtd.members = ["root" "${vars.user}"]; + + virtualisation = { + libvirtd = { + enable = true; + qemu = { + verbatimConfig = '' + nvram = [ "${pkgs.OVMF}/FV/OVMF.fd:${pkgs.OVMF}/FV/OVMF_VARS.fd" ] + ''; + swtpm.enable = true; + }; + }; + spiceUSBRedirection.enable = true; + }; + + environment = { + systemPackages = with pkgs; [ + virt-manager # VM Interface + virt-viewer # Remote VM + qemu # Virtualizer + OVMF # UEFI Firmware + gvfs # Shared Directory + swtpm # TPM + virglrenderer # Virtual OpenGL + ]; + }; + + services = { + # File Sharing + gvfs.enable = true; + }; +}