forked from mirrors_public/oddlama_nix-config
fix: distributed-config now works across microvms and colmena nodes
This commit is contained in:
parent
69bd2a71ce
commit
5bd65732f5
3 changed files with 20 additions and 16 deletions
|
@ -28,7 +28,6 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
nodes.sentinel.age.secrets.loki-basic-auth-hashes.generator.dependencies = [
|
nodes.sentinel.age.secrets.loki-basic-auth-hashes.generator.dependencies = [
|
||||||
aaa not wokring
|
|
||||||
config.age.secrets.grafana-loki-basic-auth-password
|
config.age.secrets.grafana-loki-basic-auth-password
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,13 @@
|
||||||
(lib)
|
(lib)
|
||||||
attrNames
|
attrNames
|
||||||
concatMap
|
concatMap
|
||||||
|
elem
|
||||||
filter
|
filter
|
||||||
mdDoc
|
mdDoc
|
||||||
mkOption
|
mkOption
|
||||||
|
mkOptionType
|
||||||
|
optionalAttrs
|
||||||
types
|
types
|
||||||
unique
|
|
||||||
subtractLists
|
|
||||||
;
|
;
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
@ -24,24 +25,24 @@
|
||||||
;
|
;
|
||||||
in {
|
in {
|
||||||
options.nodes = mkOption {
|
options.nodes = mkOption {
|
||||||
type = types.attrsOf types.unspecified;
|
type = types.attrsOf (mkOptionType {
|
||||||
|
name = "Toplevel NixOS config";
|
||||||
|
merge = loc: map (x: x.value);
|
||||||
|
});
|
||||||
default = {};
|
default = {};
|
||||||
description = mdDoc "Allows extending the configuration of other machines.";
|
description = mdDoc "Allows extending the configuration of other machines.";
|
||||||
};
|
};
|
||||||
|
|
||||||
config = let
|
config = let
|
||||||
|
isColmenaNode = elem nodeName (attrNames colmenaNodes);
|
||||||
otherNodes = filter (n: n != nodeName) (attrNames colmenaNodes);
|
otherNodes = filter (n: n != nodeName) (attrNames colmenaNodes);
|
||||||
foreignConfigs = map (n: colmenaNodes.${n}.config.nodes.${nodeName} or {}) otherNodes;
|
foreignConfigs = concatMap (n: colmenaNodes.${n}.config.nodes.${nodeName} or []) otherNodes;
|
||||||
toplevelAttrs = ["age" "networking" "systemd" "services"];
|
toplevelAttrs = ["age" "networking" "systemd" "services"];
|
||||||
in
|
in
|
||||||
todo wrong, currently extension FROM microvms is not possible
|
optionalAttrs isColmenaNode (mergeToplevelConfigs toplevelAttrs (
|
||||||
{
|
foreignConfigs
|
||||||
assertions =
|
# Also allow extending ourselves, in case some attributes from depenent
|
||||||
map (n: {
|
# configurations such as containers or microvms are merged to the host
|
||||||
assertion = false;
|
++ [config.nodes.${nodeName} or {}]
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,10 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Propagate node expansions, since doing this directly in the
|
||||||
|
# distributed-config module would cause infinite recursion.
|
||||||
|
nodes = mkMerge config.microvm.vms.${vmName}.config.options.nodes.definitions;
|
||||||
|
|
||||||
microvm.vms.${vmName} = let
|
microvm.vms.${vmName} = let
|
||||||
node = import ../nix/generate-node.nix inputs vmCfg.nodeName {
|
node = import ../nix/generate-node.nix inputs vmCfg.nodeName {
|
||||||
inherit (vmCfg) system configPath;
|
inherit (vmCfg) system configPath;
|
||||||
|
@ -360,6 +364,6 @@ in {
|
||||||
ipv6 = net.cidr.host 1 cfg.networking.wireguard.cidrv6;
|
ipv6 = net.cidr.host 1 cfg.networking.wireguard.cidrv6;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// extraLib.mergeToplevelConfigs ["disko" "microvm" "systemd"] (mapAttrsToList microvmConfig vms)
|
// extraLib.mergeToplevelConfigs ["nodes" "disko" "microvm" "systemd"] (mapAttrsToList microvmConfig vms)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue