@@ -342,52 +342,6 @@ rec {
342342 } ;
343343 in
344344 ( feature . enable or false ) && builtins . elem vmName ( feature . targetVms or [ ] ) ;
345-
346- # Get all features enabled for a specific VM
347- #
348- # Usage:
349- # lib.ghaf.features.forVm globalConfig "gui-vm"
350- # # Returns: { fprint = true; yubikey = true; brightness = true; wifi = false; ... }
351- #
352- # Parameters:
353- # globalConfig: The ghaf.global-config attribute set
354- # vmName: Name of the VM to check
355- #
356- # Returns: attrset of featureName -> bool
357- forVm =
358- globalConfig : vmName :
359- let
360- featuresAttr = globalConfig . features or { } ;
361- in
362- lib . mapAttrs (
363- _name : feature : ( feature . enable or false ) && builtins . elem vmName ( feature . targetVms or [ ] )
364- ) featuresAttr ;
365-
366- # List all available feature names
367- #
368- # Usage:
369- # lib.ghaf.features.available globalConfig
370- # # Returns: [ "fprint" "yubikey" "brightness" "wifi" "audio" "bluetooth" ]
371- #
372- available = globalConfig : builtins . attrNames ( globalConfig . features or { } ) ;
373-
374- # Get VMs that have a specific feature enabled
375- #
376- # Usage:
377- # lib.ghaf.features.vmsWithFeature globalConfig "fprint"
378- # # Returns: [ "gui-vm" ] (or whatever targetVms is set to)
379- #
380- vmsWithFeature =
381- globalConfig : featureName :
382- let
383- featuresAttr = globalConfig . features or { } ;
384- feature =
385- featuresAttr . ${ featureName } or {
386- enable = false ;
387- targetVms = [ ] ;
388- } ;
389- in
390- if feature . enable or false then feature . targetVms or [ ] else [ ] ;
391345 } ;
392346
393347 # Predefined global config profiles
@@ -575,8 +529,8 @@ rec {
575529 # Functions:
576530 # lib.ghaf.vm.mkSpecialArgs - Create specialArgs for VM modules
577531 # lib.ghaf.vm.mkHostConfig - Extract host config for VM specialArgs
578- # lib.ghaf.vm.extend - Extend a VM base with modules
579532 # lib.ghaf.vm.getConfig - Get inner NixOS config from microvm.vms entry
533+ # lib.ghaf.vm.applyVmConfig - Build modules list with vmConfig applied
580534 #
581535 # Usage Example:
582536 # guivmBase = lib.nixosSystem {
@@ -661,7 +615,7 @@ rec {
661615 enable = config . ghaf . microvm-boot . enable or false ;
662616 } ;
663617
664- # Hardware devices (for modules.nix)
618+ # Hardware devices
665619 hardware = {
666620 devices = config . ghaf . hardware . devices or { } ;
667621 } ;
@@ -699,37 +653,6 @@ rec {
699653 }
700654 // extraConfig ;
701655
702- # Extend a VM base with additional modules
703- #
704- # This function takes a base VM configuration (lib.nixosSystem result)
705- # and extends it with additional modules for profile-specific functionality.
706- #
707- # Arguments:
708- # vmBase - lib.nixosSystem result with .extendModules
709- # extraModules - Additional modules to add
710- # globalConfig - Global config value
711- # hostConfig - Host-specific config
712- # extraSpecialArgs - Optional additional specialArgs
713- #
714- # Returns: Extended NixOS system configuration
715- #
716- # See modules/profiles/laptop-x86.nix for canonical pattern.
717- extend =
718- {
719- vmBase ,
720- extraModules ? [ ] ,
721- globalConfig ? { } ,
722- hostConfig ? { } ,
723- extraSpecialArgs ? { } ,
724- } :
725- vmBase . extendModules {
726- modules = extraModules ;
727- specialArgs = {
728- inherit globalConfig hostConfig ;
729- }
730- // extraSpecialArgs ;
731- } ;
732-
733656 # Get the inner NixOS config from a microvm.vms entry
734657 #
735658 # microvm.nix supports two ways to define VMs:
@@ -796,34 +719,5 @@ rec {
796719 // lib . optionalAttrs ( vmCfg . vcpu or null != null ) { microvm . vcpu = vmCfg . vcpu ; } ;
797720 in
798721 [ resourceModule ] ++ hwModules ++ vmConfigModules ;
799-
800- # Build modules list with vmConfig applied for App VMs
801- #
802- # Similar to applyVmConfig but uses appvms namespace and
803- # ramMb/cores naming convention for consistency with appvm definitions.
804- #
805- # Arguments:
806- # config - Host configuration
807- # appName - App VM name (e.g., "chromium", "comms")
808- #
809- # Returns: List of modules to add via extendModules
810- applyAppVmConfig =
811- {
812- config ,
813- appName ,
814- } :
815- let
816- vmCfg = config . ghaf . virtualization . vmConfig . appvms . ${ appName } or { } ;
817- vmConfigModules = vmCfg . extraModules or [ ] ;
818-
819- # Resource allocation module (applies ramMb/cores as mem/vcpu)
820- resourceModule =
821- lib . optionalAttrs ( vmCfg . ramMb or null != null ) {
822- # App VMs use balloon, so scale by balloon ratio
823- microvm . mem = vmCfg . ramMb * 3 ; # Default balloon ratio is 2
824- }
825- // lib . optionalAttrs ( vmCfg . cores or null != null ) { microvm . vcpu = vmCfg . cores ; } ;
826- in
827- [ resourceModule ] ++ vmConfigModules ;
828722 } ;
829723}
0 commit comments