Ways #98
3 changed files with 35 additions and 2 deletions
|
@ -14,6 +14,7 @@ lib.evalModules {
|
||||||
./lib/services.nix
|
./lib/services.nix
|
||||||
./lib/inject-nixos-config.nix
|
./lib/inject-nixos-config.nix
|
||||||
./lib/port-magic-multi.nix
|
./lib/port-magic-multi.nix
|
||||||
|
./lib/mesh.nix
|
||||||
|
|
||||||
./import-services.nix
|
./import-services.nix
|
||||||
];
|
];
|
||||||
|
|
15
cluster/lib/mesh.nix
Normal file
15
cluster/lib/mesh.nix
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
hostLinks = lib.pipe config.services [
|
||||||
|
(lib.filterAttrs (_: svc: svc.meshLinks != {}))
|
||||||
|
(lib.mapAttrsToList (svcName: svc: lib.mapAttrsToList (name: cfg: lib.genAttrs svc.nodes.${name} (hostName: {
|
||||||
|
${cfg.name} = { ... }: {
|
||||||
|
imports = [ cfg.link ];
|
||||||
|
ipv4 = config.vars.mesh.${hostName}.meshIp;
|
||||||
|
};
|
||||||
|
})) svc.meshLinks))
|
||||||
|
(map lib.mkMerge)
|
||||||
|
lib.mkMerge
|
||||||
|
];
|
||||||
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
{ config, lib, ... }:
|
{ config, lib, name, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
filterGroup = group: hostName: builtins.filter (x: x != hostName) group;
|
filterGroup = group: hostName: builtins.filter (x: x != hostName) group;
|
||||||
|
serviceName = name;
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -31,6 +32,22 @@ in
|
||||||
type = with types; attrs;
|
type = with types; attrs;
|
||||||
default = {};
|
default = {};
|
||||||
};
|
};
|
||||||
|
meshLinks = mkOption {
|
||||||
|
description = "Create host links on the mesh network.";
|
||||||
|
type = types.attrsOf (types.submodule ({ name, ... }: {
|
||||||
|
options = {
|
||||||
|
name = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "${serviceName}-${name}";
|
||||||
|
};
|
||||||
|
link = mkOption {
|
||||||
|
type = types.deferredModule;
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
config.otherNodes = builtins.mapAttrs (const filterGroup) config.nodes;
|
config.otherNodes = builtins.mapAttrs (const filterGroup) config.nodes;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue