···1818 update the timezone.
1919 '';
2020 };
2121+2222+ package = lib.mkPackageOption pkgs "tzupdate" { };
2323+2424+ timer.enable = lib.mkOption {
2525+ type = lib.types.bool;
2626+ default = true;
2727+ description = ''
2828+ Enable the tzupdate timer to update the timezone automatically.
2929+ '';
3030+ };
3131+3232+ timer.interval = lib.mkOption {
3333+ type = lib.types.str;
3434+ default = "hourly";
3535+ description = ''
3636+ The interval at which the tzupdate timer should run. See
3737+ {manpage}`systemd.time(7)` to understand the format.
3838+ '';
3939+ };
2140 };
22412342 config = lib.mkIf cfg.enable {
···2645 # zone, which is better than silently overriding it.
2746 time.timeZone = null;
28472929- # We provide a one-shot service which can be manually run. We could
3030- # provide a service that runs on startup, but it's tricky to get
3131- # a service to run after you have *internet* access.
4848+ # We provide a one-shot service that runs at startup once network
4949+ # interfaces are up, but we can’t ensure we actually have Internet access
5050+ # at that point. It can also be run manually with `systemctl start tzupdate`.
3251 systemd.services.tzupdate = {
3352 description = "tzupdate timezone update service";
5353+ wantedBy = [ "multi-user.target" ];
3454 wants = [ "network-online.target" ];
3555 after = [ "network-online.target" ];
3656 script = ''
3737- timezone="$(${lib.getExe pkgs.tzupdate} --print-only)"
5757+ timezone="$(${lib.getExe cfg.package} --print-only)"
3858 if [[ -n "$timezone" ]]; then
3959 echo "Setting timezone to '$timezone'"
4060 timedatectl set-timezone "$timezone"
···4464 serviceConfig = {
4565 Type = "oneshot";
4666 };
6767+ };
6868+6969+ systemd.timers.tzupdate = {
7070+ enable = cfg.timer.enable;
7171+ interval = cfg.timer.interval;
7272+ timerConfig = {
7373+ OnStartupSec = "30s";
7474+ OnCalendar = cfg.timer.interval;
7575+ Persistent = true;
7676+ };
7777+ wantedBy = [ "timers.target" ];
4778 };
4879 };
4980