1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-10 23:00:39 +02:00

feat: add module to allow extending configuration of other nodes

This commit is contained in:
oddlama 2023-06-12 00:17:55 +02:00
parent 91306427ba
commit 777d803b76
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
2 changed files with 47 additions and 1 deletions

View file

@ -0,0 +1,46 @@
{
config,
extraLib,
lib,
nodeName,
colmenaNodes,
...
}: let
inherit
(lib)
attrNames
concatMap
filter
mdDoc
mkOption
types
unique
subtractLists
;
inherit
(extraLib)
mergeToplevelConfigs
;
in {
options.nodes = mkOption {
type = types.attrsOf types.unspecified;
default = {};
description = mdDoc "Allows extending the configuration of other machines.";
};
config = let
otherNodes = filter (n: n != nodeName) (attrNames colmenaNodes);
foreignConfigs = map (n: colmenaNodes.${n}.config.nodes.${nodeName} or {}) otherNodes;
toplevelAttrs = ["age" "networking" "systemd" "services"];
in
{
assertions =
map (n: {
assertion = false;
message = "Cannot extend configuration using nodes.${n} because the given node is not a registered or not a first-class nixos node (microvm's can't be extended right now).";
})
(subtractLists (attrNames colmenaNodes) (attrNames config.nodes));
}
// mergeToplevelConfigs toplevelAttrs foreignConfigs;
}

View file

@ -18,7 +18,7 @@ in {
pkgs = self.pkgs.${nodeMeta.system};
specialArgs = {
inherit (nixpkgs) lib;
inherit (self) extraLib nodes stateVersion;
inherit (self) extraLib nodes stateVersion colmenaNodes;
inherit inputs nodeName;
# Only set the nodePath if it is an actual directory
nodePath =