···18 update the timezone.
19 '';
20 };
000000000000000000021 };
2223 config = lib.mkIf cfg.enable {
···26 # zone, which is better than silently overriding it.
27 time.timeZone = null;
2829- # 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.
32 systemd.services.tzupdate = {
33 description = "tzupdate timezone update service";
034 wants = [ "network-online.target" ];
35 after = [ "network-online.target" ];
36 script = ''
37- timezone="$(${lib.getExe pkgs.tzupdate} --print-only)"
38 if [[ -n "$timezone" ]]; then
39 echo "Setting timezone to '$timezone'"
40 timedatectl set-timezone "$timezone"
···44 serviceConfig = {
45 Type = "oneshot";
46 };
0000000000047 };
48 };
49
···18 update the timezone.
19 '';
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+ };
40 };
4142 config = lib.mkIf cfg.enable {
···45 # zone, which is better than silently overriding it.
46 time.timeZone = null;
4748+ # 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`.
51 systemd.services.tzupdate = {
52 description = "tzupdate timezone update service";
53+ wantedBy = [ "multi-user.target" ];
54 wants = [ "network-online.target" ];
55 after = [ "network-online.target" ];
56 script = ''
57+ timezone="$(${lib.getExe cfg.package} --print-only)"
58 if [[ -n "$timezone" ]]; then
59 echo "Setting timezone to '$timezone'"
60 timedatectl set-timezone "$timezone"
···64 serviceConfig = {
65 Type = "oneshot";
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" ];
78 };
79 };
80