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 = { sconfig = {
gnome = true; gnome = true;
profile = "desktop"; profile = "desktop";
hardware = "physical";
security-tools = true; security-tools = true;
i3.extraConfig = '' i3.extraConfig = ''
exec xrandr --output DisplayPort-0 --mode 2560x1440 --rate 165 exec xrandr --output DisplayPort-0 --mode 2560x1440 --rate 165

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,21 +5,6 @@ let
(name: _: import (path + "/${name}")) (name: _: import (path + "/${name}"))
(builtins.readDir path); (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: getHostConfig = hostName: hostMeta:
inputs.${hostMeta.pkgs}.lib.nixosSystem inputs.${hostMeta.pkgs}.lib.nixosSystem
{ {
@ -27,7 +12,6 @@ let
modules = [ modules = [
(nixosModule) (nixosModule)
(hostMeta.module) (hostMeta.module)
(hardwareModules.${hostMeta.hardware})
(_: { networking.hostName = hostName; }) (_: { networking.hostName = hostName; })
(_: { (_: {
nixpkgs.overlays = [ 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;
}