From 8949cf78dce68d4296907adfa86182c7d4960b9d Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 22 May 2023 15:08:33 +0200 Subject: [PATCH] hive.nix: Add abstraction --- hive.nix | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/hive.nix b/hive.nix index c849d44..6de1f2c 100644 --- a/hive.nix +++ b/hive.nix @@ -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)