1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8
9 tzdir = "${pkgs.tzdata}/share/zoneinfo";
10 nospace = str: lib.filter (c: c == " ") (lib.stringToCharacters str) == [ ];
11 timezone = lib.types.nullOr (lib.types.addCheck lib.types.str nospace) // {
12 description = "null or string without spaces";
13 };
14
15 lcfg = config.location;
16
17in
18
19{
20 options = {
21
22 time = {
23
24 timeZone = lib.mkOption {
25 default = null;
26 type = timezone;
27 example = "America/New_York";
28 description = ''
29 The time zone used when displaying times and dates. See <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>
30 for a comprehensive list of possible values for this setting.
31
32 If null, the timezone will default to UTC and can be set imperatively
33 using timedatectl.
34 '';
35 };
36
37 hardwareClockInLocalTime = lib.mkOption {
38 default = false;
39 type = lib.types.bool;
40 description = "If set, keep the hardware clock in local time instead of UTC.";
41 };
42
43 };
44
45 location = {
46
47 latitude = lib.mkOption {
48 type = lib.types.float;
49 description = ''
50 Your current latitude, between
51 `-90.0` and `90.0`. Must be provided
52 along with longitude.
53 '';
54 };
55
56 longitude = lib.mkOption {
57 type = lib.types.float;
58 description = ''
59 Your current longitude, between
60 between `-180.0` and `180.0`. Must be
61 provided along with latitude.
62 '';
63 };
64
65 provider = lib.mkOption {
66 type = lib.types.enum [
67 "manual"
68 "geoclue2"
69 ];
70 default = "manual";
71 description = ''
72 The location provider to use for determining your location. If set to
73 `manual` you must also provide latitude/longitude.
74 '';
75 };
76
77 };
78 };
79
80 config = {
81
82 environment.sessionVariables.TZDIR = "/etc/zoneinfo";
83
84 services.geoclue2.enable = lib.mkIf (lcfg.provider == "geoclue2") true;
85
86 # This way services are restarted when tzdata changes.
87 systemd.globalEnvironment.TZDIR = tzdir;
88
89 systemd.services.systemd-timedated.environment = lib.optionalAttrs (config.time.timeZone != null) {
90 NIXOS_STATIC_TIMEZONE = "1";
91 };
92
93 environment.etc =
94 {
95 zoneinfo.source = tzdir;
96 }
97 // lib.optionalAttrs (config.time.timeZone != null) {
98 localtime.source = "/etc/zoneinfo/${config.time.timeZone}";
99 localtime.mode = "direct-symlink";
100 };
101 };
102
103}