Skip to content

Commit 52e533f

Browse files
cleanup some tmp backward compat code
Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
1 parent 988eed7 commit 52e533f

File tree

4 files changed

+298
-182
lines changed

4 files changed

+298
-182
lines changed

modules/common/global-config.nix

Lines changed: 13 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,39 @@
33
#
44
# Global Configuration Options Module
55
#
6-
# This module defines the ghaf.global-config options that propagate to all VMs.
7-
# Settings here are the "single source of truth" for configuration values
8-
# that should be consistent across host and all guest VMs.
9-
#
10-
# Supports versioned profiles via lib.ghaf.profiles and lib.ghaf.mkGlobalConfig.
6+
# This module defines the ghaf.global-config option type for host-level settings.
7+
# The actual global config values are created by lib.ghaf.mkGlobalConfig and
8+
# passed to VMs via specialArgs (globalConfig).
119
#
1210
# Usage:
13-
# # Use a predefined profile
14-
# ghaf.global-config = lib.ghaf.profiles.debug;
15-
#
16-
# # Or customize a profile
17-
# ghaf.global-config = lib.ghaf.mkGlobalConfig "debug" {
18-
# storage.encryption.enable = true;
19-
# };
11+
# # Set options on host (these propagate via lib.ghaf.mkGlobalConfig)
12+
# ghaf.profiles.debug.enable = true;
13+
# ghaf.development.ssh.daemon.enable = true;
2014
#
21-
# # Or set options directly
22-
# ghaf.global-config = {
23-
# debug.enable = true;
24-
# development.ssh.daemon.enable = true;
25-
# };
15+
# # VMs receive globalConfig via specialArgs, created by profiles
16+
# # See: modules/profiles/laptop-x86.nix, lib/global-config.nix
2617
#
27-
# Backward Compatibility:
28-
# This module provides sync from existing ghaf.* options → global-config.
29-
# Old-style settings will automatically populate global-config so that
30-
# VMs using the new pattern receive correct values.
3118
{
3219
config,
3320
lib,
34-
options,
3521
...
3622
}:
37-
let
38-
39-
# Helper to check if an option path exists in the options tree
40-
optionExists = path: lib.hasAttrByPath path options;
41-
42-
# Helper to get config value if option exists, otherwise use default
43-
configOrDefault =
44-
path: default: if optionExists path then lib.getAttrFromPath path config else default;
45-
in
4623
{
4724
_file = ./global-config.nix;
4825

4926
options.ghaf.global-config = lib.mkOption {
5027
type = lib.types.globalConfig;
5128
default = { };
5229
description = ''
53-
Global configuration options that automatically propagate to all VMs.
30+
Global configuration options that propagate to all VMs.
5431
5532
These settings represent the "single source of truth" for values that
5633
should be consistent across the host and all guest virtual machines.
5734
58-
You can use predefined profiles:
59-
ghaf.global-config = lib.ghaf.profiles.debug;
60-
61-
Or customize a profile:
62-
ghaf.global-config = lib.ghaf.mkGlobalConfig "debug" {
63-
storage.encryption.enable = true;
64-
};
65-
66-
Or set options directly:
67-
ghaf.global-config = {
68-
debug.enable = true;
69-
development.ssh.daemon.enable = true;
70-
storage.encryption.enable = true;
71-
};
35+
The actual propagation to VMs happens via:
36+
1. lib.ghaf.mkGlobalConfig creates globalConfig from host config
37+
2. Profiles pass globalConfig to VM bases via specialArgs
38+
3. VMs read from globalConfig specialArg
7239
7340
Hardware-specific VM configurations go via hardware definition:
7441
ghaf.hardware.definition.guivm.extraModules = [{
@@ -85,86 +52,5 @@ in
8552
hostSystem = lib.mkDefault config.nixpkgs.hostPlatform.system;
8653
timeZone = lib.mkDefault (if config.time.timeZone != null then config.time.timeZone else "UTC");
8754
};
88-
89-
# Backward compatibility: sync from old-style ghaf.* options → global-config
90-
# Use lib.mkOverride 900 so explicit global-config settings (priority 1000) take precedence
91-
# but these defaults take precedence over the type defaults (priority 1500)
92-
93-
# Debug settings
94-
ghaf.global-config.debug.enable = lib.mkOverride 900 (
95-
configOrDefault [ "ghaf" "profiles" "debug" "enable" ] false
96-
);
97-
98-
# Development settings
99-
ghaf.global-config.development.ssh.daemon.enable = lib.mkOverride 900 (
100-
configOrDefault [ "ghaf" "development" "ssh" "daemon" "enable" ] false
101-
);
102-
103-
ghaf.global-config.development.debug.tools.enable = lib.mkOverride 900 (
104-
configOrDefault [ "ghaf" "development" "debug" "tools" "enable" ] false
105-
);
106-
107-
ghaf.global-config.development.nix-setup.enable = lib.mkOverride 900 (
108-
configOrDefault [ "ghaf" "development" "nix-setup" "enable" ] false
109-
);
110-
111-
# Logging settings
112-
ghaf.global-config.logging.enable = lib.mkOverride 900 (
113-
configOrDefault [ "ghaf" "logging" "enable" ] false
114-
);
115-
116-
ghaf.global-config.logging.listener.address = lib.mkOverride 900 (
117-
configOrDefault [ "ghaf" "logging" "listener" "address" ] ""
118-
);
119-
120-
ghaf.global-config.logging.server.endpoint = lib.mkOverride 900 (
121-
configOrDefault [ "ghaf" "logging" "server" "endpoint" ] ""
122-
);
123-
124-
# Security settings
125-
ghaf.global-config.security.audit.enable = lib.mkOverride 900 (
126-
configOrDefault [ "ghaf" "security" "audit" "enable" ] false
127-
);
128-
129-
# GIVC settings
130-
ghaf.global-config.givc.enable = lib.mkOverride 900 (
131-
configOrDefault [ "ghaf" "givc" "enable" ] false
132-
);
133-
134-
ghaf.global-config.givc.debug = lib.mkOverride 900 (
135-
configOrDefault [ "ghaf" "givc" "debug" ] false
136-
);
137-
138-
# Services settings
139-
ghaf.global-config.services.power-manager.enable = lib.mkOverride 900 (
140-
configOrDefault [ "ghaf" "services" "power-manager" "enable" ] false
141-
);
142-
143-
ghaf.global-config.services.performance.enable = lib.mkOverride 900 (
144-
configOrDefault [ "ghaf" "services" "performance" "enable" ] false
145-
);
146-
147-
# Storage settings
148-
ghaf.global-config.storage.encryption.enable = lib.mkOverride 900 (
149-
configOrDefault [ "ghaf" "virtualization" "storagevm-encryption" "enable" ] false
150-
);
151-
152-
ghaf.global-config.storage.storeOnDisk = lib.mkOverride 900 (
153-
configOrDefault [ "ghaf" "virtualization" "microvm" "storeOnDisk" ] false
154-
);
155-
156-
# Shared memory settings
157-
ghaf.global-config.shm.enable = lib.mkOverride 900 (
158-
configOrDefault [ "ghaf" "shm" "enable" ] false
159-
);
160-
161-
ghaf.global-config.shm.serverSocketPath = lib.mkOverride 900 (
162-
configOrDefault [ "ghaf" "shm" "serverSocketPath" ] ""
163-
);
164-
165-
# IDS VM settings
166-
ghaf.global-config.idsvm.mitmproxy.enable = lib.mkOverride 900 (
167-
configOrDefault [ "ghaf" "virtualization" "microvm" "idsvm" "mitmproxy" "enable" ] false
168-
);
16955
};
17056
}

modules/profiles/flake-module.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,12 @@
3535
inputs.self.nixosModules.microvm
3636
./orin.nix
3737
];
38+
39+
# Profile for VM targets that run GUI on host (no gui-vm)
40+
profiles-vm.imports = [
41+
inputs.self.nixosModules.profiles
42+
inputs.self.nixosModules.microvm
43+
./vm.nix
44+
];
3845
};
3946
}

