97 lines
1.9 KiB
Nix
97 lines
1.9 KiB
Nix
{
|
|
lib,
|
|
inputs,
|
|
self,
|
|
}:
|
|
let
|
|
registryAssembly = import ./registry.nix { inherit lib self; };
|
|
|
|
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");
|
|
|
|
collectedRegistry = registryAssembly.collect { hosts = self.nixosConfigurations; };
|
|
|
|
specialArgs = {
|
|
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
|
|
lib
|
|
self
|
|
specialArgs
|
|
bridgeName
|
|
moduleFiles
|
|
registryAssembly
|
|
;
|
|
};
|
|
|
|
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; });
|
|
in
|
|
{
|
|
inherit mkHosts;
|
|
}
|