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 # Expose artifacts to all systems, but they are always built for x86_64-linux
packages = forAllSystems (_: artifacts); 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. # the target device and swap size.
{ {
options.ugaif.host = { options.ugaif = {
host = {
filesystem = { filesystem = {
device = lib.mkOption { device = lib.mkOption {
type = lib.types.str; 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 = { config = {
# Enable Disko for declarative partitioning # Enable Disko for declarative partitioning
disko.enableConfig = true; disko.enableConfig = lib.mkDefault true;
disko.devices = { disko.devices = {
disk.main = { 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 let
nixpkgs = inputs.nixpkgs; nixpkgs = inputs.nixpkgs;
lib = nixpkgs.lib; 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 # Helper to create a single NixOS system configuration
mkHost = mkHost =
{ {
@@ -72,8 +40,7 @@ let
) accounts; ) accounts;
allModules = allModules =
commonModules userFlakeModules
++ userFlakeModules
++ extraModules ++ extraModules
++ [ ++ [
{ networking.hostName = hostName; } { networking.hostName = hostName; }
@@ -164,7 +131,7 @@ let
typeFile = ./types + "/${type}.nix"; typeFile = ./types + "/${type}.nix";
modules = modules =
if builtins.pathExists typeFile then if builtins.pathExists typeFile then
import typeFile { inherit inputs; } [ (import typeFile { inherit inputs; }) ]
else else
throw "Host type '${type}' not found in hosts/types/"; throw "Host type '${type}' not found in hosts/types/";
in in

View File

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

View File

@@ -1,6 +1,4 @@
{ inputs, ... }: { inputs, ... }:
[
(
{ {
config, config,
lib, lib,
@@ -10,7 +8,10 @@
{ {
# This host type is for ephemeral, diskless systems (e.g. kiosks, netboot clients). # 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. # 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 = [ boot.initrd.availableKernelModules = [
"xhci_pci" "xhci_pci"
@@ -54,10 +55,7 @@
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}
)
{
ugaif.sw.enable = true; ugaif.sw.enable = true;
ugaif.sw.type = "stateless-kiosk"; ugaif.sw.type = lib.mkDefault "stateless-kiosk";
} }
]

View File

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

View File

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

View File

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

View File

@@ -1,10 +1,16 @@
{ inputs, ... }: { inputs, ... }:
[ {
lib,
config,
...
}:
{
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
( ];
{ lib, config, ... }:
{
options.ugaif.host.wsl.user = lib.mkOption { options.ugaif.host.wsl.user = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = "engr-ugaif"; default = "engr-ugaif";
@@ -17,7 +23,7 @@
# Enable the headless software profile # Enable the headless software profile
ugaif.sw.enable = true; 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 # Fix for VS Code Server in WSL if needed, though vscode-server input exists
services.vscode-server.enable = true; services.vscode-server.enable = true;
@@ -35,5 +41,3 @@
ugaif.host.filesystem.swapSize = "0G"; 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; };
}