Skip to content

Commit

Permalink
timezone.nix -> locale.nix
Browse files Browse the repository at this point in the history
Also includes geolocation information abstracted from redshift.nix
  • Loading branch information
eadwu committed Aug 12, 2019
1 parent c5592fa commit c4de0bf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ let
timezone = types.nullOr (types.addCheck types.str nospace)
// { description = "null or string without spaces"; };

lcfg = config.location;

in

{
Expand Down Expand Up @@ -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 = {

environment.sessionVariables.TZDIR = "/etc/zoneinfo";

services.geoclue2.enable = mkIf (lcfg.provider == "geoclue2") true;

# This way services are restarted when tzdata changes.
systemd.globalEnvironment.TZDIR = tzdir;

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
./config/iproute2.nix
./config/krb5/default.nix
./config/ldap.nix
./config/locale.nix
./config/malloc.nix
./config/networking.nix
./config/no-x-libs.nix
Expand All @@ -33,7 +34,6 @@
./config/system-environment.nix
./config/system-path.nix
./config/terminfo.nix
./config/timezone.nix
./config/unix-odbc-drivers.nix
./config/users-groups.nix
./config/vpnc.nix
Expand Down
14 changes: 14 additions & 0 deletions nixos/modules/rename.nix
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@ with lib;
(mkRenamedOptionModule [ "networking" "extraResolvconfConf" ] [ "networking" "resolvconf" "extraConfig" ])
(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"
"jsonExporter" "minioExporter" "nginxExporter" "nodeExporter"
"snmpExporter" "unifiExporter" "varnishExporter" ]
Expand Down
58 changes: 8 additions & 50 deletions nixos/modules/services/x11/redshift.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with lib;
let

cfg = config.services.redshift;
lcfg = config.location;

in {

Expand All @@ -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 = {
day = mkOption {
type = types.int;
Expand Down Expand Up @@ -106,33 +78,19 @@ in {
};

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
environment.systemPackages = [ cfg.package ];

services.geoclue2 = mkIf (cfg.provider == "geoclue2") {
enable = true;
appConfig."redshift" = {
isAllowed = true;
isSystem = true;
};
services.geoclue2.appConfig."redshift" = {
isAllowed = true;
isSystem = true;
};

systemd.user.services.redshift =
systemd.user.services.redshift =
let
providerString =
if cfg.provider == "manual"
then "${cfg.latitude}:${cfg.longitude}"
else cfg.provider;
providerString = if lcfg.provider == "manual"
then "${toString lcfg.latitude}:${toString lcfg.longitude}"
else lcfg.provider;
in
{
description = "Redshift colour temperature adjuster";
Expand Down

0 comments on commit c4de0bf

Please sign in to comment.