2017-10-17 09:26:02 -07:00
|
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
lib,
|
|
|
|
|
pkgs,
|
|
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.tzupdate;
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
options.services.tzupdate = {
|
2024-08-30 00:46:52 +02:00
|
|
|
|
enable = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
2017-10-17 09:26:02 -07:00
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Enable the tzupdate timezone updating service. This provides
|
2020-08-07 14:43:58 +01:00
|
|
|
|
a one-shot service which can be activated with systemctl to
|
2017-10-17 09:26:02 -07:00
|
|
|
|
update the timezone.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-12-16 11:22:00 +00:00
|
|
|
|
|
|
|
|
|
package = lib.mkPackageOption pkgs "tzupdate" { };
|
|
|
|
|
|
|
|
|
|
timer.enable = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Enable the tzupdate timer to update the timezone automatically.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
timer.interval = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "hourly";
|
|
|
|
|
description = ''
|
|
|
|
|
The interval at which the tzupdate timer should run. See
|
|
|
|
|
{manpage}`systemd.time(7)` to understand the format.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2017-10-17 09:26:02 -07:00
|
|
|
|
};
|
|
|
|
|
|
2024-08-30 00:46:52 +02:00
|
|
|
|
config = lib.mkIf cfg.enable {
|
2017-10-17 09:26:02 -07:00
|
|
|
|
# We need to have imperative time zone management for this to work.
|
|
|
|
|
# This will give users an error if they have set an explicit time
|
|
|
|
|
# zone, which is better than silently overriding it.
|
2020-08-07 14:43:58 +01:00
|
|
|
|
time.timeZone = null;
|
2017-10-17 09:26:02 -07:00
|
|
|
|
|
2024-12-03 09:30:45 +01:00
|
|
|
|
# We provide a one-shot service that runs at startup once network
|
|
|
|
|
# interfaces are up, but we can’t ensure we actually have Internet access
|
|
|
|
|
# at that point. It can also be run manually with `systemctl start tzupdate`.
|
2017-10-17 09:26:02 -07:00
|
|
|
|
systemd.services.tzupdate = {
|
|
|
|
|
description = "tzupdate timezone update service";
|
2024-12-03 09:30:45 +01:00
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2017-10-17 09:26:02 -07:00
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
|
after = [ "network-online.target" ];
|
2024-09-17 09:30:55 +03:00
|
|
|
|
script = ''
|
2024-12-16 11:22:00 +00:00
|
|
|
|
timezone="$(${lib.getExe cfg.package} --print-only)"
|
2025-01-17 10:36:40 +02:00
|
|
|
|
if [[ -n "$timezone" ]]; then
|
|
|
|
|
echo "Setting timezone to '$timezone'"
|
|
|
|
|
timedatectl set-timezone "$timezone"
|
|
|
|
|
fi
|
2024-09-17 09:30:55 +03:00
|
|
|
|
'';
|
2017-10-17 09:26:02 -07:00
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
};
|
|
|
|
|
};
|
2024-12-16 11:22:00 +00:00
|
|
|
|
|
|
|
|
|
systemd.timers.tzupdate = {
|
|
|
|
|
enable = cfg.timer.enable;
|
|
|
|
|
timerConfig = {
|
|
|
|
|
OnStartupSec = "30s";
|
|
|
|
|
OnCalendar = cfg.timer.interval;
|
|
|
|
|
Persistent = true;
|
|
|
|
|
};
|
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
|
};
|
2017-10-17 09:26:02 -07:00
|
|
|
|
};
|
|
|
|
|
|
2024-09-17 09:30:19 +03:00
|
|
|
|
meta.maintainers = with lib.maintainers; [ doronbehar ];
|
2017-10-17 09:26:02 -07:00
|
|
|
|
}
|