refactor(flake): move assembly code out of lib
This commit is contained in:
@@ -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.<guest>.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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user