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-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
|
|
|
|
|
|
|
# We provide a one-shot service which can be manually run. We could
|
|
|
|
# provide a service that runs on startup, but it's tricky to get
|
|
|
|
# a service to run after you have *internet* access.
|
|
|
|
systemd.services.tzupdate = {
|
|
|
|
description = "tzupdate timezone update service";
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
2024-09-17 09:30:55 +03:00
|
|
|
script = ''
|
2025-01-17 10:36:40 +02:00
|
|
|
timezone="$(${lib.getExe pkgs.tzupdate} --print-only)"
|
|
|
|
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-09-17 09:30:19 +03:00
|
|
|
meta.maintainers = with lib.maintainers; [ doronbehar ];
|
2017-10-17 09:26:02 -07:00
|
|
|
}
|