flake: add builder lib & formatter

flake: add builder lib & formatter

flake: add builder lib & formatter

flake: add builder lib & formatter
This commit is contained in:
ooks-io 2024-10-20 13:55:00 +13:00
parent 6ccdce3710
commit 19a4bbda3c
6 changed files with 157 additions and 63 deletions

91
outputs/lib/builders.nix Normal file
View file

@ -0,0 +1,91 @@
{
lib,
inputs,
self,
...
}: let
inherit (lib) singleton recursiveUpdate mkDefault;
inherit (builtins) concatLists;
inherit (self) keys;
hm = inputs.home-manager.nixosModules.home-manager;
agenix = inputs.agenix.nixosModules.default;
nixosModules = "${self}/nixos";
mkNixos = inputs.nixpkgs.lib.nixosSystem;
hostModules = "${self}/hosts";
mkBaseSystem = {
withSystem,
hostname,
system,
type,
role,
additionalModules ? [],
specialArgs ? {},
}:
withSystem system ({
inputs',
self',
...
}:
mkNixos {
specialArgs =
recursiveUpdate {
inherit keys lib inputs self inputs' self';
}
specialArgs;
modules = concatLists [
(singleton {
networking.hostName = hostname;
nixpkgs.hostPlatform = mkDefault system;
ooknet.host = {
name = hostname;
inherit role type;
};
})
[(hostModules + "/${hostname}")]
additionalModules
];
});
mkWorkstation = {
withSystem,
hostname,
system,
type,
additionalModules ? [],
specialArgs ? {},
}:
mkBaseSystem {
inherit withSystem hostname system type specialArgs;
role = "workstation";
additionalModules = concatLists [
[hm agenix nixosModules]
additionalModules
];
};
mkServer = {
withSystem,
hostname,
system,
type,
platform,
services,
additionalModules ? [],
specialArgs ? {},
}:
mkBaseSystem {
inherit withSystem hostname system type specialArgs;
role = "server";
additionalModules = concatLists [
(singleton {
ooknet.host = {
inherit platform services;
};
})
additionalModules
];
};
in {
inherit mkServer mkWorkstation;
}

12
outputs/lib/default.nix Normal file
View file

@ -0,0 +1,12 @@
{
lib,
self,
inputs,
...
}: let
builders = import ./builders.nix {inherit self lib inputs;};
in {
_module.args.ooknet.lib = {
inherit builders;
};
}