at 22.05-pre 2.5 kB view raw
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 = '' 26 The time zone used when displaying times and dates. See <link 27 xlink:href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones"/> 28 for a comprehensive list of possible values for this setting. 29 30 If null, the timezone will default to UTC and can be set imperatively 31 using timedatectl. 32 ''; 33 }; 34 35 hardwareClockInLocalTime = mkOption { 36 default = false; 37 type = types.bool; 38 description = "If set, keep the hardware clock in local time instead of UTC."; 39 }; 40 41 }; 42 43 location = { 44 45 latitude = mkOption { 46 type = types.float; 47 description = '' 48 Your current latitude, between 49 <literal>-90.0</literal> and <literal>90.0</literal>. Must be provided 50 along with longitude. 51 ''; 52 }; 53 54 longitude = mkOption { 55 type = types.float; 56 description = '' 57 Your current longitude, between 58 between <literal>-180.0</literal> and <literal>180.0</literal>. Must be 59 provided along with latitude. 60 ''; 61 }; 62 63 provider = mkOption { 64 type = types.enum [ "manual" "geoclue2" ]; 65 default = "manual"; 66 description = '' 67 The location provider to use for determining your location. If set to 68 <literal>manual</literal> you must also provide latitude/longitude. 69 ''; 70 }; 71 72 }; 73 }; 74 75 config = { 76 77 environment.sessionVariables.TZDIR = "/etc/zoneinfo"; 78 79 services.geoclue2.enable = mkIf (lcfg.provider == "geoclue2") true; 80 81 # This way services are restarted when tzdata changes. 82 systemd.globalEnvironment.TZDIR = tzdir; 83 84 systemd.services.systemd-timedated.environment = lib.optionalAttrs (config.time.timeZone != null) { NIXOS_STATIC_TIMEZONE = "1"; }; 85 86 environment.etc = { 87 zoneinfo.source = tzdir; 88 } // lib.optionalAttrs (config.time.timeZone != null) { 89 localtime.source = "/etc/zoneinfo/${config.time.timeZone}"; 90 localtime.mode = "direct-symlink"; 91 }; 92 }; 93 94}