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

24 lines
733 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
services.tinc.networks.my-tinc.hostSettings = mapAttrs (name: host: {
2021-10-28 20:35:02 +00:00
addresses = [ { address = host.address; } ];
2021-10-28 20:07:49 +00:00
subnets = [ { address = host.subnetAddr; } ];
2021-10-28 20:35:02 +00:00
rsaPublicKey = if (host ? "rsaPublicKey") then (builtins.readFile host.rsaPublicKey) else null;
settings.Ed25519PublicKey = mkIf (host ? "ed25519PublicKey") (builtins.readFile host.ed25519PublicKey);
2021-10-28 20:07:49 +00:00
}) hosts;
};
}