refactor: Make more modular and do some refactoring

This commit is contained in:
UGA Innovation Factory
2025-12-15 17:07:31 -05:00
committed by Hunter Halloran
parent 205f03337a
commit 01af38a5b9
11 changed files with 393 additions and 337 deletions

View File

@@ -91,5 +91,8 @@
# Expose artifacts to all systems, but they are always built for x86_64-linux
packages = forAllSystems (_: artifacts);
# Expose host type modules for external use
nixosModules = import ./installer/modules.nix { inherit inputs; };
};
}

View File

@@ -12,7 +12,8 @@
# the target device and swap size.
{
options.ugaif.host = {
options.ugaif = {
host = {
filesystem = {
device = lib.mkOption {
type = lib.types.str;
@@ -38,9 +39,33 @@
};
};
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 = {
# Enable Disko for declarative partitioning
disko.enableConfig = true;
disko.enableConfig = lib.mkDefault true;
disko.devices = {
disk.main = {

47
hosts/common.nix Normal file
View File

@@ -0,0 +1,47 @@
# ============================================================================
# Common Modules
# ============================================================================
# This module contains all the common configuration shared by all host types.
# It includes:
# - Boot and user configuration
# - Software configurations
# - User management (users.nix)
# - Home Manager integration
# - Secret management (agenix)
# - Disk partitioning (disko)
# - System-wide Nix settings (experimental features, garbage collection)
{ inputs }:
{
config,
lib,
...
}:
{
imports = [
./boot.nix
./user-config.nix
../sw
../users.nix
inputs.home-manager.nixosModules.home-manager
inputs.agenix.nixosModules.default
inputs.disko.nixosModules.disko
];
system.stateVersion = "25.11";
nix.settings.experimental-features = [
"nix-command"
"flakes"
];
# Automatic Garbage Collection
nix.gc = lib.mkIf config.ugaif.system.gc.enable {
automatic = true;
dates = config.ugaif.system.gc.frequency;
options = "--delete-older-than ${toString config.ugaif.system.gc.retentionDays}d";
};
# Optimize storage
nix.optimise.automatic = config.ugaif.system.gc.optimise;
}

View File

@@ -16,38 +16,6 @@
let
nixpkgs = inputs.nixpkgs;
lib = nixpkgs.lib;
home-manager = inputs.home-manager;
agenix = inputs.agenix;
disko = inputs.disko;
# Modules shared by all hosts
commonModules = [
./boot.nix
./user-config.nix
../users.nix
../sw
home-manager.nixosModules.home-manager
agenix.nixosModules.default
disko.nixosModules.disko
{
system.stateVersion = "25.11";
nix.settings.experimental-features = [
"nix-command"
"flakes"
];
# Automatic Garbage Collection
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 30d";
};
# Optimize storage
nix.optimise.automatic = true;
}
];
# Helper to create a single NixOS system configuration
mkHost =
{
@@ -72,8 +40,7 @@ let
) accounts;
allModules =
commonModules
++ userFlakeModules
userFlakeModules
++ extraModules
++ [
{ networking.hostName = hostName; }
@@ -164,7 +131,7 @@ let
typeFile = ./types + "/${type}.nix";
modules =
if builtins.pathExists typeFile then
import typeFile { inherit inputs; }
[ (import typeFile { inherit inputs; }) ]
else
throw "Host type '${type}' not found in hosts/types/";
in

View File

@@ -1,14 +1,15 @@
{ inputs, ... }:
[
(
{
{
config,
lib,
modulesPath,
...
}:
{
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
}:
{
imports = [
(import ../common.nix { inherit inputs; })
(modulesPath + "/installer/scan/not-detected.nix")
];
boot.initrd.availableKernelModules = [
"xhci_pci"
@@ -34,10 +35,7 @@
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}
)
{
ugaif.sw.enable = true;
ugaif.sw.type = "desktop";
}
]
ugaif.sw.type = lib.mkDefault "desktop";
}

View File

@@ -1,16 +1,17 @@
{ inputs, ... }:
[
(
{
{
config,
lib,
modulesPath,
...
}:
{
}:
{
# This host type is for ephemeral, diskless systems (e.g. kiosks, netboot clients).
# It runs entirely from RAM and does not persist state across reboots.
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
imports = [
(import ../common.nix { inherit inputs; })
(modulesPath + "/installer/scan/not-detected.nix")
];
boot.initrd.availableKernelModules = [
"xhci_pci"
@@ -54,10 +55,7 @@
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}
)
{
ugaif.sw.enable = true;
ugaif.sw.type = "stateless-kiosk";
}
]
ugaif.sw.type = lib.mkDefault "stateless-kiosk";
}

View File

@@ -1,14 +1,15 @@
{ inputs, ... }:
[
(
{
{
config,
lib,
modulesPath,
...
}:
{
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
}:
{
imports = [
(import ../common.nix { inherit inputs; })
(modulesPath + "/installer/scan/not-detected.nix")
];
boot.initrd.availableKernelModules = [
"xhci_pci"
@@ -48,10 +49,7 @@
HandleLidSwitchDocked = "ignore";
};
};
}
)
{
ugaif.sw.enable = true;
ugaif.sw.type = "desktop";
}
]
ugaif.sw.type = lib.mkDefault "desktop";
}

View File

@@ -1,14 +1,17 @@
{ inputs, ... }:
[
inputs.vscode-server.nixosModules.default
(
{
{
config,
lib,
modulesPath,
...
}:
{
}:
{
imports = [
(import ../common.nix { inherit inputs; })
inputs.vscode-server.nixosModules.default
"${modulesPath}/virtualisation/proxmox-lxc.nix"
];
nix.settings.trusted-users = [
"root"
"engr-ugaif"
@@ -17,9 +20,7 @@
"nix-command"
"flakes"
];
imports = [
"${modulesPath}/virtualisation/proxmox-lxc.nix"
];
boot.isContainer = true;
boot.loader.systemd-boot.enable = lib.mkForce false;
disko.enableConfig = lib.mkForce false;
@@ -39,10 +40,7 @@
"lxc"
"proxmox"
];
}
)
{
ugaif.sw.enable = true;
ugaif.sw.type = "headless";
}
]
ugaif.sw.type = lib.mkDefault "headless";
}

View File

@@ -1,22 +1,24 @@
{ inputs, ... }:
[
(
{
{
config,
lib,
pkgs,
modulesPath,
...
}:
let
}:
let
refSystem = inputs.nixpkgs-old-kernel.lib.nixosSystem {
system = pkgs.stdenv.hostPlatform.system;
modules = [ inputs.nixos-hardware.nixosModules.microsoft-surface-go ];
};
refKernelPackages = refSystem.config.boot.kernelPackages;
in
{
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
in
{
imports = [
(import ../common.nix { inherit inputs; })
(modulesPath + "/installer/scan/not-detected.nix")
inputs.nixos-hardware.nixosModules.microsoft-surface-go
];
boot.initrd.availableKernelModules = [
"xhci_pci"
@@ -49,11 +51,7 @@
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}
)
inputs.nixos-hardware.nixosModules.microsoft-surface-go
{
ugaif.sw.enable = true;
ugaif.sw.type = "tablet-kiosk";
}
]
ugaif.sw.type = lib.mkDefault "tablet-kiosk";
}

View File

@@ -1,10 +1,16 @@
{ inputs, ... }:
[
{
lib,
config,
...
}:
{
imports = [
(import ../common.nix { inherit inputs; })
inputs.nixos-wsl.nixosModules.default
inputs.vscode-server.nixosModules.default
(
{ lib, config, ... }:
{
];
options.ugaif.host.wsl.user = lib.mkOption {
type = lib.types.str;
default = "engr-ugaif";
@@ -17,7 +23,7 @@
# Enable the headless software profile
ugaif.sw.enable = true;
ugaif.sw.type = "headless";
ugaif.sw.type = lib.mkDefault "headless";
# Fix for VS Code Server in WSL if needed, though vscode-server input exists
services.vscode-server.enable = true;
@@ -34,6 +40,4 @@
ugaif.host.filesystem.device = "/dev/null";
ugaif.host.filesystem.swapSize = "0G";
};
}
)
]
}

20
installer/modules.nix Normal file
View File

@@ -0,0 +1,20 @@
# ============================================================================
# Host Type Modules Export
# ============================================================================
# This file exposes each host type as a reusable NixOS module that can be
# imported by external flakes or configurations.
#
# Usage in another flake:
# inputs.nixos-systems.nixosModules.nix-desktop
# inputs.nixos-systems.nixosModules.nix-laptop
# etc.
{ inputs }:
{
nix-desktop = import ../hosts/types/nix-desktop.nix { inherit inputs; };
nix-laptop = import ../hosts/types/nix-laptop.nix { inherit inputs; };
nix-surface = import ../hosts/types/nix-surface.nix { inherit inputs; };
nix-lxc = import ../hosts/types/nix-lxc.nix { inherit inputs; };
nix-wsl = import ../hosts/types/nix-wsl.nix { inherit inputs; };
nix-ephemeral = import ../hosts/types/nix-ephemeral.nix { inherit inputs; };
}