1
0
Fork 0
selfhostblocks/_disnix/caddy/unit.nix

81 lines
1.5 KiB
Nix
Raw Normal View History

2022-09-09 08:26:33 +02:00
{ stdenv
, pkgs
, utils
}:
{ user ? "http"
, group ? "http"
2022-12-31 09:35:08 +01:00
, siteConfigDir
2022-09-09 08:26:33 +02:00
}:
{...}:
2022-12-31 09:35:08 +01:00
let
config = pkgs.writeTextDir "Caddyfile" ''
{
# Disable auto https
http_port 10001
https_port 10002
}
import ${siteConfigDir}/*
'';
in
2022-09-09 08:26:33 +02:00
utils.systemd.mkService rec {
name = "caddy";
content = ''
[Unit]
Description=Caddy webserver
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Wants=network-online.target systemd-networkd-wait-online.target
StartLimitInterval=14400
StartLimitBurst=10
[Service]
Type=notify
User=${user}
Group=${group}
2022-12-31 09:35:08 +01:00
ExecStart=${pkgs.caddy}/bin/caddy run --environ --config ${config}
ExecReload=${pkgs.caddy}/bin/caddy reload --config ${config}
2022-09-09 08:26:33 +02:00
# Restart=on-abnormal
2022-09-10 08:15:03 +02:00
RuntimeDirectory=caddy
2022-09-09 08:26:33 +02:00
# KillMode=mixed
# KillSignal=SIGQUIT
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
# PrivateDevices=true
2022-09-10 08:15:03 +02:00
LockPersonality=true
NoNewPrivileges=true
PrivateDevices=true
2022-09-09 08:26:33 +02:00
PrivateTmp=true
2022-09-10 08:15:03 +02:00
ProtectClock=true
ProtectControlGroups=true
ProtectHome=true
ProtectHostname=true
ProtectKernelLogs=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectSystem=full
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
2022-09-09 08:26:33 +02:00
# CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
# ProtectSystem=strict
# ReadWritePaths=/var/lib/caddy /var/log/caddy
[Install]
WantedBy=multi-user.target
'';
}