move hardware stuff from getHosts to module

This commit is contained in:
Sean Buckley 2021-09-28 22:24:03 -04:00
parent a117839071
commit a118b52a02
10 changed files with 40 additions and 20 deletions

View file

@ -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

View file

@ -1,6 +1,5 @@
{
pkgs = "nixpkgs";
system = "x86_64-linux";
hardware = "physical";
module = ./configuration.nix;
}

View file

@ -7,6 +7,7 @@
sconfig = {
gnome = true;
profile = "desktop";
hardware = "physical";
security-tools = true;
};

View file

@ -1,6 +1,5 @@
{
pkgs = "nixpkgs";
system = "x86_64-linux";
hardware = "physical";
module = ./configuration.nix;
}

View file

@ -2,6 +2,7 @@
{
sconfig = {
profile = "server";
hardware = "qemu";
};
environment.persistence."/nix/persist" = {

View file

@ -1,6 +1,5 @@
{
pkgs = "nixpkgs";
system = "x86_64-linux";
hardware = "qemu";
module = ./configuration.nix;
}

View file

@ -2,6 +2,7 @@
{
sconfig = {
profile = "desktop";
hardware = "physical";
gnome = true;
security-tools = true;
};

View file

@ -1,6 +1,5 @@
{
pkgs = "nixpkgs";
system = "x86_64-linux";
hardware = "physical";
module = ./configuration.nix;
}

View file

@ -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 = [

36
modules/hardware.nix Normal file
View file

@ -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;
}