diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-04-25 14:52:15 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-04-25 14:52:15 +0200 |
commit | 740081d9eecff224fe5aa398000f0dcb72ff89b5 (patch) | |
tree | 1fb23f7d07e1fef673e3d9106c1450124a11119c /modules | |
parent | e85f955fbcf4e0541a0c7985deab5e59c37164a7 (diff) | |
download | nixos-740081d9eecff224fe5aa398000f0dcb72ff89b5.tar nixos-740081d9eecff224fe5aa398000f0dcb72ff89b5.tar.gz nixos-740081d9eecff224fe5aa398000f0dcb72ff89b5.tar.bz2 nixos-740081d9eecff224fe5aa398000f0dcb72ff89b5.tar.xz nixos-740081d9eecff224fe5aa398000f0dcb72ff89b5.zip |
bump
Diffstat (limited to 'modules')
-rw-r--r-- | modules/tzupdate.nix | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/modules/tzupdate.nix b/modules/tzupdate.nix new file mode 100644 index 00000000..6465d33f --- /dev/null +++ b/modules/tzupdate.nix | |||
@@ -0,0 +1,81 @@ | |||
1 | { | ||
2 | config, | ||
3 | lib, | ||
4 | pkgs, | ||
5 | ... | ||
6 | }: | ||
7 | let | ||
8 | cfg = config.services.tzupdate; | ||
9 | in | ||
10 | { | ||
11 | disabledModules = [ "services/misc/tzupdate.nix" ]; | ||
12 | |||
13 | options.services.tzupdate = { | ||
14 | enable = lib.mkOption { | ||
15 | type = lib.types.bool; | ||
16 | default = false; | ||
17 | description = '' | ||
18 | Enable the tzupdate timezone updating service. This provides | ||
19 | a one-shot service which can be activated with systemctl to | ||
20 | update the timezone. | ||
21 | ''; | ||
22 | }; | ||
23 | |||
24 | package = lib.mkPackageOption pkgs "tzupdate" { }; | ||
25 | |||
26 | timer.enable = lib.mkOption { | ||
27 | type = lib.types.bool; | ||
28 | default = true; | ||
29 | description = '' | ||
30 | Enable the tzupdate timer to update the timezone automatically. | ||
31 | ''; | ||
32 | }; | ||
33 | |||
34 | timer.interval = lib.mkOption { | ||
35 | type = lib.types.str; | ||
36 | default = "hourly"; | ||
37 | description = '' | ||
38 | The interval at which the tzupdate timer should run. See | ||
39 | {manpage}`systemd.time(7)` to understand the format. | ||
40 | ''; | ||
41 | }; | ||
42 | }; | ||
43 | |||
44 | config = lib.mkIf cfg.enable { | ||
45 | # We need to have imperative time zone management for this to work. | ||
46 | # This will give users an error if they have set an explicit time | ||
47 | # zone, which is better than silently overriding it. | ||
48 | time.timeZone = null; | ||
49 | |||
50 | # We provide a one-shot service that runs at startup once network | ||
51 | # interfaces are up, but we can’t ensure we actually have Internet access | ||
52 | # at that point. It can also be run manually with `systemctl start tzupdate`. | ||
53 | systemd.services.tzupdate = { | ||
54 | description = "tzupdate timezone update service"; | ||
55 | wantedBy = [ "multi-user.target" ]; | ||
56 | wants = [ "network-online.target" ]; | ||
57 | after = [ "network-online.target" ]; | ||
58 | script = '' | ||
59 | timezone="$(${lib.getExe cfg.package} --print-only)" | ||
60 | if [[ -n "$timezone" ]]; then | ||
61 | echo "Setting timezone to '$timezone'" | ||
62 | ${lib.getExe' config.systemd.package "timedatectl"} set-timezone "$timezone" | ||
63 | fi | ||
64 | ''; | ||
65 | |||
66 | serviceConfig = { | ||
67 | Type = "oneshot"; | ||
68 | }; | ||
69 | }; | ||
70 | |||
71 | systemd.timers.tzupdate = { | ||
72 | enable = cfg.timer.enable; | ||
73 | timerConfig = { | ||
74 | OnStartupSec = "30s"; | ||
75 | OnCalendar = cfg.timer.interval; | ||
76 | Persistent = true; | ||
77 | }; | ||
78 | wantedBy = [ "timers.target" ]; | ||
79 | }; | ||
80 | }; | ||
81 | } | ||