From b649b974fa4d06756f30e59f499424c20995bc46 Mon Sep 17 00:00:00 2001 From: tux Date: Wed, 13 May 2026 04:33:14 +0530 Subject: [PATCH] refactor(hosts): simplify configuration imports across hosts --- modules/hosts/alpha/config.nix | 19 +++++---------- modules/hosts/alpha/default.nix | 9 ++++++- modules/hosts/alpha/hardware.nix | 17 +++++++++++++ modules/hosts/arcturus/config.nix | 6 ----- modules/hosts/arcturus/default.nix | 9 ++++++- modules/hosts/arcturus/hardware.nix | 26 +++++++++++--------- modules/hosts/canopus/config.nix | 14 ----------- modules/hosts/canopus/default.nix | 9 ++++++- modules/hosts/canopus/hardware.nix | 21 ++++++++-------- modules/hosts/sirius/config.nix | 14 ----------- modules/hosts/sirius/default.nix | 9 ++++++- modules/hosts/sirius/hardware.nix | 37 ++++++++++++++++++++--------- modules/hosts/vps/config.nix | 19 +++++---------- modules/hosts/vps/default.nix | 9 ++++++- modules/hosts/vps/hardware.nix | 17 +++++++++++++ 15 files changed, 137 insertions(+), 98 deletions(-) create mode 100644 modules/hosts/alpha/hardware.nix create mode 100644 modules/hosts/vps/hardware.nix diff --git a/modules/hosts/alpha/config.nix b/modules/hosts/alpha/config.nix index e2d2626..14e115a 100644 --- a/modules/hosts/alpha/config.nix +++ b/modules/hosts/alpha/config.nix @@ -4,22 +4,15 @@ { hostName, userName, - modulesPath, ... }: { - imports = - with config.flake.modules.nixos; - [ - boot - hardware - networking - virtualisation - services - ] - ++ [ - (modulesPath + "/profiles/qemu-guest.nix") - ]; + imports = with config.flake.modules.nixos; [ + boot + networking + virtualisation + services + ]; tnix = { boot = { diff --git a/modules/hosts/alpha/default.nix b/modules/hosts/alpha/default.nix index df67fe3..ea6e18e 100644 --- a/modules/hosts/alpha/default.nix +++ b/modules/hosts/alpha/default.nix @@ -14,7 +14,14 @@ in { flake.nixosConfigurations."${hostName}" = nixpkgs.lib.nixosSystem { inherit system; - specialArgs = { inherit hostName userName userEmail; }; + specialArgs = { + inherit + hostName + userName + userEmail + system + ; + }; modules = [ config.flake.modules.nixos.core config.flake.modules.nixos.${hostName} diff --git a/modules/hosts/alpha/hardware.nix b/modules/hosts/alpha/hardware.nix new file mode 100644 index 0000000..297cffe --- /dev/null +++ b/modules/hosts/alpha/hardware.nix @@ -0,0 +1,17 @@ +{ + flake.modules.nixos.alpha = + { + lib, + modulesPath, + system, + ... + }: + { + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + networking.useDHCP = lib.mkDefault true; + nixpkgs.hostPlatform = lib.mkDefault system; + }; +} diff --git a/modules/hosts/arcturus/config.nix b/modules/hosts/arcturus/config.nix index 1e0d200..1526dc8 100644 --- a/modules/hosts/arcturus/config.nix +++ b/modules/hosts/arcturus/config.nix @@ -2,7 +2,6 @@ { flake.modules.nixos.arcturus = { - pkgs, hostName, userName, ... @@ -10,7 +9,6 @@ { imports = with config.flake.modules.nixos; [ boot - hardware networking virtualisation services @@ -109,10 +107,6 @@ firewall.enable = false; }; - environment.systemPackages = with pkgs; [ - nvtopPackages.full - ]; - system.stateVersion = "26.05"; }; } diff --git a/modules/hosts/arcturus/default.nix b/modules/hosts/arcturus/default.nix index a3f8793..e4f6c8e 100644 --- a/modules/hosts/arcturus/default.nix +++ b/modules/hosts/arcturus/default.nix @@ -14,7 +14,14 @@ in { flake.nixosConfigurations."${hostName}" = nixpkgs.lib.nixosSystem { inherit system; - specialArgs = { inherit hostName userName userEmail; }; + specialArgs = { + inherit + hostName + userName + userEmail + system + ; + }; modules = [ config.flake.modules.nixos.core config.flake.modules.nixos.${hostName} diff --git a/modules/hosts/arcturus/hardware.nix b/modules/hosts/arcturus/hardware.nix index 2857c16..8648393 100644 --- a/modules/hosts/arcturus/hardware.nix +++ b/modules/hosts/arcturus/hardware.nix @@ -1,11 +1,17 @@ +{ config, ... }: { flake.modules.nixos.arcturus = { - config, lib, + pkgs, + system, ... - }: + }@innerArgs: { + imports = with config.flake.modules.nixos; [ + hardware + ]; + boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" @@ -18,15 +24,13 @@ boot.kernelModules = [ "kvm-amd" ]; boot.extraModulePackages = [ ]; - # 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.useDHCP = lib.mkDefault true; - # networking.interfaces.eno1.useDHCP = lib.mkDefault true; - # networking.interfaces.wlp10s0f3u2i2.useDHCP = lib.mkDefault true; + hardware.cpu.amd.updateMicrocode = lib.mkDefault innerArgs.config.hardware.enableRedistributableFirmware; - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + networking.useDHCP = lib.mkDefault true; + nixpkgs.hostPlatform = lib.mkDefault system; + + environment.systemPackages = with pkgs; [ + nvtopPackages.amd + ]; }; } diff --git a/modules/hosts/canopus/config.nix b/modules/hosts/canopus/config.nix index 5b0bfd7..b2769a3 100644 --- a/modules/hosts/canopus/config.nix +++ b/modules/hosts/canopus/config.nix @@ -10,7 +10,6 @@ { imports = with config.flake.modules.nixos; [ boot - hardware networking desktop gaming @@ -120,20 +119,7 @@ firewall.enable = false; }; - # --- Hardware / GPU --- - # hardware = { - # nvidia = { - # modesetting.enable = true; - # open = false; - # nvidiaSettings = true; - # }; - # }; - # boot.kernelParams = [ "nvidia-drm.modeset=1" ]; - # nixpkgs.config.cudaSupport = true; - # services.xserver.videoDrivers = [ "nvidia" ]; - environment.systemPackages = with pkgs; [ - nvtopPackages.full davinci-resolve telegram-desktop ]; diff --git a/modules/hosts/canopus/default.nix b/modules/hosts/canopus/default.nix index 03a73fc..a9b3e47 100644 --- a/modules/hosts/canopus/default.nix +++ b/modules/hosts/canopus/default.nix @@ -14,7 +14,14 @@ in { flake.nixosConfigurations."${hostName}" = nixpkgs.lib.nixosSystem { inherit system; - specialArgs = { inherit hostName userName userEmail; }; + specialArgs = { + inherit + hostName + userName + userEmail + system + ; + }; modules = [ config.flake.modules.nixos.core config.flake.modules.nixos.${hostName} diff --git a/modules/hosts/canopus/hardware.nix b/modules/hosts/canopus/hardware.nix index f69252d..09ba4cf 100644 --- a/modules/hosts/canopus/hardware.nix +++ b/modules/hosts/canopus/hardware.nix @@ -1,11 +1,16 @@ +{ config, ... }: { flake.modules.nixos.canopus = { - config, lib, + system, ... - }: + }@innerArgs: { + imports = with config.flake.modules.nixos; [ + hardware + ]; + boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" @@ -18,15 +23,9 @@ boot.kernelModules = [ "kvm-amd" ]; boot.extraModulePackages = [ ]; - # 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.useDHCP = lib.mkDefault true; - # networking.interfaces.eno1.useDHCP = lib.mkDefault true; - # networking.interfaces.wlp10s0f3u2i2.useDHCP = lib.mkDefault true; + hardware.cpu.amd.updateMicrocode = lib.mkDefault innerArgs.config.hardware.enableRedistributableFirmware; - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + networking.useDHCP = lib.mkDefault true; + nixpkgs.hostPlatform = lib.mkDefault system; }; } diff --git a/modules/hosts/sirius/config.nix b/modules/hosts/sirius/config.nix index fa97499..84903ef 100644 --- a/modules/hosts/sirius/config.nix +++ b/modules/hosts/sirius/config.nix @@ -10,7 +10,6 @@ { imports = with config.flake.modules.nixos; [ boot - hardware networking desktop gaming @@ -121,20 +120,7 @@ firewall.enable = false; }; - # --- Hardware / GPU --- - hardware = { - nvidia = { - modesetting.enable = true; - open = false; - nvidiaSettings = true; - }; - }; - boot.kernelParams = [ "nvidia-drm.modeset=1" ]; - nixpkgs.config.cudaSupport = true; - services.xserver.videoDrivers = [ "nvidia" ]; - environment.systemPackages = with pkgs; [ - nvtopPackages.full davinci-resolve telegram-desktop ]; diff --git a/modules/hosts/sirius/default.nix b/modules/hosts/sirius/default.nix index b77e9ac..d9b5f9b 100644 --- a/modules/hosts/sirius/default.nix +++ b/modules/hosts/sirius/default.nix @@ -14,7 +14,14 @@ in { flake.nixosConfigurations."${hostName}" = nixpkgs.lib.nixosSystem { inherit system; - specialArgs = { inherit hostName userName userEmail; }; + specialArgs = { + inherit + hostName + userName + userEmail + system + ; + }; modules = [ config.flake.modules.nixos.core config.flake.modules.nixos.${hostName} diff --git a/modules/hosts/sirius/hardware.nix b/modules/hosts/sirius/hardware.nix index d5b41df..45b9a6c 100644 --- a/modules/hosts/sirius/hardware.nix +++ b/modules/hosts/sirius/hardware.nix @@ -1,11 +1,18 @@ +{ config, ... }: { flake.modules.nixos.sirius = { - config, lib, + pkgs, + system, ... - }: + }@innerArgs: { + imports = with config.flake.modules.nixos; [ + hardware + ]; + + boot.kernelParams = [ "nvidia-drm.modeset=1" ]; boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" @@ -18,15 +25,23 @@ boot.kernelModules = [ "kvm-amd" ]; boot.extraModulePackages = [ ]; - # 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.useDHCP = lib.mkDefault true; - # networking.interfaces.eno1.useDHCP = lib.mkDefault true; - # networking.interfaces.wlp10s0f3u2i2.useDHCP = lib.mkDefault true; + hardware = { + nvidia = { + modesetting.enable = true; + open = false; + nvidiaSettings = true; + }; - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + cpu.amd.updateMicrocode = lib.mkDefault innerArgs.config.hardware.enableRedistributableFirmware; + }; + services.xserver.videoDrivers = [ "nvidia" ]; + + networking.useDHCP = lib.mkDefault true; + nixpkgs.config.cudaSupport = true; + nixpkgs.hostPlatform = lib.mkDefault system; + + environment.systemPackages = with pkgs; [ + nvtopPackages.full + ]; }; } diff --git a/modules/hosts/vps/config.nix b/modules/hosts/vps/config.nix index 6ecd88d..ac29c61 100644 --- a/modules/hosts/vps/config.nix +++ b/modules/hosts/vps/config.nix @@ -3,22 +3,15 @@ flake.modules.nixos.vps = { hostName, - modulesPath, ... }: { - imports = - with config.flake.modules.nixos; - [ - boot - hardware - networking - virtualisation - services - ] - ++ [ - (modulesPath + "/profiles/qemu-guest.nix") - ]; + imports = with config.flake.modules.nixos; [ + boot + networking + virtualisation + services + ]; tnix = { boot = { diff --git a/modules/hosts/vps/default.nix b/modules/hosts/vps/default.nix index 73b21bb..600077d 100644 --- a/modules/hosts/vps/default.nix +++ b/modules/hosts/vps/default.nix @@ -14,7 +14,14 @@ in { flake.nixosConfigurations."${hostName}" = nixpkgs.lib.nixosSystem { inherit system; - specialArgs = { inherit hostName userName userEmail; }; + specialArgs = { + inherit + hostName + userName + userEmail + system + ; + }; modules = [ config.flake.modules.nixos.core config.flake.modules.nixos.${hostName} diff --git a/modules/hosts/vps/hardware.nix b/modules/hosts/vps/hardware.nix new file mode 100644 index 0000000..0dbbb22 --- /dev/null +++ b/modules/hosts/vps/hardware.nix @@ -0,0 +1,17 @@ +{ + flake.modules.nixos.vps = + { + lib, + modulesPath, + system, + ... + }: + { + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + networking.useDHCP = lib.mkDefault true; + nixpkgs.hostPlatform = lib.mkDefault system; + }; +}