refactor(flake): split assembly by concept

This commit is contained in:
2026-08-28 11:01:15 -04:00
parent fc834168aa
commit d0b00ada96
11 changed files with 117 additions and 81 deletions

View File

@@ -5,26 +5,11 @@
}:
let
registryAssembly = import ./registry.nix { inherit lib self; };
modules = import ./modules.nix { inherit lib; };
dotfilesLib = import ../lib { inherit lib; };
collectNixFiles =
dir:
lib.flatten (
lib.mapAttrsToList (
name: type:
let
path = dir + "/${name}";
in
if type == "directory" then
collectNixFiles path
else if type == "regular" && lib.hasSuffix ".nix" name then
[ path ]
else
[ ]
) (builtins.readDir dir)
);
moduleFiles = collectNixFiles (self + "/modules");
guestFiles = collectNixFiles (self + "/guests");
moduleFiles = modules.mkModules (self + "/modules");
guestFiles = modules.mkModules (self + "/guests");
collectedRegistry = registryAssembly.collect { hosts = self.nixosConfigurations; };
@@ -37,15 +22,10 @@ let
registry = collectedRegistry;
};
bridgeName = id: "br-vlan${toString id}";
dotfiles = {
inherit (guests) guest;
inherit (guests) mkGuest;
lib = {
inherit bridgeName;
inherit (guests) deriveMac;
};
lib = dotfilesLib;
};
guests = import ./guests.nix {
@@ -54,43 +34,24 @@ let
lib
self
specialArgs
bridgeName
moduleFiles
registryAssembly
dotfilesLib
;
};
mkHost =
{
hostName,
system ? "x86_64-linux",
}:
inputs.nixpkgs.lib.nixosSystem {
inherit system specialArgs;
modules =
moduleFiles
++ guestFiles
++ [
inputs.chaotic.nixosModules.default
inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops
inputs.stylix.nixosModules.stylix
registryAssembly.module
(self + "/hosts/${hostName}")
{
networking.hostName = hostName;
modules.host.enable = true;
}
];
};
mkHosts =
hostsDir:
let
hostNames = lib.attrNames (lib.filterAttrs (_name: type: type == "directory") (builtins.readDir hostsDir));
in
lib.genAttrs hostNames (hostName: mkHost { inherit hostName; });
hosts = import ./hosts.nix {
inherit
inputs
lib
self
specialArgs
moduleFiles
guestFiles
registryAssembly
;
};
in
{
inherit mkHosts;
inherit (hosts) mkHosts;
}