From a38cebe6f366c99c197451c150ab84d6becdbdc7 Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Fri, 10 Dec 2021 01:34:46 -0500 Subject: [PATCH] move hardware profiles --- flake.nix | 12 +++------ hosts/default.nix | 17 ++++++++++++ hosts/x86_64-linux/cube/default.nix | 3 ++- hosts/x86_64-linux/hp/default.nix | 3 ++- hosts/x86_64-linux/lenny/default.nix | 3 ++- hosts/x86_64-linux/nixdev/default.nix | 3 ++- hosts/x86_64-linux/slate/default.nix | 3 ++- lib/hardware.nix | 20 ++++++++++++++ modules/hardware.nix | 39 --------------------------- 9 files changed, 50 insertions(+), 53 deletions(-) create mode 100644 hosts/default.nix create mode 100644 lib/hardware.nix delete mode 100644 modules/hardware.nix diff --git a/flake.nix b/flake.nix index 7a5d245..fabf8c5 100644 --- a/flake.nix +++ b/flake.nix @@ -5,8 +5,8 @@ let mypkgs = import ./pkgs; - getHosts = import lib/hosts.nix; morphHosts = import lib/morph.nix; + hardware = import lib/hardware.nix; forAllSystems = f: builtins.listToAttrs (map (name: { inherit name; value = f name; }) @@ -23,7 +23,7 @@ in { - lib = { inherit forAllSystems getHosts morphHosts; }; + lib = { inherit forAllSystems morphHosts hardware; }; nixosModules = { inherit pins; } // @@ -39,13 +39,7 @@ nixpkgs.overlays = [ (_: mypkgs) ]; }; - nixosConfigurations = - builtins.mapAttrs - (_: nixpkgs.lib.nixosSystem) - (getHosts { - inherit (self) nixosModule; - path = ./hosts; - }); + nixosConfigurations = import ./hosts nixpkgs hardware self.nixosModule; packages = forAllSystems (system: mypkgs nixpkgs.legacyPackages.${system}); diff --git a/hosts/default.nix b/hosts/default.nix new file mode 100644 index 0000000..76efc2d --- /dev/null +++ b/hosts/default.nix @@ -0,0 +1,17 @@ +nixpkgs: hardware: nixosModule: +with hardware; + +let + sys = args: nixpkgs.lib.nixosSystem { + system = builtins.head args; + modules = [ nixosModule ] ++ builtins.tail args; + }; + +in +{ + cube = sys [ "x86_64-linux" physical ./x86_64-linux/cube ]; + hp = sys [ "x86_64-linux" physical ./x86_64-linux/hp ]; + lenny = sys [ "x86_64-linux" physical ./x86_64-linux/lenny ]; + nixdev = sys [ "x86_64-linux" qemu ./x86_64-linux/nixdev ]; + slate = sys [ "x86_64-linux" physical ./x86_64-linux/slate ]; +} diff --git a/hosts/x86_64-linux/cube/default.nix b/hosts/x86_64-linux/cube/default.nix index f631730..8a57330 100644 --- a/hosts/x86_64-linux/cube/default.nix +++ b/hosts/x86_64-linux/cube/default.nix @@ -1,9 +1,10 @@ { pkgs, ... }: { + networking.hostName = "cube"; + sconfig = { gnome = true; profile = "desktop"; - hardware = "physical"; }; environment.etc = diff --git a/hosts/x86_64-linux/hp/default.nix b/hosts/x86_64-linux/hp/default.nix index 9d693a5..e9edba4 100644 --- a/hosts/x86_64-linux/hp/default.nix +++ b/hosts/x86_64-linux/hp/default.nix @@ -1,5 +1,7 @@ { pkgs, ... }: { + networking.hostName = "hp"; + services = { openssh.enable = true; }; @@ -21,7 +23,6 @@ sconfig = { gnome = true; profile = "desktop"; - hardware = "physical"; }; environment.systemPackages = [ pkgs.vmware-horizon-client ]; diff --git a/hosts/x86_64-linux/lenny/default.nix b/hosts/x86_64-linux/lenny/default.nix index 1e00538..0aa164d 100644 --- a/hosts/x86_64-linux/lenny/default.nix +++ b/hosts/x86_64-linux/lenny/default.nix @@ -1,5 +1,7 @@ { pkgs, ... }: { + networking.hostName = "lenny"; + services = { openssh.enable = true; }; @@ -21,7 +23,6 @@ sconfig = { gnome = true; profile = "desktop"; - hardware = "physical"; }; environment.systemPackages = [ pkgs.vmware-horizon-client ]; diff --git a/hosts/x86_64-linux/nixdev/default.nix b/hosts/x86_64-linux/nixdev/default.nix index afc6344..2096f10 100644 --- a/hosts/x86_64-linux/nixdev/default.nix +++ b/hosts/x86_64-linux/nixdev/default.nix @@ -1,8 +1,9 @@ { config, lib, pkgs, ... }: { + networking.hostName = "nixdev"; + sconfig = { gnome = true; - hardware = "qemu"; profile = "desktop"; }; diff --git a/hosts/x86_64-linux/slate/default.nix b/hosts/x86_64-linux/slate/default.nix index a15460a..336b60b 100644 --- a/hosts/x86_64-linux/slate/default.nix +++ b/hosts/x86_64-linux/slate/default.nix @@ -1,8 +1,9 @@ { pkgs, ... }: { + networking.hostName = "slate"; + sconfig = { profile = "desktop"; - hardware = "physical"; gnome = true; }; diff --git a/lib/hardware.nix b/lib/hardware.nix new file mode 100644 index 0000000..0c4ca09 --- /dev/null +++ b/lib/hardware.nix @@ -0,0 +1,20 @@ +{ + physical = { lib, modulesPath, ... }: lib.mkMerge + [ + (import "${modulesPath}/installer/scan/not-detected.nix" { inherit lib; }) + { hardware.cpu.amd.updateMicrocode = true; } + { hardware.cpu.intel.updateMicrocode = true; } + ]; + + qemu = { lib, modulesPath, ... }: lib.mkMerge + [ + (import "${modulesPath}/profiles/qemu-guest.nix" { }) + { services.qemuGuest.enable = true; } + ]; + + vmware = { lib, modulesPath, ... }: lib.mkMerge + [ + { virtualisation.vmware.guest.enable = true; } + { boot.initrd.availableKernelModules = [ "mptspi" ]; } + ]; +} diff --git a/modules/hardware.nix b/modules/hardware.nix deleted file mode 100644 index 838d4b0..0000000 --- a/modules/hardware.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ config, lib, modulesPath, ... }: -let - - hardwareFor = name: cfg: - lib.mkIf - (config.sconfig.hardware == name) - (lib.mkMerge cfg); - - hardwareModules = - [ - (hardwareFor "qemu" - [ - (import "${modulesPath}/profiles/qemu-guest.nix" { }) - { services.qemuGuest.enable = true; } - ]) - - (hardwareFor "vmware" - [ - { virtualisation.vmware.guest.enable = true; } - { boot.initrd.availableKernelModules = [ "mptspi" ]; } - ]) - - (hardwareFor "physical" - [ - (import "${modulesPath}/installer/scan/not-detected.nix" { inherit lib; }) - { hardware.cpu.amd.updateMicrocode = true; } - { hardware.cpu.intel.updateMicrocode = true; } - ]) - ]; - -in -with lib; -{ - options.sconfig.hardware = mkOption { - type = types.enum [ "physical" "vmware" "qemu" ]; - }; - - config = mkMerge hardwareModules; -}