Files
dotfiles/lib/default.nix
alexion 451c02f798 Build the Skeleton and a minimal neogaia Host
Stand up the walking skeleton the rest of the laptop MVI extends and
re-verifies against: the whole neogaia Host evaluates and its system
toplevel builds (nix flake check green).

- flake.nix: hand-rolled flake (no flake-parts). Base nixos-unstable, plus
  nixpkgs-unstable and nixos-25.05 for the per-package unstable/stable
  overlays, home-manager (nixpkgs followed), and chaotic-nyx (deliberately
  not following our nixpkgs, to keep its binary cache usable). checks build
  each Host toplevel.
- lib/: trimmed helper lib — the Auto-loader (recursive .nix discovery, no
  null-placeholder hack), the host-builder, and the script-from-file helper.
  Deps inherited explicitly; no with lib.my, no nixosModules output.
- system/: shared base config — the unstable/stable overlays, the user
  option (defaults to alexion, in wheel, drives system + home-manager user
  in lockstep), flakes, git, and home-manager as a NixOS module.
- modules/example.nix: Auto-loader / Enable-convention reference Module,
  inert until enabled.
- hosts/neogaia/: minimal laptop Host — placeholder filesystems, bootloader,
  and hardware profile.
- CLAUDE.md: project agent instructions with a Gotchas section (nix on the
  CachyOS dev host, the chaotic overlay/cache behaviour, the forge CLI).
2026-07-19 07:57:21 -04:00

84 lines
2.2 KiB
Nix

{
lib,
inputs,
self,
}:
let
inherit (lib)
attrNames
filterAttrs
genAttrs
flatten
hasSuffix
mapAttrsToList
;
# --- Auto-loader ---------------------------------------------------------
# Recursively collect every `.nix` file under `dir`, returned as a flat list
# of paths suitable for a module `imports`. No null-placeholder traversal
# hack: a directory recurses, a `.nix` file is taken, anything else is skipped.
collectNixFiles =
dir:
flatten (
mapAttrsToList (
name: type:
let
path = dir + "/${name}";
in
if type == "directory" then
collectNixFiles path
else if type == "regular" && hasSuffix ".nix" name then
[ path ]
else
[ ]
) (builtins.readDir dir)
);
# --- Host-builder --------------------------------------------------------
# Build one Host: every Module is imported unconditionally (inert until its
# `enable` flag is set), alongside home-manager, chaotic, the shared base,
# and the Host's own directory.
mkHost =
{
hostName,
system ? "x86_64-linux",
}:
inputs.nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = {
inherit inputs;
my = self.lib;
};
modules =
(collectNixFiles (self + "/modules"))
++ [
inputs.home-manager.nixosModules.home-manager
inputs.chaotic.nixosModules.default
(self + "/system")
(self + "/hosts/${hostName}")
{ networking.hostName = hostName; }
];
};
# Discover every Host (a subdirectory of `hostsDir`) and build each one.
mkHosts =
hostsDir:
let
hostNames = attrNames (filterAttrs (_name: type: type == "directory") (builtins.readDir hostsDir));
in
genAttrs hostNames (hostName: mkHost { inherit hostName; });
# --- Script-from-file helper --------------------------------------------
# Turn a standalone script file into a package on PATH, keeping the script
# itself editable as a real file rather than an inlined heredoc.
scriptFromFile = pkgs: name: path: pkgs.writeShellScriptBin name (builtins.readFile path);
in
{
inherit
collectNixFiles
mkHost
mkHosts
scriptFromFile
;
}