nix-home/modules/my-tinc/hosts.nix

36 lines
973 B
Nix
Raw Normal View History

2021-10-28 20:10:47 +00:00
{ config, pkgs, lib, ... }:
2021-10-28 20:07:49 +00:00
with lib;
let
hosts = import ./hosts;
cfg = config.services.my-tinc;
mapAttrs = f: attrs: builtins.listToAttrs (
map (name: { inherit name; value = f name (builtins.getAttr name attrs); }) (builtins.attrNames attrs)
);
in
{
config = mkIf cfg.enable {
# All hosts we know of
2022-05-31 16:45:33 +00:00
services.tinc.networks.my-tinc.hostSettings = mapAttrs
(name: host: {
addresses = if (host ? address) then [{ address = host.address; }] else [ ];
subnets = [{ address = host.subnetAddr; }];
rsaPublicKey = mkIf (host ? "rsaPublicKey") host.rsaPublicKey;
settings.Ed25519PublicKey = mkIf (host ? "ed25519PublicKey") host.ed25519PublicKey;
})
hosts;
2022-10-17 12:10:39 +00:00
# Add all of them to host
2024-08-16 12:13:30 +00:00
nki.services.edns = {
enable = true;
cloaking-rules =
(lib.attrsets.mapAttrs'
(name: host: { name = "${name}.tinc"; value = host.subnetAddr; })
hosts)
;
};
2021-10-28 20:07:49 +00:00
};
}