config/modules/services/headscale/default.nix

64 lines
1.7 KiB
Nix
Raw Normal View History

2023-08-24 23:44:18 +03:00
{
config,
lib,
pkgs,
...
2024-07-29 15:39:54 +03:00
}:
{
2023-08-24 23:44:18 +03:00
options.mj.services.headscale = with lib.types; {
enable = lib.mkEnableOption "Enable headscale";
2024-07-29 15:39:54 +03:00
clientOidcPath = lib.mkOption { type = str; };
subnetCIDR = lib.mkOption { type = str; };
2023-08-24 23:44:18 +03:00
};
config = lib.mkIf config.mj.services.headscale.enable {
2024-07-29 15:39:54 +03:00
environment.systemPackages = [ pkgs.headscale ];
2023-08-24 23:44:18 +03:00
2024-07-29 15:39:54 +03:00
networking.firewall.allowedTCPPorts = [ 3478 ];
networking.firewall.allowedUDPPorts = [ 3478 ];
2023-08-24 23:44:18 +03:00
services = {
headscale = {
enable = true;
settings = {
server_url = "https://vpn.jakstys.lt";
2024-07-29 15:39:54 +03:00
ip_prefixes = [ config.mj.services.headscale.subnetCIDR ];
2023-08-24 23:44:18 +03:00
log.level = "warn";
dns_config = {
2024-07-29 15:39:54 +03:00
nameservers = [
"1.1.1.1"
"8.8.4.4"
];
2023-08-24 23:44:18 +03:00
magic_dns = false;
base_domain = "jakst";
};
oidc = {
issuer = "https://git.jakstys.lt/";
client_id = "e25c15ea-41ca-4bf0-9ebf-2be9f2d1ccea";
2023-11-27 12:07:19 +02:00
client_secret_path = "\${CREDENTIALS_DIRECTORY}/oidc-client-secret";
2023-08-24 23:44:18 +03:00
};
};
};
caddy = {
virtualHosts."vpn.jakstys.lt".extraConfig = ''
reverse_proxy 127.0.0.1:8080
'';
};
};
systemd.services.headscale = {
unitConfig.StartLimitIntervalSec = "5m";
# Allow restarts for up to a minute. A start
# itself may take a while, thus the window of restart
# is higher.
unitConfig.StartLimitBurst = 50;
serviceConfig.RestartSec = 1;
serviceConfig.LoadCredential = [
"oidc-client-secret:${config.mj.services.headscale.clientOidcPath}"
];
};
};
}