Switch to regular systemd service

This commit is contained in:
niten 2024-08-22 17:49:36 -07:00
parent 233c1fb29c
commit 2c20446df3

View File

@ -267,40 +267,67 @@ in {
}; };
}; };
system.services.adguard-dns-proxy = systemd.services.adguard-dns-proxy =
let cfg-path = "/run/adguard-dns-proxy/config.yaml"; let configFile = "/run/adguard-dns-proxy/config.yaml";
in { in {
description = description =
"DNS Proxy for ad filtering and DNS-over-HTTPS lookups."; "DNS proxy for ad filtering and DNS-over-HTTPS lookups.";
wantedBy = [ "default.target" ]; wantedBy = [ "default.target" ];
after = [ "syslog.target" ]; after = [ "syslog.target" "network.target" ];
requires = [ "network.target" ]; requires = [ "syslog.target" "network.target" ];
privateNetwork = false; serviceConfig = {
requiredCapabilities = optional upgrade-perms "CAP_NET_BIND_SERVICE"; ExecStartPre = ''
restartWhen = "always"; cp ${generate-config-file cfg} $RUNTIME_DIRECTORY/config.yaml
addressFamilies = null; '';
networkWhitelist = cfg.allowed-networks; ExecStart = concatStringsSep " " [
user = mkIf upgrade-perms cfg.user; "${pkgs.adguardhome}/bin/adguardhome"
runtimeDirectory = "adguard-dns-proxy";
stateDirectory = "adguard-dns-proxy";
preStart = ''
cp ${generate-config-file cfg} ${cfg-path};
chown $USER ${cfg-path};
chmod u+w ${cfg-path};
'';
execStart = let
args = [
"--no-check-update" "--no-check-update"
"--work-dir /var/lib/adguard-dns-proxy" "--work-dir /var/lib/adguard-dns-proxy"
"--pidfile /run/adguard-dns-proxy/adguard-dns-proxy.pid" "--pidfile /run/adguard-dns-proxy.pid"
"--host ${cfg.http.listen-ip}" "--host ${cfg.http.listen-ip}"
"--port ${toString cfg.http.listen-port}" "--port ${toString cfg.http.listen-port}"
"--config ${cfg-path}" "--config $RUNTIME_DIRECTORY/config.yaml"
]; ];
arg-string = concatStringsSep " " args; AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
in "${pkgs.adguardhome}/bin/adguardhome ${arg-string}"; DynamicUser = true;
RuntimeDirectory = "adguard-dns-proxy";
};
}; };
# system.services.adguard-dns-proxy =
# let cfg-path = "/run/adguard-dns-proxy/config.yaml";
# in {
# description =
# "DNS Proxy for ad filtering and DNS-over-HTTPS lookups.";
# wantedBy = [ "default.target" ];
# after = [ "syslog.target" ];
# requires = [ "network.target" ];
# privateNetwork = false;
# requiredCapabilities = optional upgrade-perms "CAP_NET_BIND_SERVICE";
# restartWhen = "always";
# addressFamilies = null;
# networkWhitelist = cfg.allowed-networks;
# user = mkIf upgrade-perms cfg.user;
# runtimeDirectory = "adguard-dns-proxy";
# stateDirectory = "adguard-dns-proxy";
# preStart = ''
# cp ${generate-config-file cfg} ${cfg-path};
# chown $USER ${cfg-path};
# chmod u+w ${cfg-path};
# '';
# execStart = let
# args = [
# "--no-check-update"
# "--work-dir /var/lib/adguard-dns-proxy"
# "--pidfile /run/adguard-dns-proxy/adguard-dns-proxy.pid"
# "--host ${cfg.http.listen-ip}"
# "--port ${toString cfg.http.listen-port}"
# "--config ${cfg-path}"
# ];
# arg-string = concatStringsSep " " args;
# in "${pkgs.adguardhome}/bin/adguardhome ${arg-string}";
# };
}; };
}); });
} }