refactor: define options where they are used

This commit is contained in:
UGA Innovation Factory
2026-01-06 14:43:45 -05:00
parent 9a2f167efe
commit 03f532e867
10 changed files with 155 additions and 159 deletions

View File

@@ -5,29 +5,18 @@
# - Disko partition layout (EFI, swap, root) # - Disko partition layout (EFI, swap, root)
# - Bootloader configuration (systemd-boot with Plymouth) # - Bootloader configuration (systemd-boot with Plymouth)
# - Filesystem options (device, swap size) # - Filesystem options (device, swap size)
# - Build method options (ISO, iPXE, LXC, Proxmox) # - Build method options (used by installer/artifacts.nix)
# - Garbage collection settings
# - Convenience options (forUser, useHostPrefix) # - Convenience options (forUser, useHostPrefix)
{ config, lib, ... }: { config, lib, ... }:
{ {
options.athenix = { 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 = { host = {
useHostPrefix = lib.mkOption { useHostPrefix = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = true; 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 = { filesystem = {
device = lib.mkOption { device = lib.mkOption {
@@ -44,151 +33,105 @@
description = "The size of the swap partition."; 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 [ config = {
# Enable forUser if specified # ========== Disk Partitioning (Disko) ==========
(lib.mkIf (config.athenix.forUser != null) { disko.enableConfig = lib.mkDefault true;
athenix.users.${config.athenix.forUser}.enable = true;
})
# Main configuration disko.devices = {
{ disk.main = {
# ========== Disk Partitioning (Disko) ========== type = "disk";
disko.enableConfig = lib.mkDefault true; device = config.athenix.host.filesystem.device;
content = {
disko.devices = { type = "gpt";
disk.main = { partitions = {
type = "disk"; # EFI System Partition
device = config.athenix.host.filesystem.device; ESP = {
content = { name = "ESP";
type = "gpt"; label = "BOOT";
partitions = { size = "1G";
# EFI System Partition type = "EF00";
ESP = { content = {
name = "ESP"; type = "filesystem";
label = "BOOT"; format = "vfat";
size = "1G"; mountpoint = "/boot";
type = "EF00"; mountOptions = [ "umask=0077" ];
content = { extraArgs = [
type = "filesystem"; "-n"
format = "vfat"; "BOOT"
mountpoint = "/boot"; ];
mountOptions = [ "umask=0077" ];
extraArgs = [
"-n"
"BOOT"
];
};
}; };
};
# Swap Partition (size configurable per host) # Swap Partition (size configurable per host)
swap = lib.mkIf config.athenix.host.filesystem.useSwap { swap = lib.mkIf config.athenix.host.filesystem.useSwap {
name = "swap"; name = "swap";
label = "swap"; label = "swap";
size = config.athenix.host.filesystem.swapSize; size = config.athenix.host.filesystem.swapSize;
content = { content = {
type = "swap"; type = "swap";
};
}; };
};
# Root Partition (takes remaining space) # Root Partition (takes remaining space)
root = { root = {
name = "root"; name = "root";
label = "root"; label = "root";
size = "100%"; size = "100%";
content = { content = {
type = "filesystem"; type = "filesystem";
format = "ext4"; format = "ext4";
mountpoint = "/"; mountpoint = "/";
extraArgs = [ extraArgs = [
"-L" "-L"
"ROOT" "ROOT"
]; ];
};
}; };
}; };
}; };
}; };
}; };
};
# Bootloader Configuration # Bootloader Configuration
boot = { boot = {
loader.systemd-boot.enable = true; loader.systemd-boot.enable = true;
loader.efi.canTouchEfiVariables = true; loader.efi.canTouchEfiVariables = true;
plymouth.enable = true; plymouth.enable = true;
# Enable "Silent boot" # Enable "Silent boot"
consoleLogLevel = 3; consoleLogLevel = 3;
initrd.verbose = false; initrd.verbose = false;
# Hide the OS choice for bootloaders. # Hide the OS choice for bootloaders.
# It's still possible to open the bootloader list by pressing any key # 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 # It will just not appear on screen unless a key is pressed
loader.timeout = lib.mkDefault 0; loader.timeout = lib.mkDefault 0;
}; };
# Set your time zone. # Set your time zone.
time.timeZone = "America/New_York"; time.timeZone = "America/New_York";
# Select internationalisation properties. # Select internationalisation properties.
i18n.defaultLocale = "en_US.UTF-8"; i18n.defaultLocale = "en_US.UTF-8";
i18n.extraLocaleSettings = { i18n.extraLocaleSettings = {
LC_ADDRESS = "en_US.UTF-8"; LC_ADDRESS = "en_US.UTF-8";
LC_IDENTIFICATION = "en_US.UTF-8"; LC_IDENTIFICATION = "en_US.UTF-8";
LC_MEASUREMENT = "en_US.UTF-8"; LC_MEASUREMENT = "en_US.UTF-8";
LC_MONETARY = "en_US.UTF-8"; LC_MONETARY = "en_US.UTF-8";
LC_NAME = "en_US.UTF-8"; LC_NAME = "en_US.UTF-8";
LC_NUMERIC = "en_US.UTF-8"; LC_NUMERIC = "en_US.UTF-8";
LC_PAPER = "en_US.UTF-8"; LC_PAPER = "en_US.UTF-8";
LC_TELEPHONE = "en_US.UTF-8"; LC_TELEPHONE = "en_US.UTF-8";
LC_TIME = "en_US.UTF-8"; LC_TIME = "en_US.UTF-8";
}; };
systemd.sleep.extraConfig = '' systemd.sleep.extraConfig = ''
SuspendState=freeze SuspendState=freeze
HibernateDelaySec=2h HibernateDelaySec=2h
''; '';
};
system.stateVersion = "25.11"; # Did you read the comment?
}
];
} }

View File

@@ -28,20 +28,79 @@
inputs.disko.nixosModules.disko 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 = [ system.gc = {
"nix-command" enable = lib.mkOption {
"flakes" 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 host.buildMethods = lib.mkOption {
nix.gc = lib.mkIf config.athenix.system.gc.enable { type = lib.types.listOf lib.types.str;
automatic = true; default = [ "installer-iso" ];
dates = config.athenix.system.gc.frequency; description = ''
options = "--delete-older-than ${toString config.athenix.system.gc.retentionDays}d"; 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 config = lib.mkMerge [
nix.optimise.automatic = config.athenix.system.gc.optimise; # 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;
}
];
} }

View File

@@ -132,6 +132,7 @@ let
allModules = allModules =
userNixosModules userNixosModules
++ [ ++ [
(import ./common.nix { inherit inputs; })
typeModule typeModule
overrideModule overrideModule
{ networking.hostName = hostName; } { networking.hostName = hostName; }

View File

@@ -13,7 +13,6 @@
}: }:
{ {
imports = [ imports = [
(import ../common.nix { inherit inputs; })
(modulesPath + "/installer/scan/not-detected.nix") (modulesPath + "/installer/scan/not-detected.nix")
]; ];

View File

@@ -14,7 +14,6 @@
}: }:
{ {
imports = [ imports = [
(import ../common.nix { inherit inputs; })
(modulesPath + "/installer/scan/not-detected.nix") (modulesPath + "/installer/scan/not-detected.nix")
]; ];

View File

@@ -13,7 +13,6 @@
}: }:
{ {
imports = [ imports = [
(import ../common.nix { inherit inputs; })
(modulesPath + "/installer/scan/not-detected.nix") (modulesPath + "/installer/scan/not-detected.nix")
]; ];

View File

@@ -13,7 +13,6 @@
}: }:
{ {
imports = [ imports = [
(import ../common.nix { inherit inputs; })
inputs.vscode-server.nixosModules.default inputs.vscode-server.nixosModules.default
"${modulesPath}/virtualisation/proxmox-lxc.nix" "${modulesPath}/virtualisation/proxmox-lxc.nix"
]; ];

View File

@@ -22,7 +22,6 @@ let
in in
{ {
imports = [ imports = [
(import ../common.nix { inherit inputs; })
(modulesPath + "/installer/scan/not-detected.nix") (modulesPath + "/installer/scan/not-detected.nix")
inputs.nixos-hardware.nixosModules.microsoft-surface-go inputs.nixos-hardware.nixosModules.microsoft-surface-go
]; ];

View File

@@ -12,7 +12,6 @@
}: }:
{ {
imports = [ imports = [
(import ../common.nix { inherit inputs; })
inputs.nixos-wsl.nixosModules.default inputs.nixos-wsl.nixosModules.default
inputs.vscode-server.nixosModules.default inputs.vscode-server.nixosModules.default
]; ];

View File

@@ -13,7 +13,6 @@
}: }:
{ {
imports = [ imports = [
(import ../common.nix { inherit inputs; })
(modulesPath + "/installer/scan/not-detected.nix") (modulesPath + "/installer/scan/not-detected.nix")
]; ];