hive.nix: Add abstraction

This commit is contained in:
Tom Hubrecht 2023-05-22 15:08:33 +02:00
parent 0fd05cd197
commit 8949cf78dc

View file

@ -1,21 +1,42 @@
let
sources = import ./npins;
metadata = import ./meta;
lib = import ./lib/trivial.nix;
mkNode = node: { name, nodes, ... }: {
# Import the base configuration for each node
imports = builtins.map (lib.mkRel ./machines/${node}) [
"_configuration.nix"
"_hardware-configuration.nix"
];
# Deployment config is specified in meta.nodes.${node}.deployment
inherit (metadata.nodes.${node}) deployment;
};
mkNixpkgs = node: import sources."nixos-${metadata.nodes.${node}.nixpkgs}" { };
mkArgs = node: {
dgn-lib = import ./lib { inherit ((mkNixpkgs node)) lib; };
};
nodes = builtins.attrNames metadata.nodes;
in
{
meta = {
nixpkgs = import sources.nixpkgs;
nodeNixpkgs = lib.mapSingleFuse mkNixpkgs nodes;
nodeNixpkgs = {
};
specialArgs = { meta = metadata; };
nodeSpecialArgs = lib.mapSingleFuse mkArgs nodes;
# TODO: Add remote builders (`machinesFile` option)
};
web-01 = { name, nodes, ... }: {
imports = [ ./machines/${name}/configuration.nix ];
deployment = {
targetUser = "root";
targetHost = "129.199.129.200";
defaults = { ... }: {
# Import the default modules
imports = [ ./modules ];
};
};
}
} // (lib.mapSingleFuse mkNode nodes)