From 140648cd8fe4367cf098686d371517300003ae0b Mon Sep 17 00:00:00 2001 From: UGA Innovation Factory Date: Mon, 15 Dec 2025 15:57:56 -0500 Subject: [PATCH] run nix fmt --- flake.nix | 2 +- hosts/default.nix | 2 +- hosts/types/nix-ephemeral.nix | 13 +- hosts/types/nix-lxc.nix | 5 +- hosts/types/nix-wsl.nix | 57 ++++----- installer/artifacts.nix | 175 ++++++++++++++++++--------- installer/auto-install.nix | 17 ++- sw/stateless-kiosk/default.nix | 28 ++++- sw/stateless-kiosk/kiosk-browser.nix | 8 +- sw/stateless-kiosk/mac-hostmap.nix | 13 +- sw/stateless-kiosk/net.nix | 8 +- sw/stateless-kiosk/programs.nix | 7 +- sw/stateless-kiosk/services.nix | 7 +- sw/updater.nix | 9 +- 14 files changed, 236 insertions(+), 115 deletions(-) diff --git a/flake.nix b/flake.nix index 15717e8..b5a2325 100644 --- a/flake.nix +++ b/flake.nix @@ -85,7 +85,7 @@ { # Formatter for 'nix fmt' formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); - + # Generate NixOS configurations from hosts/default.nix nixosConfigurations = hosts.nixosConfigurations; diff --git a/hosts/default.nix b/hosts/default.nix index bde895a..c89a09e 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -70,7 +70,7 @@ let else { } ) accounts; - + allModules = commonModules ++ userFlakeModules diff --git a/hosts/types/nix-ephemeral.nix b/hosts/types/nix-ephemeral.nix index 470b6a2..208dec7 100644 --- a/hosts/types/nix-ephemeral.nix +++ b/hosts/types/nix-ephemeral.nix @@ -33,8 +33,11 @@ # Ephemeral setup: No swap, no disk ugaif.host.filesystem.swapSize = lib.mkForce "0G"; ugaif.host.filesystem.device = lib.mkForce "/dev/null"; # Dummy device - ugaif.host.buildMethods = lib.mkDefault [ "iso" "ipxe" ]; - + ugaif.host.buildMethods = lib.mkDefault [ + "iso" + "ipxe" + ]; + # Disable Disko config since we are running from RAM/ISO disko.enableConfig = lib.mkForce false; @@ -42,7 +45,11 @@ fileSystems."/" = { device = "none"; fsType = "tmpfs"; - options = [ "defaults" "size=50%" "mode=755" ]; + options = [ + "defaults" + "size=50%" + "mode=755" + ]; }; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; diff --git a/hosts/types/nix-lxc.nix b/hosts/types/nix-lxc.nix index 3acfd78..c9ddb28 100644 --- a/hosts/types/nix-lxc.nix +++ b/hosts/types/nix-lxc.nix @@ -35,7 +35,10 @@ ]; services.vscode-server.enable = true; system.stateVersion = "25.11"; - ugaif.host.buildMethods = lib.mkDefault [ "lxc" "proxmox" ]; + ugaif.host.buildMethods = lib.mkDefault [ + "lxc" + "proxmox" + ]; } ) { diff --git a/hosts/types/nix-wsl.nix b/hosts/types/nix-wsl.nix index 47a0c1a..3db7380 100644 --- a/hosts/types/nix-wsl.nix +++ b/hosts/types/nix-wsl.nix @@ -2,35 +2,38 @@ [ 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"; - description = "The default user to log in as in WSL."; - }; + ( + { lib, config, ... }: + { + options.ugaif.host.wsl.user = lib.mkOption { + type = lib.types.str; + default = "engr-ugaif"; + description = "The default user to log in as in WSL."; + }; - config = { - wsl.enable = true; - wsl.defaultUser = config.ugaif.host.wsl.user; - - # Enable the headless software profile - ugaif.sw.enable = true; - ugaif.sw.type = "headless"; + config = { + wsl.enable = true; + wsl.defaultUser = config.ugaif.host.wsl.user; - # Fix for VS Code Server in WSL if needed, though vscode-server input exists - services.vscode-server.enable = true; + # Enable the headless software profile + ugaif.sw.enable = true; + ugaif.sw.type = "headless"; - # Disable Disko and Bootloader for WSL - disko.enableConfig = lib.mkForce false; - boot.loader.systemd-boot.enable = lib.mkForce false; - boot.loader.grub.enable = lib.mkForce false; + # Fix for VS Code Server in WSL if needed, though vscode-server input exists + services.vscode-server.enable = true; - # Disable networking for wsl (it manages its own networking) - systemd.network.enable = lib.mkForce false; - - # Provide dummy values for required options from boot.nix - ugaif.host.filesystem.device = "/dev/null"; - ugaif.host.filesystem.swapSize = "0G"; - }; - }) + # Disable Disko and Bootloader for WSL + disko.enableConfig = lib.mkForce false; + boot.loader.systemd-boot.enable = lib.mkForce false; + boot.loader.grub.enable = lib.mkForce false; + + # Disable networking for wsl (it manages its own networking) + systemd.network.enable = lib.mkForce false; + + # Provide dummy values for required options from boot.nix + ugaif.host.filesystem.device = "/dev/null"; + ugaif.host.filesystem.swapSize = "0G"; + }; + } + ) ] diff --git a/installer/artifacts.nix b/installer/artifacts.nix index b682bb8..beea1b4 100644 --- a/installer/artifacts.nix +++ b/installer/artifacts.nix @@ -1,4 +1,9 @@ -{ inputs, hosts, self, system }: +{ + inputs, + hosts, + self, + system, +}: # This file defines the logic for generating various build artifacts (ISOs, Netboot, LXC, etc.) # It exports a set of packages that can be built using `nix build .#` let @@ -9,7 +14,8 @@ let # Creates a self-installing ISO for a specific host configuration # This ISO will automatically partition the disk (using disko) and install the system - mkInstaller = hostName: + mkInstaller = + hostName: let targetConfig = self.nixosConfigurations.${hostName}.config; targetSystem = targetConfig.system.build.toplevel; @@ -18,7 +24,12 @@ let nixpkgs.lib.nixosSystem { inherit system; specialArgs = { - inherit inputs hostName targetSystem diskoScript; + inherit + inputs + hostName + targetSystem + diskoScript + ; hostPlatform = system; }; modules = [ @@ -29,7 +40,8 @@ let }; # Uses nixos-generators to create artifacts like LXC containers, Proxmox VMA, or Live ISOs - mkGenerator = hostName: format: + mkGenerator = + hostName: format: nixos-generators.nixosGenerate { inherit system; specialArgs = { inherit inputs; }; @@ -44,7 +56,8 @@ let # Creates Netboot (iPXE) artifacts using the native NixOS netboot module # Returns a system configuration that includes the netboot module - mkNetboot = hostName: + mkNetboot = + hostName: nixpkgs.lib.nixosSystem { inherit system; specialArgs = { inherit inputs; }; @@ -60,66 +73,110 @@ let hostNames = builtins.attrNames hosts.nixosConfigurations; # Generate installer ISOs for hosts that have "installer-iso" in their buildMethods - installerPackages = lib.listToAttrs (lib.concatMap (name: - let cfg = hosts.nixosConfigurations.${name}; in - if lib.elem "installer-iso" cfg.config.ugaif.host.buildMethods then [{ - name = "installer-iso-${name}"; - value = (mkInstaller name).config.system.build.isoImage; - }] else [] - ) hostNames); + installerPackages = lib.listToAttrs ( + lib.concatMap ( + name: + let + cfg = hosts.nixosConfigurations.${name}; + in + if lib.elem "installer-iso" cfg.config.ugaif.host.buildMethods then + [ + { + name = "installer-iso-${name}"; + value = (mkInstaller name).config.system.build.isoImage; + } + ] + else + [ ] + ) hostNames + ); # Generate Live ISOs for hosts that have "iso" in their buildMethods - isoPackages = lib.listToAttrs (lib.concatMap (name: - let cfg = hosts.nixosConfigurations.${name}; in - if lib.elem "iso" cfg.config.ugaif.host.buildMethods then [{ - name = "iso-${name}"; - value = mkGenerator name "iso"; - }] else [] - ) hostNames); + isoPackages = lib.listToAttrs ( + lib.concatMap ( + name: + let + cfg = hosts.nixosConfigurations.${name}; + in + if lib.elem "iso" cfg.config.ugaif.host.buildMethods then + [ + { + name = "iso-${name}"; + value = mkGenerator name "iso"; + } + ] + else + [ ] + ) hostNames + ); # Generate iPXE artifacts (kernel, initrd, script) for hosts that have "ipxe" in their buildMethods - ipxePackages = lib.listToAttrs (lib.concatMap (name: - let cfg = hosts.nixosConfigurations.${name}; in - if lib.elem "ipxe" cfg.config.ugaif.host.buildMethods then [{ - name = "ipxe-${name}"; - value = - let - build = (mkNetboot name).config.system.build; - in - pkgs.symlinkJoin { - name = "netboot-artifacts-${name}"; - paths = [ - build.netbootRamdisk - build.kernel - build.netbootIpxeScript - ]; - }; - }] else [] - ) hostNames); + ipxePackages = lib.listToAttrs ( + lib.concatMap ( + name: + let + cfg = hosts.nixosConfigurations.${name}; + in + if lib.elem "ipxe" cfg.config.ugaif.host.buildMethods then + [ + { + name = "ipxe-${name}"; + value = + let + build = (mkNetboot name).config.system.build; + in + pkgs.symlinkJoin { + name = "netboot-artifacts-${name}"; + paths = [ + build.netbootRamdisk + build.kernel + build.netbootIpxeScript + ]; + }; + } + ] + else + [ ] + ) hostNames + ); # Generate LXC tarballs for hosts that have "lxc" in their buildMethods - lxcPackages = lib.listToAttrs (lib.concatMap (name: - let cfg = hosts.nixosConfigurations.${name}; in - if lib.elem "lxc" cfg.config.ugaif.host.buildMethods then [{ - name = "lxc-${name}"; - value = - if cfg.config.boot.isContainer then - cfg.config.system.build.tarball - else - mkGenerator name "lxc"; - }] else [] - ) hostNames); + lxcPackages = lib.listToAttrs ( + lib.concatMap ( + name: + let + cfg = hosts.nixosConfigurations.${name}; + in + if lib.elem "lxc" cfg.config.ugaif.host.buildMethods then + [ + { + name = "lxc-${name}"; + value = + if cfg.config.boot.isContainer then cfg.config.system.build.tarball else mkGenerator name "lxc"; + } + ] + else + [ ] + ) hostNames + ); - proxmoxPackages = lib.listToAttrs (lib.concatMap (name: - let cfg = hosts.nixosConfigurations.${name}; in - if lib.elem "proxmox" cfg.config.ugaif.host.buildMethods then [{ - name = "proxmox-${name}"; - value = - if cfg.config.boot.isContainer then - cfg.config.system.build.tarball - else - mkGenerator name "proxmox"; - }] else [] - ) hostNames); + proxmoxPackages = lib.listToAttrs ( + lib.concatMap ( + name: + let + cfg = hosts.nixosConfigurations.${name}; + in + if lib.elem "proxmox" cfg.config.ugaif.host.buildMethods then + [ + { + name = "proxmox-${name}"; + value = + if cfg.config.boot.isContainer then cfg.config.system.build.tarball else mkGenerator name "proxmox"; + } + ] + else + [ ] + ) hostNames + ); in installerPackages // isoPackages // ipxePackages // lxcPackages // proxmoxPackages diff --git a/installer/auto-install.nix b/installer/auto-install.nix index dbcf678..0bfc6e2 100644 --- a/installer/auto-install.nix +++ b/installer/auto-install.nix @@ -1,7 +1,17 @@ # This module defines a systemd service that automatically installs NixOS to the disk. # It is intended to be used in an installation ISO. # It expects `targetSystem` (the closure to install) and `diskoScript` (the partitioning script) to be passed as arguments. -{ config, lib, pkgs, inputs, hostName, hostPlatform, targetSystem, diskoScript, ... }: +{ + config, + lib, + pkgs, + inputs, + hostName, + hostPlatform, + targetSystem, + diskoScript, + ... +}: { environment.systemPackages = [ pkgs.git @@ -14,7 +24,10 @@ systemd.services.auto-install = { description = "Automatic NixOS install for ${hostName}"; - after = [ "network-online.target" "systemd-udev-settle.service" ]; + after = [ + "network-online.target" + "systemd-udev-settle.service" + ]; wants = [ "network-online.target" ]; wantedBy = [ "multi-user.target" ]; diff --git a/sw/stateless-kiosk/default.nix b/sw/stateless-kiosk/default.nix index 4b051c2..dedfad4 100644 --- a/sw/stateless-kiosk/default.nix +++ b/sw/stateless-kiosk/default.nix @@ -9,15 +9,35 @@ }: lib.mkMerge [ (import ./kiosk-browser.nix { - inherit config lib pkgs inputs; + inherit + config + lib + pkgs + inputs + ; }) (import ./services.nix { - inherit config lib pkgs inputs; + inherit + config + lib + pkgs + inputs + ; }) (import ./net.nix { - inherit config lib pkgs inputs; + inherit + config + lib + pkgs + inputs + ; }) (import ./programs.nix { - inherit config lib pkgs inputs; + inherit + config + lib + pkgs + inputs + ; }) ] diff --git a/sw/stateless-kiosk/kiosk-browser.nix b/sw/stateless-kiosk/kiosk-browser.nix index 192c095..b1ff685 100644 --- a/sw/stateless-kiosk/kiosk-browser.nix +++ b/sw/stateless-kiosk/kiosk-browser.nix @@ -1,7 +1,11 @@ - # This module configures Chromium for kiosk mode under Sway. # It includes a startup script that determines the kiosk URL based on the machine's MAC address. -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let macCaseBuilder = (import ./mac-hostmap.nix { inherit lib; }).macCaseBuilder; diff --git a/sw/stateless-kiosk/mac-hostmap.nix b/sw/stateless-kiosk/mac-hostmap.nix index 099b37d..c0d243e 100644 --- a/sw/stateless-kiosk/mac-hostmap.nix +++ b/sw/stateless-kiosk/mac-hostmap.nix @@ -13,15 +13,16 @@ let # varName: the shell variable to assign # prefix: optional string to prepend to the value (default: "") # attrset: attribute set to use (default: hostmap) - macCaseBuilder = { - varName, - prefix ? "", - attrset ? hostmap - }: + macCaseBuilder = + { + varName, + prefix ? "", + attrset ? hostmap, + }: lib.concatStringsSep "\n" ( lib.mapAttrsToList (mac: val: " ${mac}) ${varName}=${prefix}${val} ;;") attrset ); -in +in { inherit hostmap macCaseBuilder; } diff --git a/sw/stateless-kiosk/net.nix b/sw/stateless-kiosk/net.nix index e0e9d27..f8aad34 100644 --- a/sw/stateless-kiosk/net.nix +++ b/sw/stateless-kiosk/net.nix @@ -1,5 +1,11 @@ # This module configures the network for the stateless kiosk using base networking (no systemd-networkd). -{ config, lib, pkgs, inputs, ... }: +{ + config, + lib, + pkgs, + inputs, + ... +}: { networking = { useNetworkd = false; diff --git a/sw/stateless-kiosk/programs.nix b/sw/stateless-kiosk/programs.nix index 55ffbd9..2e35552 100644 --- a/sw/stateless-kiosk/programs.nix +++ b/sw/stateless-kiosk/programs.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: { programs.sway = { enable = true; diff --git a/sw/stateless-kiosk/services.nix b/sw/stateless-kiosk/services.nix index 2416549..4bd2641 100644 --- a/sw/stateless-kiosk/services.nix +++ b/sw/stateless-kiosk/services.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let macCaseBuilder = (import ./mac-hostmap.nix { inherit lib; }).macCaseBuilder; shellCases = macCaseBuilder { diff --git a/sw/updater.nix b/sw/updater.nix index 10b9240..ba3942b 100644 --- a/sw/updater.nix +++ b/sw/updater.nix @@ -62,18 +62,15 @@ with lib; description = "System daemon to one-shot run the Nix updater from fleet flake as root"; serviceConfig = { Type = "oneshot"; - ExecStart = + ExecStart = let hosts = config.ugaif.sw.remoteBuild.hosts; builders = lib.strings.concatMapStringsSep ";" (x: x) hosts; rebuildCmd = "${pkgs.nixos-rebuild}/bin/nixos-rebuild switch --refresh"; source = "--flake github:UGA-Innovation-Factory/nixos-systems"; - remoteBuildFlags = if config.ugaif.sw.remoteBuild.enable - then - ''--builders "${builders}"'' - else ""; + remoteBuildFlags = if config.ugaif.sw.remoteBuild.enable then ''--builders "${builders}"'' else ""; in - "${rebuildCmd} ${remoteBuildFlags} --print-build-logs ${source}#${config.networking.hostName}"; + "${rebuildCmd} ${remoteBuildFlags} --print-build-logs ${source}#${config.networking.hostName}"; User = "root"; Group = "root"; TimeoutStartSec = "0";