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
12in
13
14{
15 options = {
16
17 time = {
18
19 timeZone = mkOption {
20 default = null;
21 type = timezone;
22 example = "America/New_York";
23 description = ''
24 The time zone used when displaying times and dates. See <link
25 xlink:href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones"/>
26 for a comprehensive list of possible values for this setting.
27
28 If null, the timezone will default to UTC and can be set imperatively
29 using timedatectl.
30 '';
31 };
32
33 hardwareClockInLocalTime = mkOption {
34 default = false;
35 type = types.bool;
36 description = "If set, keep the hardware clock in local time instead of UTC.";
37 };
38
39 };
40 };
41
42 config = {
43
44 environment.sessionVariables.TZDIR = "/etc/zoneinfo";
45
46 # This way services are restarted when tzdata changes.
47 systemd.globalEnvironment.TZDIR = tzdir;
48
49 systemd.services.systemd-timedated.environment = lib.optionalAttrs (config.time.timeZone != null) { NIXOS_STATIC_TIMEZONE = "1"; };
50
51 environment.etc = {
52 zoneinfo.source = tzdir;
53 } // lib.optionalAttrs (config.time.timeZone != null) {
54 localtime.source = "/etc/zoneinfo/${config.time.timeZone}";
55 localtime.mode = "direct-symlink";
56 };
57 };
58
59}