From 18b6b0f605db3b56e4cf553f0322b09ecaf0eb0d Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Wed, 29 Nov 2023 15:33:45 +0100 Subject: [PATCH] feat(modules/dgn-harware): Refactor hardware config --- machines/compute01/_configuration.nix | 2 + .../compute01/_hardware-configuration.nix | 41 ++++--------- machines/storage01/_configuration.nix | 4 ++ .../storage01/_hardware-configuration.nix | 57 ++++--------------- machines/web01/_hardware-configuration.nix | 19 ++----- modules/dgn-hardware.nix | 55 ++++++++++++++---- 6 files changed, 76 insertions(+), 102 deletions(-) diff --git a/machines/compute01/_configuration.nix b/machines/compute01/_configuration.nix index 1b39850..3400c06 100644 --- a/machines/compute01/_configuration.nix +++ b/machines/compute01/_configuration.nix @@ -28,6 +28,8 @@ lib.extra.mkConfig { "sshd-bruteforce" "sshd-timeout" ]; + + dgn-hardware.useZfs = true; }; root = ./.; diff --git a/machines/compute01/_hardware-configuration.nix b/machines/compute01/_hardware-configuration.nix index 5c7c0a4..629c599 100644 --- a/machines/compute01/_hardware-configuration.nix +++ b/machines/compute01/_hardware-configuration.nix @@ -1,42 +1,21 @@ # Do not modify this file! It was generated by ‘nixos-generate-config’ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. -{ config, lib, pkgs, modulesPath, ... }: +{ modulesPath, ... }: { - imports = - [ - (modulesPath + "/installer/scan/not-detected.nix") - ]; + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - boot.initrd.availableKernelModules = [ "ahci" "ehci_pci" "megaraid_sas" "usb_storage" "usbhid" "sd_mod" "sr_mod" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.supportedFilesystems = [ "zfs" ]; - boot.zfs.forceImportRoot = false; - boot.zfs.extraPools = [ "fast01" "work01" ]; - boot.extraModulePackages = [ ]; + fileSystems."/" = { + device = "/dev/disk/by-uuid/c83f6978-fd26-44a8-a86a-b0e971bb0c8c"; + fsType = "ext4"; + }; - fileSystems."/" = - { - device = "/dev/disk/by-uuid/c83f6978-fd26-44a8-a86a-b0e971bb0c8c"; - fsType = "ext4"; - }; - - fileSystems."/boot" = - { - device = "/dev/disk/by-uuid/55DB-056F"; - fsType = "vfat"; - }; + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/55DB-056F"; + fsType = "vfat"; + }; swapDevices = [{ device = "/dev/disk/by-uuid/30547280-00e9-4ee1-8a07-d116590d9fbf"; }]; - - # networking.interfaces.eno2.useDHCP = lib.mkDefault true; - # networking.interfaces.eno3.useDHCP = lib.mkDefault true; - # networking.interfaces.eno4.useDHCP = lib.mkDefault true; - # networking.interfaces.idrac.useDHCP = lib.mkDefault true; - - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; } diff --git a/machines/storage01/_configuration.nix b/machines/storage01/_configuration.nix index 5f216d3..e41d0b7 100644 --- a/machines/storage01/_configuration.nix +++ b/machines/storage01/_configuration.nix @@ -14,5 +14,9 @@ lib.extra.mkConfig { "peertube" ]; + extraConfig = { + dgn-hardware.useZfs = true; + }; + root = ./.; } diff --git a/machines/storage01/_hardware-configuration.nix b/machines/storage01/_hardware-configuration.nix index 7706a41..2272703 100644 --- a/machines/storage01/_hardware-configuration.nix +++ b/machines/storage01/_hardware-configuration.nix @@ -1,58 +1,21 @@ # Do not modify this file! It was generated by ‘nixos-generate-config’ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. -{ config, lib, modulesPath, ... }: +{ modulesPath, ... }: { - imports = - [ - (modulesPath + "/installer/scan/not-detected.nix") - ]; + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - boot.initrd.availableKernelModules = [ "ahci" "ehci_pci" "megaraid_sas" "usb_storage" "usbhid" "sd_mod" "sr_mod" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.supportedFilesystems = [ "zfs" ]; - boot.zfs.forceImportRoot = false; - boot.zfs.extraPools = [ "fast01" "work01" ]; - boot.extraModulePackages = [ ]; + fileSystems."/" = { + device = "/dev/disk/by-uuid/278cb2a2-47b9-4ec5-8b68-a5a6d037d59e"; + fsType = "ext4"; + }; - fileSystems."/" = - { - device = "/dev/disk/by-uuid/278cb2a2-47b9-4ec5-8b68-a5a6d037d59e"; - fsType = "ext4"; - }; - - fileSystems."/boot" = - { - device = "/dev/disk/by-uuid/8BD2-C908"; - fsType = "vfat"; - }; + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/8BD2-C908"; + fsType = "vfat"; + }; swapDevices = [{ device = "/dev/disk/by-uuid/65a6f6e4-e996-4718-a4d0-cd0c78dcb15b"; }]; - - # Enables DHCP on each ethernet and wireless interface. In case of scripted networking - # (the default) this is the recommended approach. When using systemd-networkd it's - # still possible to use this option, but it's recommended to use it in conjunction - # with explicit per-interface declarations with `networking.interfaces..useDHCP`. - # networking.interfaces.eno1 = { - # useDHCP = true; - # ipv4 = { - # addresses = [ - # { address = "129.199.146.148"; prefixLength = 24; } - # { address = "192.168.1.148"; prefixLength = 24; } - # ]; - # - # routes = [ - # { address = "192.168.1.0"; prefixLength = 24; } - # ]; - # }; - # }; - # networking.interfaces.eno2.useDHCP = lib.mkDefault true; - # networking.interfaces.eno3.useDHCP = lib.mkDefault true; - # networking.interfaces.eno4.useDHCP = lib.mkDefault true; - - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; } diff --git a/machines/web01/_hardware-configuration.nix b/machines/web01/_hardware-configuration.nix index 0cff5b2..015c67b 100644 --- a/machines/web01/_hardware-configuration.nix +++ b/machines/web01/_hardware-configuration.nix @@ -1,21 +1,12 @@ # Do not modify this file! It was generated by ‘nixos-generate-config’ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. -{ config, lib, pkgs, modulesPath, ... }: +{ modulesPath, ... }: { imports = [ - (modulesPath + "/profiles/qemu-guest.nix") - (let sources = import ../../npins; in sources.disko + "/module.nix") - ./disko.nix - ]; - - boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "ehci_pci" "virtio_pci" "ahci" "virtio_blk" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; - - - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + (modulesPath + "/profiles/qemu-guest.nix") + (let sources = import ../../npins; in sources.disko + "/module.nix") + ./disko.nix + ]; } diff --git a/modules/dgn-hardware.nix b/modules/dgn-hardware.nix index f178b37..6993fcd 100644 --- a/modules/dgn-hardware.nix +++ b/modules/dgn-hardware.nix @@ -1,23 +1,36 @@ -{ config, lib, ... }: +{ config, lib, pkgs, ... }: let - inherit (lib) - mkEnableOption - mkIf - mkMerge; + inherit (lib) mkEnableOption mkIf mkMerge; cfg = config.dgn-hardware; -in -{ +in { options.dgn-hardware = { - enable = mkEnableOption "default hardware configuration." // { default = true; }; + enable = mkEnableOption "default hardware configuration." // { + default = true; + }; - useSystemd = mkEnableOption "sytemd boot and configuration." // { default = true; }; + useSystemd = mkEnableOption "sytemd boot and configuration." // { + default = true; + }; + + useZfs = mkEnableOption "zfs configuration."; }; config = mkIf cfg.enable (mkMerge [ - { hardware.enableRedistributableFirmware = true; } + { + hardware.enableRedistributableFirmware = true; + hardware.cpu.intel.updateMicrocode = true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + + boot = { + initrd.availableKernelModules = + [ "ata_piix" "uhci_hcd" "ehci_pci" "virtio_pci" "ahci" "virtio_blk" ]; + kernelModules = [ "kvm-intel" ]; + }; + } (mkIf cfg.useSystemd { boot.loader = { @@ -25,5 +38,27 @@ in efi.canTouchEfiVariables = true; }; }) + + (mkIf cfg.useZfs { + boot = { + initrd.availableKernelModules = [ + "ahci" + "ehci_pci" + "megaraid_sas" + "usb_storage" + "usbhid" + "sd_mod" + "sr_mod" + ]; + kernelModules = [ "kvm-intel" ]; + supportedFilesystems = [ "zfs" ]; + + zfs = { + forceImportRoot = false; + extraPools = [ "fast01" "work01" ]; + package = pkgs.zfs_2_1; + }; + }; + }) ]); }