timezone.nix -> locale.nix

Also includes geolocation information abstracted from redshift.nix
This commit is contained in:
Edmund Wu 2019-07-16 16:21:55 -04:00
parent c5592fabba
commit c4de0bf492
No known key found for this signature in database
GPG Key ID: 76AA3F9F2BD3E3A0
4 changed files with 58 additions and 51 deletions

View File

@ -9,6 +9,8 @@ let
timezone = types.nullOr (types.addCheck types.str nospace) timezone = types.nullOr (types.addCheck types.str nospace)
// { description = "null or string without spaces"; }; // { description = "null or string without spaces"; };
lcfg = config.location;
in in
{ {
@ -37,12 +39,45 @@ in
}; };
}; };
location = {
latitude = mkOption {
type = types.float;
description = ''
Your current latitude, between
<literal>-90.0</literal> and <literal>90.0</literal>. Must be provided
along with longitude.
'';
};
longitude = mkOption {
type = types.float;
description = ''
Your current longitude, between
between <literal>-180.0</literal> and <literal>180.0</literal>. Must be
provided along with latitude.
'';
};
provider = mkOption {
type = types.enum [ "manual" "geoclue2" ];
default = "manual";
description = ''
The location provider to use for determining your location. If set to
<literal>manual</literal> you must also provide latitude/longitude.
'';
};
};
}; };
config = { config = {
environment.sessionVariables.TZDIR = "/etc/zoneinfo"; environment.sessionVariables.TZDIR = "/etc/zoneinfo";
services.geoclue2.enable = mkIf (lcfg.provider == "geoclue2") true;
# This way services are restarted when tzdata changes. # This way services are restarted when tzdata changes.
systemd.globalEnvironment.TZDIR = tzdir; systemd.globalEnvironment.TZDIR = tzdir;

View File

@ -20,6 +20,7 @@
./config/iproute2.nix ./config/iproute2.nix
./config/krb5/default.nix ./config/krb5/default.nix
./config/ldap.nix ./config/ldap.nix
./config/locale.nix
./config/malloc.nix ./config/malloc.nix
./config/networking.nix ./config/networking.nix
./config/no-x-libs.nix ./config/no-x-libs.nix
@ -33,7 +34,6 @@
./config/system-environment.nix ./config/system-environment.nix
./config/system-path.nix ./config/system-path.nix
./config/terminfo.nix ./config/terminfo.nix
./config/timezone.nix
./config/unix-odbc-drivers.nix ./config/unix-odbc-drivers.nix
./config/users-groups.nix ./config/users-groups.nix
./config/vpnc.nix ./config/vpnc.nix

View File

@ -257,6 +257,20 @@ with lib;
(mkRenamedOptionModule [ "networking" "extraResolvconfConf" ] [ "networking" "resolvconf" "extraConfig" ]) (mkRenamedOptionModule [ "networking" "extraResolvconfConf" ] [ "networking" "resolvconf" "extraConfig" ])
(mkRenamedOptionModule [ "networking" "resolvconfOptions" ] [ "networking" "resolvconf" "extraOptions" ]) (mkRenamedOptionModule [ "networking" "resolvconfOptions" ] [ "networking" "resolvconf" "extraOptions" ])
# Redshift
(mkChangedOptionModule [ "services" "redshift" "latitude" ] [ "location" "latitude" ]
(config:
let value = getAttrFromPath [ "services" "redshift" "latitude" ] config;
in if value == null then
throw "services.redshift.latitude is set to null, you can remove this"
else builtins.fromJSON value))
(mkChangedOptionModule [ "services" "redshift" "longitude" ] [ "location" "longitude" ]
(config:
let value = getAttrFromPath [ "services" "redshift" "longitude" ] config;
in if value == null then
throw "services.redshift.longitude is set to null, you can remove this"
else builtins.fromJSON value))
] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter" ] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter"
"jsonExporter" "minioExporter" "nginxExporter" "nodeExporter" "jsonExporter" "minioExporter" "nginxExporter" "nodeExporter"
"snmpExporter" "unifiExporter" "varnishExporter" ] "snmpExporter" "unifiExporter" "varnishExporter" ]

View File

@ -5,6 +5,7 @@ with lib;
let let
cfg = config.services.redshift; cfg = config.services.redshift;
lcfg = config.location;
in { in {
@ -18,35 +19,6 @@ in {
''; '';
}; };
latitude = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Your current latitude, between
<literal>-90.0</literal> and <literal>90.0</literal>. Must be provided
along with longitude.
'';
};
longitude = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Your current longitude, between
between <literal>-180.0</literal> and <literal>180.0</literal>. Must be
provided along with latitude.
'';
};
provider = mkOption {
type = types.enum [ "manual" "geoclue2" ];
default = "manual";
description = ''
The location provider to use for determining your location. If set to
<literal>manual</literal> you must also provide latitude/longitude.
'';
};
temperature = { temperature = {
day = mkOption { day = mkOption {
type = types.int; type = types.int;
@ -106,33 +78,19 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [
{
assertion =
if cfg.provider == "manual"
then (cfg.latitude != null && cfg.longitude != null)
else (cfg.latitude == null && cfg.longitude == null);
message = "Latitude and longitude must be provided together, and with provider set to null.";
}
];
# needed so that .desktop files are installed, which geoclue cares about # needed so that .desktop files are installed, which geoclue cares about
environment.systemPackages = [ cfg.package ]; environment.systemPackages = [ cfg.package ];
services.geoclue2 = mkIf (cfg.provider == "geoclue2") { services.geoclue2.appConfig."redshift" = {
enable = true; isAllowed = true;
appConfig."redshift" = { isSystem = true;
isAllowed = true;
isSystem = true;
};
}; };
systemd.user.services.redshift = systemd.user.services.redshift =
let let
providerString = providerString = if lcfg.provider == "manual"
if cfg.provider == "manual" then "${toString lcfg.latitude}:${toString lcfg.longitude}"
then "${cfg.latitude}:${cfg.longitude}" else lcfg.provider;
else cfg.provider;
in in
{ {
description = "Redshift colour temperature adjuster"; description = "Redshift colour temperature adjuster";