summaryrefslogtreecommitdiff
path: root/modules/time/default.nix
blob: 01c4703b03725d8da6da36e3b2c39a2aadd7f39b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.time;

  timeZone = optionalString (cfg.timeZone != null) ''
    if ! systemsetup -listtimezones | grep -q "^ ${cfg.timeZone}$"; then
      echo "${cfg.timeZone} is not a valid timezone. The command 'listtimezones' will show a list of valid time zones." >&2
      false
    fi
    systemsetup -settimezone "${cfg.timeZone}" 2>/dev/null 1>&2
  '';

in

{
  options = {

    time.timeZone = mkOption {
      type = types.nullOr types.str;
      default = null;
      example = "America/New_York";
      description = ''
        The time zone used when displaying times and dates. See <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>
        or run {command}`sudo systemsetup -listtimezones`
        for a comprehensive list of possible values for this setting.
      '';
    };

  };

  config = {

    system.activationScripts.time.text = mkIf (cfg.timeZone != null) ''
      # Set defaults
      echo "configuring time..." >&2

      ${timeZone}
    '';

  };
}