modules/profiles/vm.nix

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# SPDX-FileCopyrightText: 2022-2026 TII (SSRC) and the Ghaf contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Profile for VM targets that run GUI on the host (no gui-vm microvm).
5+
# This profile creates VM bases for: netvm, audiovm, adminvm
6+
# but NOT guivm (since GUI runs on host).
7+
#
8+
{
9+
config,
10+
lib,
11+
inputs,
12+
...
13+
}:
14+
let
15+
cfg = config.ghaf.profiles.vm;
16+
hostGlobalConfig = config.ghaf.global-config;
17+
in
18+
{
19+
_file = ./vm.nix;
20+
21+
options.ghaf.profiles.vm = {
22+
enable = lib.mkEnableOption "VM target profile (GUI runs on host, no gui-vm)";
23+
24+
# Net VM base configuration
25+
netvmBase = lib.mkOption {
26+
type = lib.types.unspecified;
27+
readOnly = true;
28+
description = ''
29+
VM profile Net VM base configuration.
30+
Use extendModules to add hardware passthrough and GIVC overrides.
31+
'';
32+
};
33+
34+
# Audio VM base configuration
35+
audiovmBase = lib.mkOption {
36+
type = lib.types.unspecified;
37+
readOnly = true;
38+
description = ''
39+
VM profile Audio VM base configuration.
40+
Use extendModules to add GIVC socket proxy configuration.
41+
'';
42+
};
43+
44+
# Admin VM base configuration
45+
adminvmBase = lib.mkOption {
46+
type = lib.types.unspecified;
47+
readOnly = true;
48+
description = ''
49+
VM profile Admin VM base configuration.
50+
'';
51+
};
52+
53+
# App VM factory function
54+
mkAppVm = lib.mkOption {
55+
type = lib.types.unspecified;
56+
readOnly = true;
57+
description = ''
58+
Function to create App VM configurations.
59+
Takes a vmDef attribute set and returns a NixOS configuration.
60+
The result can be extended with:
61+
(mkAppVm vmDef).extendModules { modules = [ ... ]; }
62+
'';
63+
};
64+
};
65+
66+
config = lib.mkIf cfg.enable {
67+
68+
# Export Net VM base
69+
ghaf.profiles.vm.netvmBase = lib.nixosSystem {
70+
inherit (inputs.nixpkgs.legacyPackages.x86_64-linux) system;
71+
modules = [
72+
inputs.microvm.nixosModules.microvm
73+
inputs.self.nixosModules.netvm-base
74+
{
75+
nixpkgs.overlays = config.nixpkgs.overlays;
76+
nixpkgs.config = config.nixpkgs.config;
77+
}
78+
];
79+
specialArgs = lib.ghaf.vm.mkSpecialArgs {
80+
inherit lib inputs;
81+
globalConfig = hostGlobalConfig;
82+
hostConfig =
83+
lib.ghaf.vm.mkHostConfig {
84+
inherit config;
85+
vmName = "net-vm";
86+
}
87+
// {
88+
netvm = {
89+
wifi = config.ghaf.virtualization.microvm.netvm.wifi or false;
90+
};
91+
};
92+
};
93+
};
94+
95+
# Export Audio VM base
96+
ghaf.profiles.vm.audiovmBase = lib.nixosSystem {
97+
inherit (inputs.nixpkgs.legacyPackages.x86_64-linux) system;
98+
modules = [
99+
inputs.microvm.nixosModules.microvm
100+
inputs.self.nixosModules.audiovm-base
101+
{
102+
nixpkgs.overlays = config.nixpkgs.overlays;
103+
nixpkgs.config = config.nixpkgs.config;
104+
}
105+
];
106+
specialArgs = lib.ghaf.vm.mkSpecialArgs {
107+
inherit lib inputs;
108+
globalConfig = hostGlobalConfig;
109+
hostConfig =
110+
lib.ghaf.vm.mkHostConfig {
111+
inherit config;
112+
vmName = "audio-vm";
113+
}
114+
// {
115+
audiovm = {
116+
audio = config.ghaf.virtualization.microvm.audiovm.audio or false;
117+
};
118+
};
119+
};
120+
};
121+
122+
# Export Admin VM base
123+
ghaf.profiles.vm.adminvmBase = lib.nixosSystem {
124+
inherit (inputs.nixpkgs.legacyPackages.x86_64-linux) system;
125+
modules = [
126+
inputs.microvm.nixosModules.microvm
127+
inputs.self.nixosModules.adminvm-base
128+
inputs.self.nixosModules.adminvm-features
129+
{
130+
nixpkgs.overlays = config.nixpkgs.overlays;
131+
nixpkgs.config = config.nixpkgs.config;
132+
}
133+
];
134+
specialArgs = lib.ghaf.vm.mkSpecialArgs {
135+
inherit lib inputs;
136+
globalConfig = hostGlobalConfig;
137+
hostConfig = lib.ghaf.vm.mkHostConfig {
138+
inherit config;
139+
vmName = "admin-vm";
140+
};
141+
};
142+
};
143+
144+
# Export mkAppVm function for creating App VMs
145+
ghaf.profiles.vm.mkAppVm =
146+
vmDef:
147+
lib.nixosSystem {
148+
inherit (inputs.nixpkgs.legacyPackages.x86_64-linux) system;
149+
modules = [
150+
inputs.microvm.nixosModules.microvm
151+
inputs.self.nixosModules.appvm-base
152+
{
153+
nixpkgs.overlays = config.nixpkgs.overlays;
154+
nixpkgs.config = config.nixpkgs.config;
155+
}
156+
];
157+
specialArgs = lib.ghaf.vm.mkSpecialArgs {
158+
inherit lib inputs;
159+
globalConfig = hostGlobalConfig;
160+
hostConfig =
161+
lib.ghaf.vm.mkHostConfig {
162+
inherit config;
163+
vmName = "${vmDef.name}-vm";
164+
}
165+
// {
166+
appvm = vmDef;
167+
sharedVmDirectory =
168+
config.ghaf.virtualization.microvm-host.sharedVmDirectory or {
169+
enable = false;
170+
vms = [ ];
171+
};
172+
};
173+
};
174+
};
175+
};
176+
}

0 commit comments

Comments
 (0)