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:
parent
91306427ba
commit
777d803b76
2 changed files with 47 additions and 1 deletions
46
modules/distributed-config.nix
Normal file
46
modules/distributed-config.nix
Normal 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;
|
||||
}
|
|
@ -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 =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue