diff --git a/AGENTS.md b/AGENTS.md index 9281194..85f0183 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -66,7 +66,7 @@ One flake builds every machine I own. - Guest modules are host-agnostic wiring, while host files own deployment-specific service configuration such as served volumes and host paths. For example, `guests/copyparty.nix` should expose options and translate them into guest mounts/service settings, while `hosts/pikachu/default.nix` chooses `/inbox`, `/media`, and their backing paths. Guest addresses and routes are host-level configuration because a guest module can be used on multiple hosts. -- `self.lib.registry.collect { hosts = self.nixosConfigurations; }` reads only top-level host `config.registry` declarations. +- The registry collector reads only top-level host `config.registry` declarations. Registry declarations inside guest interiors live under `config.containers..config.registry`. The collected registry does not include those guest-interior declarations. Publish guest values from host-side code, or extend the collector to recurse into guests. diff --git a/flake.nix b/flake.nix index f5e8259..11ed1f0 100644 --- a/flake.nix +++ b/flake.nix @@ -76,14 +76,11 @@ { self, nixpkgs, ... }@inputs: let inherit (nixpkgs) lib; - my = import ./lib { inherit lib inputs self; }; + flake = import ./flake { inherit lib inputs self; }; in { - # Helper functions for discovering and building hosts. - lib = my; - # Every host under hosts/ is discovered and built. - nixosConfigurations = my.mkHosts (self + "/hosts"); + nixosConfigurations = flake.mkHosts (self + "/hosts"); # A project shell for agent-local resources that should travel with this # checkout rather than the operator's global profile. diff --git a/lib/default.nix b/flake/default.nix similarity index 62% rename from lib/default.nix rename to flake/default.nix index 7826de4..7127139 100644 --- a/lib/default.nix +++ b/flake/default.nix @@ -4,28 +4,19 @@ self, }: let - inherit (lib) - attrNames - filterAttrs - genAttrs - flatten - hasSuffix - mapAttrsToList - ; - - registry = import ./registry.nix { inherit lib self; }; + registryAssembly = import ./registry.nix { inherit lib self; }; collectNixFiles = dir: - flatten ( - mapAttrsToList ( + lib.flatten ( + lib.mapAttrsToList ( name: type: let path = dir + "/${name}"; in if type == "directory" then collectNixFiles path - else if type == "regular" && hasSuffix ".nix" name then + else if type == "regular" && lib.hasSuffix ".nix" name then [ path ] else [ ] @@ -35,14 +26,28 @@ let moduleFiles = collectNixFiles (self + "/modules"); guestFiles = collectNixFiles (self + "/guests"); + collectedRegistry = registryAssembly.collect { hosts = self.nixosConfigurations; }; + specialArgs = { - inherit inputs self; - my = self.lib; - registry = self.lib.registry.collect { hosts = self.nixosConfigurations; }; + inherit + dotfiles + inputs + self + ; + registry = collectedRegistry; }; bridgeName = id: "br-vlan${toString id}"; + dotfiles = { + inherit (guests) guest; + + lib = { + inherit bridgeName; + inherit (guests) deriveMac; + }; + }; + guests = import ./guests.nix { inherit inputs @@ -51,7 +56,7 @@ let specialArgs bridgeName moduleFiles - registry + registryAssembly ; }; @@ -70,7 +75,7 @@ let inputs.disko.nixosModules.disko inputs.sops-nix.nixosModules.sops inputs.stylix.nixosModules.stylix - registry.module + registryAssembly.module (self + "/hosts/${hostName}") { networking.hostName = hostName; @@ -82,19 +87,10 @@ let mkHosts = hostsDir: let - hostNames = attrNames (filterAttrs (_name: type: type == "directory") (builtins.readDir hostsDir)); + hostNames = lib.attrNames (lib.filterAttrs (_name: type: type == "directory") (builtins.readDir hostsDir)); in - genAttrs hostNames (hostName: mkHost { inherit hostName; }); + lib.genAttrs hostNames (hostName: mkHost { inherit hostName; }); in { - inherit - collectNixFiles - mkHost - mkHosts - bridgeName - registry - ; - - inherit (guests) deriveMac guest; - + inherit mkHosts; } diff --git a/lib/guests.nix b/flake/guests.nix similarity index 99% rename from lib/guests.nix rename to flake/guests.nix index 6822f3b..33ab552 100644 --- a/lib/guests.nix +++ b/flake/guests.nix @@ -5,7 +5,7 @@ specialArgs, bridgeName, moduleFiles, - registry, + registryAssembly, }: let inherit (lib) escapeShellArg mapAttrsToList; @@ -136,7 +136,7 @@ let enable = lib.mkEnableOption "a reverse-proxy route for this guest"; route = lib.mkOption { - type = self.lib.registry.definitions.route.type; + type = registryAssembly.definitions.route.type; description = "Route registry entry published for this guest."; }; }; @@ -351,7 +351,7 @@ let imports = moduleFiles ++ [ - registry.module + registryAssembly.module inputs.sops-nix.nixosModules.sops inputs.stylix.nixosModules.stylix { diff --git a/lib/registry.nix b/flake/registry.nix similarity index 100% rename from lib/registry.nix rename to flake/registry.nix diff --git a/guests/actualbudget.nix b/guests/actualbudget.nix index f22edd2..c4f5aac 100644 --- a/guests/actualbudget.nix +++ b/guests/actualbudget.nix @@ -1,7 +1,7 @@ { config, lib, - my, + dotfiles, ... }: let @@ -10,7 +10,7 @@ let in { imports = [ - (my.guest { + (dotfiles.guest { name = "actualbudget"; interior = { modules.services.actualbudget = { diff --git a/guests/copyparty.nix b/guests/copyparty.nix index ee2148f..161cdc8 100644 --- a/guests/copyparty.nix +++ b/guests/copyparty.nix @@ -1,7 +1,7 @@ { config, lib, - my, + dotfiles, ... }: let @@ -35,7 +35,7 @@ let in { imports = [ - (my.guest { + (dotfiles.guest { name = "copyparty"; interior = { modules.services.copyparty = { diff --git a/guests/nesting-sample.nix b/guests/nesting-sample.nix index 5941932..12a1e27 100644 --- a/guests/nesting-sample.nix +++ b/guests/nesting-sample.nix @@ -1,7 +1,7 @@ -args@{ my, ... }: +args@{ dotfiles, ... }: # A sample guest whose interior runs an OCI container on Podman. # The image is pulled at runtime, so the guest builds with no build-time fetch. -my.guest { +dotfiles.guest { name = "nesting-sample"; interior = { virtualisation.oci-containers.containers.hello = { diff --git a/guests/reverse-proxy.nix b/guests/reverse-proxy.nix index c8871aa..090081a 100644 --- a/guests/reverse-proxy.nix +++ b/guests/reverse-proxy.nix @@ -1,7 +1,7 @@ { config, lib, - my, + dotfiles, ... }: let @@ -9,7 +9,7 @@ let in { imports = [ - (my.guest { + (dotfiles.guest { name = "reverse-proxy"; interior = { modules.services.reverse-proxy.enable = true; diff --git a/guests/sample.nix b/guests/sample.nix index 293621a..1e0fab9 100644 --- a/guests/sample.nix +++ b/guests/sample.nix @@ -1,5 +1,5 @@ -args@{ my, ... }: +args@{ dotfiles, ... }: # The tracer-bullet guest: the thinnest complete path from discovery to a # running nested container. Its interior is just the guest-base — the baseline # toolset and SSH access — so it proves the concept without carrying a service. -my.guest { name = "sample"; } args +dotfiles.guest { name = "sample"; } args diff --git a/modules/default.nix b/modules/default.nix index 1c1310a..e4cba84 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,6 +1,7 @@ { config, lib, + dotfiles, pkgs, inputs, ... @@ -63,8 +64,7 @@ in useGlobalPkgs = true; useUserPackages = true; extraSpecialArgs = { - inherit inputs; - my = inputs.self.lib; + inherit dotfiles inputs; }; users.${user.name} = { home.username = user.name; diff --git a/modules/network/vlans.nix b/modules/network/vlans.nix index cc2c929..dd2fb9a 100644 --- a/modules/network/vlans.nix +++ b/modules/network/vlans.nix @@ -1,14 +1,14 @@ { config, lib, - my, + dotfiles, ... }: # The host networking foundation: per-VLAN bridges over a tagged trunk. let cfg = config.modules.network.vlans; - inherit (my) bridgeName; + inherit (dotfiles.lib) bridgeName; vlanName = id: "${cfg.trunk}.${toString id}"; in