From 063336f736bd584846f1cf330eec0cb0a230e8f6 Mon Sep 17 00:00:00 2001 From: UGA Innovation Factory Date: Tue, 27 Jan 2026 16:11:36 -0500 Subject: [PATCH] refactor: Fleet and sw behind mkIf guards --- fleet/boot.nix | 86 +++++++++++++++++++++--------------- fleet/fs.nix | 110 +++++++++++++++++++++++++--------------------- sw/ghostty.nix | 10 ++++- sw/python.nix | 23 ++++++++-- sw/update-ref.nix | 17 ++++++- 5 files changed, 156 insertions(+), 90 deletions(-) diff --git a/fleet/boot.nix b/fleet/boot.nix index f79d733..34888e3 100644 --- a/fleet/boot.nix +++ b/fleet/boot.nix @@ -5,44 +5,60 @@ # - Bootloader configuration (systemd-boot with Plymouth) # - Timezone and locale settings # - Systemd sleep configuration +# +# Only applies to: +# - Linux systems (not Darwin/macOS) +# - Systems with actual boot hardware (not containers/WSL) -{ lib, ... }: { - boot = { - loader.systemd-boot.enable = lib.mkDefault true; - loader.efi.canTouchEfiVariables = lib.mkDefault true; - plymouth.enable = lib.mkDefault true; + config, + lib, + pkgs, + ... +}: - # Enable "Silent boot" - consoleLogLevel = 3; - initrd.verbose = false; +let + # Check if this is a bootable system (not container, not WSL) + isBootable = !(config.boot.isContainer or false) && (pkgs.stdenv.isLinux); +in +{ + config = lib.mkIf isBootable { + boot = { + loader.systemd-boot.enable = lib.mkDefault true; + loader.efi.canTouchEfiVariables = lib.mkDefault true; + plymouth.enable = lib.mkDefault true; - # 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; + # 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; + }; + + # Set your time zone. + time.timeZone = "America/New_York"; + + # 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"; + }; + + systemd.sleep.extraConfig = '' + SuspendState=freeze + HibernateDelaySec=2h + ''; }; - - # Set your time zone. - time.timeZone = "America/New_York"; - - # 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"; - }; - - systemd.sleep.extraConfig = '' - SuspendState=freeze - HibernateDelaySec=2h - ''; } diff --git a/fleet/fs.nix b/fleet/fs.nix index 04987ec..a689d3b 100644 --- a/fleet/fs.nix +++ b/fleet/fs.nix @@ -4,9 +4,17 @@ # This module defines: # - Disko partition layout (EFI, swap, root) # - Filesystem options (device, swap size) +# +# Only applies to systems with physical disk management needs +# (not containers, not WSL, not systems without a configured device) { config, lib, ... }: +let + cfg = config.athenix.host.filesystem; + # Only enable disk config if device is set and disko is enabled + hasDiskConfig = cfg.device != null && config.disko.enableConfig; +in { options.athenix = { host.filesystem = { @@ -49,63 +57,67 @@ }; }; - config = { - # ========== Disk Partitioning (Disko) ========== - disko.enableConfig = lib.mkDefault (config.athenix.host.filesystem.device != null); + config = lib.mkMerge [ + { + # ========== Disk Partitioning (Disko) ========== + disko.enableConfig = lib.mkDefault (cfg.device != null); + } - 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" - ]; + (lib.mkIf hasDiskConfig { + disko.devices = { + disk.main = { + type = "disk"; + device = cfg.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 cfg.useSwap { + name = "swap"; + label = "swap"; + size = cfg.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" + ]; + }; }; }; }; }; }; - }; - }; + }) + ]; } diff --git a/sw/ghostty.nix b/sw/ghostty.nix index 677d9c9..74acd76 100644 --- a/sw/ghostty.nix +++ b/sw/ghostty.nix @@ -1,4 +1,6 @@ { + config, + lib, pkgs, ... }: @@ -10,7 +12,11 @@ # It reconstructs the terminfo database from the provided definition and # adds it to the system packages. +with lib; + let + cfg = config.athenix.sw; + ghostty-terminfo = pkgs.runCommand "ghostty-terminfo" { } '' mkdir -p $out/share/terminfo cat > ghostty.info <<'EOF' @@ -99,5 +105,7 @@ let ''; in { - environment.systemPackages = [ ghostty-terminfo ]; + config = mkIf cfg.enable { + environment.systemPackages = [ ghostty-terminfo ]; + }; } diff --git a/sw/python.nix b/sw/python.nix index 42e790a..9c50bc4 100644 --- a/sw/python.nix +++ b/sw/python.nix @@ -18,10 +18,27 @@ let cfg = config.athenix.sw.python; in { - options.athenix.sw.python = { - enable = mkEnableOption "Python development tools (pixi, uv)" // { - default = true; + options.athenix.sw.python = lib.mkOption { + type = lib.types.submodule { + options = { + enable = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Enable Python development tools (pixi, uv). + + Provides: + - pixi: Fast, cross-platform package manager for Python + - uv: Extremely fast Python package installer and resolver + + These tools manage project-based dependencies rather than global + Python packages, avoiding conflicts and improving reproducibility. + ''; + }; + }; }; + default = { }; + description = "Python development environment configuration."; }; config = mkIf cfg.enable { diff --git a/sw/update-ref.nix b/sw/update-ref.nix index 8cd0770..94a2287 100644 --- a/sw/update-ref.nix +++ b/sw/update-ref.nix @@ -1,6 +1,18 @@ -{ pkgs, ... }: { - environment.systemPackages = with pkgs; [ + config, + lib, + pkgs, + ... +}: + +with lib; + +let + cfg = config.athenix.sw; +in +{ + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ python3 git (pkgs.writeShellScriptBin "update-ref" '' @@ -508,4 +520,5 @@ printf " rev = %s\n" "$CUR_REV" >&2 '') ]; + }; }