From 9323f2f5734877427e3fa5d2175cfe63bf86c03c Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Wed, 8 Jan 2020 00:38:19 +0100 Subject: [PATCH] time: Add timeZone option --- modules/module-list.nix | 1 + modules/time.nix | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 modules/time.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 07b1b56..781ed11 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -11,6 +11,7 @@ ./environment/session-init.nix ./home-manager.nix ./nixpkgs.nix + ./time.nix ./user.nix ./version.nix diff --git a/modules/time.nix b/modules/time.nix new file mode 100644 index 0000000..d36572c --- /dev/null +++ b/modules/time.nix @@ -0,0 +1,57 @@ +# Copyright (c) 2019-2020, see AUTHORS. Licensed under MIT License, see LICENSE. + +# Inspired by +# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/config/locale.nix +# (Copyright (c) 2003-2019 Eelco Dolstra and the Nixpkgs/NixOS contributors, +# licensed under MIT License as well) + +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.time; + + tzdir = "${pkgs.tzdata}/share/zoneinfo"; + nospace = str: filter (c: c == " ") (stringToCharacters str) == []; + timezoneType = types.nullOr (types.addCheck types.str nospace) + // { description = "null or string without spaces"; }; +in + +{ + + ###### interface + + options = { + + time.timeZone = mkOption { + default = null; + type = timezoneType; + example = "America/New_York"; + description = '' + The time zone used when displaying times and dates. See + for a comprehensive list of possible values for this setting. + If null, the timezone will default to UTC. + ''; + }; + + }; + + + ###### implementation + + config = { + + environment = { + etc = + { zoneinfo.source = tzdir; } + // optionalAttrs (config.time.timeZone != null) { + localtime.source = "/etc/zoneinfo/${config.time.timeZone}"; + }; + + sessionVariables.TZDIR = "/etc/zoneinfo"; + }; + + }; +}