From 03f532e86772def2d52b3c9dfb3e1eacc13a9622 Mon Sep 17 00:00:00 2001 From: UGA Innovation Factory Date: Tue, 6 Jan 2026 14:43:45 -0500 Subject: [PATCH] refactor: define options where they are used --- hosts/boot.nix | 223 +++++++++++++--------------------- hosts/common.nix | 83 +++++++++++-- hosts/default.nix | 1 + hosts/types/nix-desktop.nix | 1 - hosts/types/nix-ephemeral.nix | 1 - hosts/types/nix-laptop.nix | 1 - hosts/types/nix-lxc.nix | 1 - hosts/types/nix-surface.nix | 1 - hosts/types/nix-wsl.nix | 1 - hosts/types/nix-zima.nix | 1 - 10 files changed, 155 insertions(+), 159 deletions(-) diff --git a/hosts/boot.nix b/hosts/boot.nix index a186612..8e81434 100644 --- a/hosts/boot.nix +++ b/hosts/boot.nix @@ -5,29 +5,18 @@ # - Disko partition layout (EFI, swap, root) # - Bootloader configuration (systemd-boot with Plymouth) # - Filesystem options (device, swap size) -# - Build method options (ISO, iPXE, LXC, Proxmox) -# - Garbage collection settings +# - Build method options (used by installer/artifacts.nix) # - Convenience options (forUser, useHostPrefix) { config, lib, ... }: { options.athenix = { - forUser = lib.mkOption { - type = lib.types.nullOr lib.types.str; - default = null; - description = '' - Convenience option to configure a host for a specific user. - Automatically enables the user (sets athenix.users.username.enable = true). - Value should be a username from athenix.users.accounts. - ''; - }; - host = { useHostPrefix = lib.mkOption { type = lib.types.bool; default = true; - description = "Whether to prepend the host prefix to the hostname (used in inventory)."; + description = "Whether to prepend the host prefix to the hostname (used in inventory and hosts/default.nix)."; }; filesystem = { device = lib.mkOption { @@ -44,151 +33,105 @@ description = "The size of the swap partition."; }; }; - buildMethods = lib.mkOption { - type = lib.types.listOf lib.types.str; - default = [ "installer-iso" ]; - description = '' - List of allowed build methods for this host. - Supported methods: - - "installer-iso": Generates an auto-install ISO that installs this configuration to disk. - - "iso": Generates a live ISO (using nixos-generators). - - "ipxe": Generates iPXE netboot artifacts (kernel, initrd, script). - - "lxc": Generates an LXC container tarball. - - "proxmox": Generates a Proxmox VMA archive. - ''; - }; - }; - - system.gc = { - enable = lib.mkOption { - type = lib.types.bool; - default = true; - description = "Whether to enable automatic garbage collection."; - }; - frequency = lib.mkOption { - type = lib.types.str; - default = "weekly"; - description = "How often to run garbage collection (systemd timer format)."; - }; - retentionDays = lib.mkOption { - type = lib.types.int; - default = 30; - description = "Number of days to keep old generations before deletion."; - }; - optimise = lib.mkOption { - type = lib.types.bool; - default = true; - description = "Whether to automatically optimize the Nix store."; - }; }; }; - config = lib.mkMerge [ - # Enable forUser if specified - (lib.mkIf (config.athenix.forUser != null) { - athenix.users.${config.athenix.forUser}.enable = true; - }) + config = { + # ========== Disk Partitioning (Disko) ========== + disko.enableConfig = lib.mkDefault true; - # Main configuration - { - # ========== Disk Partitioning (Disko) ========== - disko.enableConfig = lib.mkDefault true; - - disko.devices = { - disk.main = { - type = "disk"; - device = config.athenix.host.filesystem.device; - content = { - type = "gpt"; - partitions = { - # EFI System Partition - ESP = { - name = "ESP"; - label = "BOOT"; - size = "1G"; - type = "EF00"; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - mountOptions = [ "umask=0077" ]; - extraArgs = [ - "-n" - "BOOT" - ]; - }; + disko.devices = { + disk.main = { + type = "disk"; + device = config.athenix.host.filesystem.device; + content = { + type = "gpt"; + partitions = { + # EFI System Partition + ESP = { + name = "ESP"; + label = "BOOT"; + size = "1G"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; + extraArgs = [ + "-n" + "BOOT" + ]; }; + }; - # Swap Partition (size configurable per host) - swap = lib.mkIf config.athenix.host.filesystem.useSwap { - name = "swap"; - label = "swap"; - size = config.athenix.host.filesystem.swapSize; - content = { - type = "swap"; - }; + # Swap Partition (size configurable per host) + swap = lib.mkIf config.athenix.host.filesystem.useSwap { + name = "swap"; + label = "swap"; + size = config.athenix.host.filesystem.swapSize; + content = { + type = "swap"; }; + }; - # Root Partition (takes remaining space) - root = { - name = "root"; - label = "root"; - size = "100%"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; - extraArgs = [ - "-L" - "ROOT" - ]; - }; + # Root Partition (takes remaining space) + root = { + name = "root"; + label = "root"; + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + extraArgs = [ + "-L" + "ROOT" + ]; }; }; }; }; }; + }; - # Bootloader Configuration - boot = { - loader.systemd-boot.enable = true; - loader.efi.canTouchEfiVariables = true; - plymouth.enable = true; + # Bootloader Configuration + boot = { + loader.systemd-boot.enable = true; + loader.efi.canTouchEfiVariables = true; + plymouth.enable = true; - # Enable "Silent boot" - consoleLogLevel = 3; - initrd.verbose = false; + # Enable "Silent boot" + consoleLogLevel = 3; + initrd.verbose = false; - # Hide the OS choice for bootloaders. - # It's still possible to open the bootloader list by pressing any key - # It will just not appear on screen unless a key is pressed - loader.timeout = lib.mkDefault 0; - }; + # Hide the OS choice for bootloaders. + # It's still possible to open the bootloader list by pressing any key + # It will just not appear on screen unless a key is pressed + loader.timeout = lib.mkDefault 0; + }; - # Set your time zone. - time.timeZone = "America/New_York"; + # Set your time zone. + time.timeZone = "America/New_York"; - # Select internationalisation properties. - i18n.defaultLocale = "en_US.UTF-8"; + # Select internationalisation properties. + i18n.defaultLocale = "en_US.UTF-8"; - i18n.extraLocaleSettings = { - LC_ADDRESS = "en_US.UTF-8"; - LC_IDENTIFICATION = "en_US.UTF-8"; - LC_MEASUREMENT = "en_US.UTF-8"; - LC_MONETARY = "en_US.UTF-8"; - LC_NAME = "en_US.UTF-8"; - LC_NUMERIC = "en_US.UTF-8"; - LC_PAPER = "en_US.UTF-8"; - LC_TELEPHONE = "en_US.UTF-8"; - LC_TIME = "en_US.UTF-8"; - }; + i18n.extraLocaleSettings = { + LC_ADDRESS = "en_US.UTF-8"; + LC_IDENTIFICATION = "en_US.UTF-8"; + LC_MEASUREMENT = "en_US.UTF-8"; + LC_MONETARY = "en_US.UTF-8"; + LC_NAME = "en_US.UTF-8"; + LC_NUMERIC = "en_US.UTF-8"; + LC_PAPER = "en_US.UTF-8"; + LC_TELEPHONE = "en_US.UTF-8"; + LC_TIME = "en_US.UTF-8"; + }; - systemd.sleep.extraConfig = '' - SuspendState=freeze - HibernateDelaySec=2h - ''; - - system.stateVersion = "25.11"; # Did you read the comment? - } - ]; + systemd.sleep.extraConfig = '' + SuspendState=freeze + HibernateDelaySec=2h + ''; + }; } diff --git a/hosts/common.nix b/hosts/common.nix index 908faeb..ba8b4d7 100644 --- a/hosts/common.nix +++ b/hosts/common.nix @@ -28,20 +28,79 @@ inputs.disko.nixosModules.disko ]; - system.stateVersion = "25.11"; + # Define garbage collection options here since they're consumed in this module + options.athenix = { + forUser = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + description = '' + Convenience option to configure a host for a specific user. + Automatically enables the user (sets athenix.users.username.enable = true). + Value should be a username from athenix.users.accounts. + ''; + }; - nix.settings.experimental-features = [ - "nix-command" - "flakes" - ]; + system.gc = { + enable = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Whether to enable automatic garbage collection."; + }; + frequency = lib.mkOption { + type = lib.types.str; + default = "weekly"; + description = "How often to run garbage collection (systemd timer format)."; + }; + retentionDays = lib.mkOption { + type = lib.types.int; + default = 30; + description = "Number of days to keep old generations before deletion."; + }; + optimise = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Whether to automatically optimize the Nix store."; + }; + }; - # Automatic Garbage Collection - nix.gc = lib.mkIf config.athenix.system.gc.enable { - automatic = true; - dates = config.athenix.system.gc.frequency; - options = "--delete-older-than ${toString config.athenix.system.gc.retentionDays}d"; + host.buildMethods = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ "installer-iso" ]; + description = '' + List of allowed build methods for this host (used by installer/artifacts.nix). + Supported methods: + - "installer-iso": Generates an auto-install ISO that installs this configuration to disk. + - "iso": Generates a live ISO (using nixos-generators). + - "ipxe": Generates iPXE netboot artifacts (kernel, initrd, script). + - "lxc": Generates an LXC container tarball. + - "proxmox": Generates a Proxmox VMA archive. + ''; + }; }; - # Optimize storage - nix.optimise.automatic = config.athenix.system.gc.optimise; + config = lib.mkMerge [ + # Enable forUser if specified + (lib.mkIf (config.athenix.forUser != null) { + athenix.users.${config.athenix.forUser}.enable = true; + }) + + { + system.stateVersion = "25.11"; + + nix.settings.experimental-features = [ + "nix-command" + "flakes" + ]; + + # Automatic Garbage Collection + nix.gc = lib.mkIf config.athenix.system.gc.enable { + automatic = true; + dates = config.athenix.system.gc.frequency; + options = "--delete-older-than ${toString config.athenix.system.gc.retentionDays}d"; + }; + + # Optimize storage + nix.optimise.automatic = config.athenix.system.gc.optimise; + } + ]; } diff --git a/hosts/default.nix b/hosts/default.nix index 9ca57fd..f664aed 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -132,6 +132,7 @@ let allModules = userNixosModules ++ [ + (import ./common.nix { inherit inputs; }) typeModule overrideModule { networking.hostName = hostName; } diff --git a/hosts/types/nix-desktop.nix b/hosts/types/nix-desktop.nix index fc5e0e2..2455eba 100644 --- a/hosts/types/nix-desktop.nix +++ b/hosts/types/nix-desktop.nix @@ -13,7 +13,6 @@ }: { imports = [ - (import ../common.nix { inherit inputs; }) (modulesPath + "/installer/scan/not-detected.nix") ]; diff --git a/hosts/types/nix-ephemeral.nix b/hosts/types/nix-ephemeral.nix index f4f7504..51e46c0 100644 --- a/hosts/types/nix-ephemeral.nix +++ b/hosts/types/nix-ephemeral.nix @@ -14,7 +14,6 @@ }: { imports = [ - (import ../common.nix { inherit inputs; }) (modulesPath + "/installer/scan/not-detected.nix") ]; diff --git a/hosts/types/nix-laptop.nix b/hosts/types/nix-laptop.nix index c439ceb..6d9ed5c 100644 --- a/hosts/types/nix-laptop.nix +++ b/hosts/types/nix-laptop.nix @@ -13,7 +13,6 @@ }: { imports = [ - (import ../common.nix { inherit inputs; }) (modulesPath + "/installer/scan/not-detected.nix") ]; diff --git a/hosts/types/nix-lxc.nix b/hosts/types/nix-lxc.nix index fb7574e..cecb409 100644 --- a/hosts/types/nix-lxc.nix +++ b/hosts/types/nix-lxc.nix @@ -13,7 +13,6 @@ }: { imports = [ - (import ../common.nix { inherit inputs; }) inputs.vscode-server.nixosModules.default "${modulesPath}/virtualisation/proxmox-lxc.nix" ]; diff --git a/hosts/types/nix-surface.nix b/hosts/types/nix-surface.nix index 78a8fe8..53f74c4 100644 --- a/hosts/types/nix-surface.nix +++ b/hosts/types/nix-surface.nix @@ -22,7 +22,6 @@ let in { imports = [ - (import ../common.nix { inherit inputs; }) (modulesPath + "/installer/scan/not-detected.nix") inputs.nixos-hardware.nixosModules.microsoft-surface-go ]; diff --git a/hosts/types/nix-wsl.nix b/hosts/types/nix-wsl.nix index 14e0313..f13787a 100644 --- a/hosts/types/nix-wsl.nix +++ b/hosts/types/nix-wsl.nix @@ -12,7 +12,6 @@ }: { imports = [ - (import ../common.nix { inherit inputs; }) inputs.nixos-wsl.nixosModules.default inputs.vscode-server.nixosModules.default ]; diff --git a/hosts/types/nix-zima.nix b/hosts/types/nix-zima.nix index 40a9cec..1174ff0 100644 --- a/hosts/types/nix-zima.nix +++ b/hosts/types/nix-zima.nix @@ -13,7 +13,6 @@ }: { imports = [ - (import ../common.nix { inherit inputs; }) (modulesPath + "/installer/scan/not-detected.nix") ];