Skip to content

Commit 1340965

Browse files
committed
refactor(hardware): remove hw deps
- remove hardware definition dependencies - move shm and mem manager - initial reference flake module file Signed-off-by: Manuel Bluhm <manuel@ssrc.tii.ae>
1 parent 54b859a commit 1340965

File tree

21 files changed

+91
-112
lines changed

21 files changed

+91
-112
lines changed

modules/common/flake-module.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
./systemd
1717
./services
1818
./networking
19-
#TODO: this should be moved to where it is needed and included on demand
20-
# if it is a common then the file should be moved to common
21-
../hardware/definition.nix
2219
./logging
2320
];
2421
};

modules/flake-module.nix

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44
# Modules to be exported from Flake
55
#
6-
{ ... }:
76
{
87
imports = [
98
./partitioning/flake-module.nix
@@ -15,15 +14,6 @@
1514
./common/flake-module.nix
1615
./development/flake-module.nix
1716
./desktop/flake-module.nix
17+
./reference/flake-module.nix
1818
];
19-
20-
flake.nixosModules = {
21-
#TODO: Add the rest of the modules in their own directories with flake-module.nix
22-
reference-appvms.imports = [ ./reference/appvms ];
23-
reference-host-demo-apps.imports = [ ./reference/host-demo-apps ];
24-
reference-personalize.imports = [ ./reference/personalize ];
25-
reference-profiles.imports = [ ./reference/profiles ];
26-
reference-programs.imports = [ ./reference/programs ];
27-
reference-services.imports = [ ./reference/services ];
28-
};
2919
}

modules/hardware/common/default.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
./input.nix
1010
./kernel.nix
1111
./qemu.nix
12-
./shared-mem.nix
1312
];
1413
}

modules/hardware/common/devices.nix

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
# SPDX-License-Identifier: Apache-2.0
33
{ config, lib, ... }:
44
let
5-
inherit (lib) mkOption types mkForce;
5+
inherit (lib)
6+
mkOption
7+
types
8+
mkForce
9+
concatMapStringsSep
10+
;
611
in
712
{
813
options.ghaf.hardware.devices = {
@@ -45,7 +50,12 @@ in
4550
inherit (d) path;
4651
}) config.ghaf.hardware.definition.network.pciDevices
4752
);
48-
ghaf.hardware.definition.network.pciDevices = config.ghaf.hardware.definition.network.pciDevices;
53+
services.udev.extraRules = ''
54+
${concatMapStringsSep "/n" (
55+
d:
56+
''SUBSYSTEM=="net", ACTION=="add", ATTRS{vendor}=="0x${d.vendorId}", ATTRS{device}=="0x${d.productId}", NAME="${d.name}"''
57+
) config.ghaf.hardware.definition.network.pciDevices}
58+
'';
4959
};
5060

5161
guivmPCIPassthroughModule = {
@@ -55,7 +65,6 @@ in
5565
inherit (d) path qemu;
5666
}) config.ghaf.hardware.definition.gpu.pciDevices
5767
);
58-
ghaf.hardware.definition.gpu.pciDevices = config.ghaf.hardware.definition.gpu.pciDevices;
5968
};
6069

6170
audiovmPCIPassthroughModule = {
@@ -65,7 +74,6 @@ in
6574
inherit (d) path;
6675
}) config.ghaf.hardware.definition.audio.pciDevices
6776
);
68-
ghaf.hardware.definition.audio.pciDevices = config.ghaf.hardware.definition.audio.pciDevices;
6977
};
7078

7179
guivmVirtioInputHostEvdevModule = {

modules/hardware/common/qemu.nix

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ in
2626
};
2727

2828
config = {
29-
ghaf.qemu.guivm = optionalAttrs (hasAttr "hardware" config.ghaf) {
29+
ghaf.qemu.guivm = optionalAttrs (config.ghaf.type == "host") {
3030
microvm.qemu.extraArgs =
3131
optionals (config.ghaf.hardware.definition.type == "laptop") [
3232
# Button
@@ -47,8 +47,13 @@ in
4747
"pcie-root-port,bus=pcie.0,id=${config.ghaf.hardware.usb.vhotplug.pcieBusPrefix}${toString n},chassis=${toString n}"
4848
]) (lib.range 1 config.ghaf.hardware.usb.vhotplug.pciePortCount);
4949
};
50-
ghaf.qemu.audiovm = optionalAttrs (hasAttr "hardware" config.ghaf) {
51-
microvm.qemu.extraArgs = optionals (hasAttr "bt0" config.ghaf.hardware.usb.internal.qemuExtraArgs) config.ghaf.hardware.usb.internal.qemuExtraArgs.bt0;
50+
ghaf.qemu.audiovm = optionalAttrs (config.ghaf.type == "host") {
51+
microvm.qemu.extraArgs =
52+
optionals (hasAttr "bt0" config.ghaf.hardware.usb.internal.qemuExtraArgs) config.ghaf.hardware.usb.internal.qemuExtraArgs.bt0
53+
++ optionals (config.ghaf.hardware.definition.audio.acpiPath != null) [
54+
"-acpitable"
55+
"file=${config.ghaf.hardware.definition.audio.acpiPath}"
56+
];
5257
};
5358
};
5459
}

modules/hardware/flake-module.nix

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
# Copyright 2024 TII (SSRC) and the Ghaf contributors
22
# SPDX-License-Identifier: Apache-2.0
33
{
4-
54
flake.nixosModules = {
6-
hardware-x86_64-laptop.imports = [
7-
./definition.nix
8-
./x86_64-generic
9-
./common
10-
];
11-
hardware-x86_64-desktop.imports = [
5+
hardware-x86_64-workstation.imports = [
126
./definition.nix
137
./x86_64-generic
148
./common

modules/microvm/flake-module.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{
55
flake.nixosModules = {
66
microvm.imports = [
7-
inputs.microvm.nixosModules.host
87
(import ./host/microvm-host.nix { inherit inputs; })
98
(import ./sysvms/netvm.nix { inherit inputs; })
109
(import ./sysvms/adminvm.nix { inherit inputs; })
@@ -14,12 +13,12 @@
1413
(import ./sysvms/idsvm/idsvm.nix { inherit inputs; })
1514
./sysvms/idsvm/mitmproxy
1615
./modules.nix
17-
../hardware/common/shared-mem.nix
1816
];
1917

2018
mem-manager.imports = [
21-
./mem-manager.nix
19+
./host/mem-manager.nix
2220
];
21+
2322
vm-modules.imports = [
2423
./common/ghaf-audio.nix
2524
./common/shared-directory.nix

modules/microvm/host/microvm-host.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ let
2222
in
2323
{
2424
imports = [
25+
inputs.microvm.nixosModules.host
2526
inputs.impermanence.nixosModules.impermanence
2627
inputs.self.nixosModules.givc
28+
inputs.self.nixosModules.mem-manager
2729
./networking.nix
30+
./shared-mem.nix
2831
];
2932

3033
options.ghaf.virtualization.microvm-host = {

0 commit comments

Comments
 (0)