xin/configs/peerix.nix

50 lines
1.2 KiB
Nix
Raw Normal View History

2022-08-30 15:55:21 -06:00
{ config, lib, ... }:
with lib; {
options = {
2022-08-30 15:56:37 -06:00
tsPeerix = {
2022-08-30 15:55:21 -06:00
enable = mkOption {
description = "Enable peerix";
default = false;
example = true;
type = lib.types.bool;
};
privateKeyFile = mkOption {
description = "Private key file for signing";
default = "";
example = "./private_key";
type = lib.types.path;
};
interfaces = mkOption {
description = "Interfaces to allow peerix to listen on.";
type = types.listOf types.str;
default = [ "tailscale0" ];
};
2022-08-30 15:55:21 -06:00
};
};
2022-08-30 15:56:37 -06:00
config = mkIf config.tsPeerix.enable {
2022-08-30 15:58:26 -06:00
users.groups.peerix = { name = "peerix"; };
2022-08-30 15:56:37 -06:00
users.users.peerix = {
name = "peerix";
group = "peerix";
isSystemUser = true;
};
2022-08-30 15:55:21 -06:00
services = {
peerix = {
enable = true;
2022-08-30 15:56:37 -06:00
openFirewall = false;
user = "peerix";
privateKeyFile = "${config.tsPeerix.privateKeyFile}";
publicKeyFile = ./peerix.pubs;
2022-08-30 15:55:21 -06:00
};
};
networking.firewall.interfaces = listToAttrs (flatten (map (i: {
name = i;
value = {
2022-08-30 15:56:37 -06:00
allowedUDPPorts = [ 12304 ];
allowedTCPPorts = [ 12304 ];
2022-08-30 15:55:21 -06:00
};
}) config.tsPeerix.interfaces));
2022-08-30 15:55:21 -06:00
};
}