Split the 1,409-line modules/config.nix into 9 focused modules: - lib/helpers.nix: Pure utility functions (CIDR, MAC generation, PCI helpers) - assertions.nix: All validation assertions - pci.nix: PCI isolation (vfio-pci, udev rules, activation script) - networking.nix: TAP interfaces, NAT, vm-switch activation - services.nix: Systemd units (sockets, services, tmpfiles, polkit) - scripts.nix: VM launcher and user scripts (vm-run, vm-start, etc.) - desktop.nix: Desktop integration (.desktop files, bash completion) - overlay.nix: KWin window decoration patches - package.nix: Package assembly and environment config Each module imports lib/helpers.nix for shared functions and computes its own derived values from cfg, keeping modules independent. Added internal options (_internal.vmScripts, proxyScripts, userScripts, desktopFilesPackage, bashCompletionScript) for inter-module communication. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
62 lines
1.6 KiB
Nix
62 lines
1.6 KiB
Nix
# Package assembly for vmsilo NixOS module
|
|
# Bundles all scripts and configures environment
|
|
{
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}:
|
|
|
|
let
|
|
cfg = config.programs.vmsilo;
|
|
|
|
# Generate the package with all scripts
|
|
vmPackage = pkgs.runCommand "vmsilo-scripts" { } ''
|
|
mkdir -p $out/bin
|
|
mkdir -p $out/share/bash-completion/completions
|
|
|
|
# VM launcher scripts
|
|
${lib.concatMapStringsSep "\n" (vm: ''
|
|
ln -s ${cfg._internal.vmScripts.${vm.name}} $out/bin/vmsilo-start-${vm.name}
|
|
'') cfg.nixosVms}
|
|
|
|
# User-facing scripts
|
|
${lib.concatMapStringsSep "\n" (name: ''
|
|
ln -s ${cfg._internal.userScripts.${name}} $out/bin/${name}
|
|
'') (lib.attrNames cfg._internal.userScripts)}
|
|
|
|
# Link crosvm for convenience
|
|
ln -s ${cfg._internal.crosvm}/bin/crosvm $out/bin/crosvm
|
|
|
|
# Bash completions
|
|
${lib.optionalString cfg.enableBashIntegration ''
|
|
for cmd in vm-run vm-start vm-start-debug vm-stop vm-shell; do
|
|
ln -s ${cfg._internal.bashCompletionScript} $out/share/bash-completion/completions/$cmd
|
|
done
|
|
''}
|
|
'';
|
|
in
|
|
{
|
|
config = lib.mkIf cfg.enable {
|
|
# Set the package output
|
|
programs.vmsilo.package = vmPackage;
|
|
|
|
# Add scripts and desktop files to system PATH
|
|
environment.systemPackages = [
|
|
vmPackage
|
|
cfg._internal.desktopFilesPackage
|
|
];
|
|
|
|
# Ensure required paths are linked
|
|
environment.pathsToLink = [
|
|
"/share/applications"
|
|
"/share/desktop-directories"
|
|
"/share/icons"
|
|
"/share/pixmaps"
|
|
"/etc/xdg/menus"
|
|
]
|
|
++ lib.optionals cfg.enableBashIntegration [
|
|
"/share/bash-completion"
|
|
];
|
|
};
|
|
}
|