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