Add caddy module with tailscale integration

This commit is contained in:
SebastianStork 2025-05-29 01:05:42 +02:00
parent 1f4b3e734b
commit e909dcd866
6 changed files with 164 additions and 147 deletions

View file

@ -1,9 +1,4 @@
{
config,
pkgs,
lib,
...
}:
{ config, lib, ... }:
let
cfg = config.custom.services.tailscale;
in
@ -16,13 +11,6 @@ in
};
ssh.enable = lib.mkEnableOption "";
exitNode.enable = lib.mkEnableOption "";
serve = {
isFunnel = lib.mkEnableOption "";
target = lib.mkOption {
type = lib.types.nullOr lib.types.nonEmptyStr;
default = null;
};
};
};
config = lib.mkIf cfg.enable {
@ -40,30 +28,5 @@ in
"--advertise-exit-node=${lib.boolToString cfg.exitNode.enable}"
];
};
systemd.services =
let
mode = if cfg.serve.isFunnel then "funnel" else "serve";
in
{
"tailscaled-${mode}" = lib.mkIf (cfg.serve.target != null) {
after = [
"tailscaled.service"
"tailscaled-autoconnect.service"
];
wants = [ "tailscaled.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStartPre = "${lib.getExe pkgs.tailscale} cert --min-validity 120h ${config.networking.hostName}.${cfg.domain}";
ExecStart = "${lib.getExe pkgs.tailscale} ${mode} --bg ${cfg.serve.target}";
ExecStop = "${lib.getExe pkgs.tailscale} ${mode} reset";
Restart = "on-failure";
};
};
tailscaled-set.after = [ "tailscaled-autoconnect.service" ];
};
};
}