1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-19 16:09:19 +03:00
nixpkgs/nixos/modules/services/misc/tzupdate.nix
2025-04-27 10:48:37 +02:00

81 lines
2.2 KiB
Nix
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.tzupdate;
in
{
options.services.tzupdate = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Enable the tzupdate timezone updating service. This provides
a one-shot service which can be activated with systemctl to
update the timezone.
'';
};
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.
'';
};
};
config = lib.mkIf cfg.enable {
# 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.
time.timeZone = null;
# We provide a one-shot service that runs at startup once network
# interfaces are up, but we cant ensure we actually have Internet access
# at that point. It can also be run manually with `systemctl start tzupdate`.
systemd.services.tzupdate = {
description = "tzupdate timezone update service";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
script = ''
timezone="$(${lib.getExe cfg.package} --print-only)"
if [[ -n "$timezone" ]]; then
echo "Setting timezone to '$timezone'"
timedatectl set-timezone "$timezone"
fi
'';
serviceConfig = {
Type = "oneshot";
};
};
systemd.timers.tzupdate = {
enable = cfg.timer.enable;
timerConfig = {
OnStartupSec = "30s";
OnCalendar = cfg.timer.interval;
Persistent = true;
};
wantedBy = [ "timers.target" ];
};
};
meta.maintainers = with lib.maintainers; [ doronbehar ];
}