1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-21 00:49:27 +03:00
nixpkgs/nixos/modules/services/misc/tzupdate.nix

82 lines
2.2 KiB
Nix
Raw Permalink Normal View History

{
config,
lib,
pkgs,
...
}:
2017-10-17 09:26:02 -07:00
let
cfg = config.services.tzupdate;
in
{
2017-10-17 09:26:02 -07:00
options.services.tzupdate = {
enable = lib.mkOption {
type = lib.types.bool;
2017-10-17 09:26:02 -07:00
default = false;
description = ''
2017-10-17 09:26:02 -07:00
Enable the tzupdate timezone updating service. This provides
a one-shot service which can be activated with systemctl to
2017-10-17 09:26:02 -07:00
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.
'';
};
2017-10-17 09:26:02 -07: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.
time.timeZone = null;
2017-10-17 09:26:02 -07:00
# 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`.
2017-10-17 09:26:02 -07:00
systemd.services.tzupdate = {
description = "tzupdate timezone update service";
wantedBy = [ "multi-user.target" ];
2017-10-17 09:26:02 -07:00
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
'';
2017-10-17 09:26:02 -07:00
serviceConfig = {
Type = "oneshot";
};
};
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
};
meta.maintainers = with lib.maintainers; [ doronbehar ];
2017-10-17 09:26:02 -07:00
}