From a118b52a02da391f65fd794b979545e9646f5981 Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Tue, 28 Sep 2021 22:24:03 -0400 Subject: [PATCH] move hardware stuff from getHosts to module --- hosts/cube/configuration.nix | 1 + hosts/cube/default.nix | 1 - hosts/hp/configuration.nix | 1 + hosts/hp/default.nix | 1 - hosts/nixdev/configuration.nix | 1 + hosts/nixdev/default.nix | 1 - hosts/slate/configuration.nix | 1 + hosts/slate/default.nix | 1 - lib/hosts.nix | 16 --------------- modules/hardware.nix | 36 ++++++++++++++++++++++++++++++++++ 10 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 modules/hardware.nix diff --git a/hosts/cube/configuration.nix b/hosts/cube/configuration.nix index 1c3cf4b..d8f5229 100644 --- a/hosts/cube/configuration.nix +++ b/hosts/cube/configuration.nix @@ -3,6 +3,7 @@ sconfig = { gnome = true; profile = "desktop"; + hardware = "physical"; security-tools = true; i3.extraConfig = '' exec xrandr --output DisplayPort-0 --mode 2560x1440 --rate 165 diff --git a/hosts/cube/default.nix b/hosts/cube/default.nix index 14c0a47..70175cd 100644 --- a/hosts/cube/default.nix +++ b/hosts/cube/default.nix @@ -1,6 +1,5 @@ { pkgs = "nixpkgs"; system = "x86_64-linux"; - hardware = "physical"; module = ./configuration.nix; } diff --git a/hosts/hp/configuration.nix b/hosts/hp/configuration.nix index 521b56e..c358280 100644 --- a/hosts/hp/configuration.nix +++ b/hosts/hp/configuration.nix @@ -7,6 +7,7 @@ sconfig = { gnome = true; profile = "desktop"; + hardware = "physical"; security-tools = true; }; diff --git a/hosts/hp/default.nix b/hosts/hp/default.nix index 14c0a47..70175cd 100644 --- a/hosts/hp/default.nix +++ b/hosts/hp/default.nix @@ -1,6 +1,5 @@ { pkgs = "nixpkgs"; system = "x86_64-linux"; - hardware = "physical"; module = ./configuration.nix; } diff --git a/hosts/nixdev/configuration.nix b/hosts/nixdev/configuration.nix index ef53a07..bc78394 100644 --- a/hosts/nixdev/configuration.nix +++ b/hosts/nixdev/configuration.nix @@ -2,6 +2,7 @@ { sconfig = { profile = "server"; + hardware = "qemu"; }; environment.persistence."/nix/persist" = { diff --git a/hosts/nixdev/default.nix b/hosts/nixdev/default.nix index 165044d..70175cd 100644 --- a/hosts/nixdev/default.nix +++ b/hosts/nixdev/default.nix @@ -1,6 +1,5 @@ { pkgs = "nixpkgs"; system = "x86_64-linux"; - hardware = "qemu"; module = ./configuration.nix; } diff --git a/hosts/slate/configuration.nix b/hosts/slate/configuration.nix index 5741d5b..f678357 100644 --- a/hosts/slate/configuration.nix +++ b/hosts/slate/configuration.nix @@ -2,6 +2,7 @@ { sconfig = { profile = "desktop"; + hardware = "physical"; gnome = true; security-tools = true; }; diff --git a/hosts/slate/default.nix b/hosts/slate/default.nix index 14c0a47..70175cd 100644 --- a/hosts/slate/default.nix +++ b/hosts/slate/default.nix @@ -1,6 +1,5 @@ { pkgs = "nixpkgs"; system = "x86_64-linux"; - hardware = "physical"; module = ./configuration.nix; } diff --git a/lib/hosts.nix b/lib/hosts.nix index 5504b3b..6f4438b 100644 --- a/lib/hosts.nix +++ b/lib/hosts.nix @@ -5,21 +5,6 @@ let (name: _: import (path + "/${name}")) (builtins.readDir path); - hardwareModules = - { - physical = (x: { - imports = [ "${x.modulesPath}/installer/scan/not-detected.nix" ]; - }); - vmware = (x: { - virtualisation.vmware.guest.enable = true; - boot.initrd.availableKernelModules = [ "mptspi" ]; - }); - qemu = (x: { - services.qemuGuest.enable = true; - imports = [ "${x.modulesPath}/profiles/qemu-guest.nix" ]; - }); - }; - getHostConfig = hostName: hostMeta: inputs.${hostMeta.pkgs}.lib.nixosSystem { @@ -27,7 +12,6 @@ let modules = [ (nixosModule) (hostMeta.module) - (hardwareModules.${hostMeta.hardware}) (_: { networking.hostName = hostName; }) (_: { nixpkgs.overlays = [ diff --git a/modules/hardware.nix b/modules/hardware.nix new file mode 100644 index 0000000..05a3dd9 --- /dev/null +++ b/modules/hardware.nix @@ -0,0 +1,36 @@ +{ config, pkgs, lib, modulesPath, ... }: +let + + inherit (pkgs) callPackage; + + hardwareFor = name: cfg: lib.mkIf (config.sconfig.hardware == name) cfg; + + hardwareModules = + [ + (hardwareFor "qemu" + { + inherit (callPackage "${modulesPath}/profiles/qemu-guest.nix" { }) boot; + services.qemuGuest.enable = true; + }) + + (hardwareFor "vmware" + { + virtualisation.vmware.guest.enable = true; + boot.initrd.availableKernelModules = [ "mptspi" ]; + }) + + (hardwareFor "physical" + { + inherit (callPackage "${modulesPath}/installer/scan/not-detected.nix" { }) hardware; + }) + ]; + +in +with lib; +{ + options.sconfig.hardware = mkOption { + type = types.enum [ "physical" "vmware" "qemu" ]; + }; + + config = fold (a: b: a // b) { } hardwareModules; +}