This commit is contained in:
Peritia 2025-09-10 12:17:16 +02:00
parent fc0abdd4bb
commit aca73cdd0f
73 changed files with 3873 additions and 381 deletions

View file

@ -1,3 +1,21 @@
# VM (System Module)
#
# Provides:
# - QEMU/KVM virtualization via libvirt
# - virt-manager GUI
# - User access via libvirtd and kvm groups
# - Spice, dnsmasq, and bridge-utils for networking and display
#
# Options:
# - enable → Enable VM system module
# - username → User to add to virtualization groups (required)
#
# Notes:
# - QEMU runs as root by default (can be adjusted)
# - virt-manager GUI is enabled automatically
# - Only generic "kvm" kernel module is forced (host picks intel/amd)
#
{ config, lib, pkgs, ... }:
let
@ -5,16 +23,45 @@ let
in
{
options.nyx-module.system.vm = {
enable = lib.mkEnableOption "Enable vm (system) module";
enable = lib.mkEnableOption "Enable VM (system module)";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.vm;
description = "Package to install for vm.";
username = lib.mkOption {
type = lib.types.str;
example = "alice";
description = "User to add to virtualization groups.";
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
environment.systemPackages = with pkgs; [
virt-manager
spice-gtk
dnsmasq
bridge-utils
];
virtualisation.libvirtd = {
enable = true;
qemu = {
package = pkgs.qemu_full;
runAsRoot = true;
};
};
# Add user to groups
users.users.${cfg.username}.extraGroups = [ "libvirtd" "kvm" ];
# Enable kernel modules for virtualization
boot.kernelModules = [ "kvm" ];
# Enable GUI management tool
programs.virt-manager.enable = true;
assertions = [
{
assertion = cfg.username != "";
message = "nyx-module.system.vm.username must be set to a valid user.";
}
];
};
}