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