host/tatos: use systemd timers instead of cron to run geoip updates

This commit is contained in:
Dmitriy Pleshevskiy 2024-12-28 16:06:30 +03:00
parent 1f360c1696
commit ddc3d08ed9
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
2 changed files with 21 additions and 10 deletions
hosts/tatos/services/wireguard

View file

@ -6,6 +6,8 @@ let
istalData = import (hostsPath + "/istal/data.secret.nix"); istalData = import (hostsPath + "/istal/data.secret.nix");
tatosData = import (hostsPath + "/tatos/data.secret.nix"); tatosData = import (hostsPath + "/tatos/data.secret.nix");
port = tatosData.wireguard.port; port = tatosData.wireguard.port;
update_ru_routes = pkgs.callPackage ./update_ru_routes.nix { };
in in
{ {
boot.kernel.sysctl."net.ipv4.ip_forward" = 1; boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
@ -20,16 +22,24 @@ in
networking.firewall.allowedUDPPorts = [ port ]; networking.firewall.allowedUDPPorts = [ port ];
services.cron = systemd.services.geoip-update = {
let update_ru_routes = pkgs.callPackage ./update_ru_routes.nix { }; in script = ''
let cmd = "${update_ru_routes}/bin/update_ru_routes > /root/update_routes.log 2>&1"; in set -eu
{ ${update_ru_routes}/bin/update_ru_routes > /root/update_routes.log
enable = true; '';
systemCronJobs = [ serviceConfig = {
"@reboot root sleep 30 && ${cmd}" Type = "oneshot";
"0 3 * * mon root ${cmd}" User = "root";
];
}; };
restartTriggers = [ update_ru_routes ];
};
systemd.timers.geoip-update = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "1m";
OnCalendar = "mon 3:00";
};
};
networking.wg-quick.interfaces = { networking.wg-quick.interfaces = {
# "wg0" is the network interface name. You can name the interface arbitrarily. # "wg0" is the network interface name. You can name the interface arbitrarily.

View file

@ -6,6 +6,7 @@
, iptables , iptables
, ipcalc , ipcalc
, jq , jq
, iproute2
, gawk , gawk
, curl , curl
}: }:
@ -19,7 +20,7 @@ in
symlinkJoin { symlinkJoin {
name = "update_ru_routes"; name = "update_ru_routes";
paths = [ update_ru_routes_unwrapped ] ++ [ bind.dnsutils iptables jq gawk curl ipcalc ]; paths = [ update_ru_routes_unwrapped ] ++ [ bind.dnsutils iptables jq gawk curl ipcalc iproute2 ];
buildInputs = [ makeWrapper ]; buildInputs = [ makeWrapper ];
postBuild = '' postBuild = ''