0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-20 00:50:38 +03:00
nixpkgs/nixos/modules/services/misc/tzupdate.nix
Doron Behar f74883a691 nixos/tzupdate: report timezone being set in journal
Also, no need for set -uo pipefail as there are no pipes there at the
moment.
2025-02-08 22:50:13 +02:00

45 lines
1.4 KiB
Nix

{ 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.
'';
};
};
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 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" ];
script = ''
timezone="$(${lib.getExe pkgs.tzupdate} --print-only)"
if [[ -n "$timezone" ]]; then
echo "Setting timezone to '$timezone'"
timedatectl set-timezone "$timezone"
fi
'';
serviceConfig = {
Type = "oneshot";
};
};
};
meta.maintainers = with lib.maintainers; [ doronbehar ];
}