Ways #98

Merged
max merged 10 commits from pr-cluster-reverse-proxy into master 2024-07-04 22:05:22 +03:00
3 changed files with 35 additions and 2 deletions
Showing only changes of commit 01f113046f - Show all commits

View file

@ -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
View 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
];
}

View file

@ -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;
} }