nixos/tzupdate: make enabled module actually be enabled (#361373)

authored by xanderio and committed by GitHub aca27064 a8004f9f

+35 -4
+35 -4
nixos/modules/services/misc/tzupdate.nix
··· 18 18 update the timezone. 19 19 ''; 20 20 }; 21 + 22 + package = lib.mkPackageOption pkgs "tzupdate" { }; 23 + 24 + timer.enable = lib.mkOption { 25 + type = lib.types.bool; 26 + default = true; 27 + description = '' 28 + Enable the tzupdate timer to update the timezone automatically. 29 + ''; 30 + }; 31 + 32 + timer.interval = lib.mkOption { 33 + type = lib.types.str; 34 + default = "hourly"; 35 + description = '' 36 + The interval at which the tzupdate timer should run. See 37 + {manpage}`systemd.time(7)` to understand the format. 38 + ''; 39 + }; 21 40 }; 22 41 23 42 config = lib.mkIf cfg.enable { ··· 26 45 # zone, which is better than silently overriding it. 27 46 time.timeZone = null; 28 47 29 - # We provide a one-shot service which can be manually run. We could 30 - # provide a service that runs on startup, but it's tricky to get 31 - # a service to run after you have *internet* access. 48 + # We provide a one-shot service that runs at startup once network 49 + # interfaces are up, but we can’t ensure we actually have Internet access 50 + # at that point. It can also be run manually with `systemctl start tzupdate`. 32 51 systemd.services.tzupdate = { 33 52 description = "tzupdate timezone update service"; 53 + wantedBy = [ "multi-user.target" ]; 34 54 wants = [ "network-online.target" ]; 35 55 after = [ "network-online.target" ]; 36 56 script = '' 37 - timezone="$(${lib.getExe pkgs.tzupdate} --print-only)" 57 + timezone="$(${lib.getExe cfg.package} --print-only)" 38 58 if [[ -n "$timezone" ]]; then 39 59 echo "Setting timezone to '$timezone'" 40 60 timedatectl set-timezone "$timezone" ··· 44 64 serviceConfig = { 45 65 Type = "oneshot"; 46 66 }; 67 + }; 68 + 69 + systemd.timers.tzupdate = { 70 + enable = cfg.timer.enable; 71 + interval = cfg.timer.interval; 72 + timerConfig = { 73 + OnStartupSec = "30s"; 74 + OnCalendar = cfg.timer.interval; 75 + Persistent = true; 76 + }; 77 + wantedBy = [ "timers.target" ]; 47 78 }; 48 79 }; 49 80