2024-12-10 20:26:33 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2024-12-31 14:04:42 -08:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2013-10-21 17:08:42 +01:00
|
|
|
let
|
2015-09-06 03:57:00 +02:00
|
|
|
|
2013-10-21 17:08:42 +01:00
|
|
|
cfg = config.services.redshift;
|
2019-07-16 16:21:55 -04:00
|
|
|
lcfg = config.location;
|
2013-10-21 17:08:42 +01:00
|
|
|
|
2024-12-10 20:26:33 +01:00
|
|
|
in
|
|
|
|
{
|
2015-09-06 03:57:00 +02:00
|
|
|
|
2019-09-15 18:25:40 +02:00
|
|
|
imports = [
|
2024-12-31 14:04:42 -08:00
|
|
|
(mkChangedOptionModule [ "services" "redshift" "latitude" ] [ "location" "latitude" ] (
|
2024-12-10 20:26:33 +01:00
|
|
|
config:
|
|
|
|
let
|
2024-12-31 14:04:42 -08:00
|
|
|
value = getAttrFromPath [ "services" "redshift" "latitude" ] config;
|
2024-12-10 20:26:33 +01:00
|
|
|
in
|
|
|
|
if value == null then
|
|
|
|
throw "services.redshift.latitude is set to null, you can remove this"
|
|
|
|
else
|
|
|
|
builtins.fromJSON value
|
|
|
|
))
|
2024-12-31 14:04:42 -08:00
|
|
|
(mkChangedOptionModule [ "services" "redshift" "longitude" ] [ "location" "longitude" ] (
|
2024-12-10 20:26:33 +01:00
|
|
|
config:
|
|
|
|
let
|
2024-12-31 14:04:42 -08:00
|
|
|
value = getAttrFromPath [ "services" "redshift" "longitude" ] config;
|
2024-12-10 20:26:33 +01:00
|
|
|
in
|
|
|
|
if value == null then
|
|
|
|
throw "services.redshift.longitude is set to null, you can remove this"
|
|
|
|
else
|
|
|
|
builtins.fromJSON value
|
|
|
|
))
|
2024-12-31 14:04:42 -08:00
|
|
|
(mkRenamedOptionModule [ "services" "redshift" "provider" ] [ "location" "provider" ])
|
2019-09-15 18:25:40 +02:00
|
|
|
];
|
|
|
|
|
2015-09-06 03:57:00 +02:00
|
|
|
options.services.redshift = {
|
2024-12-31 14:04:42 -08:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
2013-10-21 17:08:42 +01:00
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2015-09-06 03:57:00 +02:00
|
|
|
Enable Redshift to change your screen's colour temperature depending on
|
|
|
|
the time of day.
|
|
|
|
'';
|
2013-10-21 17:08:42 +01:00
|
|
|
};
|
|
|
|
|
2015-09-06 03:57:00 +02:00
|
|
|
temperature = {
|
2024-12-31 14:04:42 -08:00
|
|
|
day = mkOption {
|
|
|
|
type = types.int;
|
2015-09-06 03:57:00 +02:00
|
|
|
default = 5500;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2015-11-10 22:28:37 -08:00
|
|
|
Colour temperature to use during the day, between
|
2022-07-28 23:19:15 +02:00
|
|
|
`1000` and `25000` K.
|
2015-09-06 03:57:00 +02:00
|
|
|
'';
|
2013-10-21 17:08:42 +01:00
|
|
|
};
|
2024-12-31 14:04:42 -08:00
|
|
|
night = mkOption {
|
|
|
|
type = types.int;
|
2015-09-06 03:57:00 +02:00
|
|
|
default = 3700;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2015-11-10 22:28:37 -08:00
|
|
|
Colour temperature to use at night, between
|
2022-07-28 23:19:15 +02:00
|
|
|
`1000` and `25000` K.
|
2015-09-06 03:57:00 +02:00
|
|
|
'';
|
2014-02-13 11:11:14 -05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-09-06 03:57:00 +02:00
|
|
|
brightness = {
|
2024-12-31 14:04:42 -08:00
|
|
|
day = mkOption {
|
|
|
|
type = types.str;
|
2015-09-06 03:57:00 +02:00
|
|
|
default = "1";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2015-09-06 03:57:00 +02:00
|
|
|
Screen brightness to apply during the day,
|
2022-07-28 23:19:15 +02:00
|
|
|
between `0.1` and `1.0`.
|
2015-09-06 03:57:00 +02:00
|
|
|
'';
|
2014-02-13 11:11:14 -05:00
|
|
|
};
|
2024-12-31 14:04:42 -08:00
|
|
|
night = mkOption {
|
|
|
|
type = types.str;
|
2015-09-06 03:57:00 +02:00
|
|
|
default = "1";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2015-09-06 03:57:00 +02:00
|
|
|
Screen brightness to apply during the night,
|
2022-07-28 23:19:15 +02:00
|
|
|
between `0.1` and `1.0`.
|
2015-09-06 03:57:00 +02:00
|
|
|
'';
|
2013-10-21 17:08:42 +01:00
|
|
|
};
|
|
|
|
};
|
2015-07-26 23:32:43 +02:00
|
|
|
|
2024-12-31 14:04:42 -08:00
|
|
|
package = mkPackageOption pkgs "redshift" { };
|
2015-09-06 03:57:00 +02:00
|
|
|
|
2024-12-31 14:04:42 -08:00
|
|
|
executable = mkOption {
|
|
|
|
type = types.str;
|
2020-09-28 11:01:38 -06:00
|
|
|
default = "/bin/redshift";
|
|
|
|
example = "/bin/redshift-gtk";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2020-09-28 11:01:38 -06:00
|
|
|
Redshift executable to use within the package.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-12-31 14:04:42 -08:00
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2024-12-10 20:26:33 +01:00
|
|
|
default = [ ];
|
|
|
|
example = [
|
|
|
|
"-v"
|
|
|
|
"-m randr"
|
|
|
|
];
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2015-09-06 03:57:00 +02:00
|
|
|
Additional command-line arguments to pass to
|
2022-07-28 23:19:15 +02:00
|
|
|
{command}`redshift`.
|
2015-09-06 03:57:00 +02:00
|
|
|
'';
|
2015-07-26 23:32:43 +02:00
|
|
|
};
|
2013-10-21 17:08:42 +01:00
|
|
|
};
|
|
|
|
|
2024-12-31 14:04:42 -08:00
|
|
|
config = mkIf cfg.enable {
|
2018-08-09 15:17:43 +01:00
|
|
|
# needed so that .desktop files are installed, which geoclue cares about
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
services.geoclue2.appConfig.redshift = {
|
2019-07-16 16:21:55 -04:00
|
|
|
isAllowed = true;
|
|
|
|
isSystem = true;
|
2019-06-03 18:03:30 +01:00
|
|
|
};
|
2017-10-21 06:14:40 +01:00
|
|
|
|
2019-07-16 16:21:55 -04:00
|
|
|
systemd.user.services.redshift =
|
2024-12-10 20:26:33 +01:00
|
|
|
let
|
|
|
|
providerString =
|
|
|
|
if lcfg.provider == "manual" then
|
|
|
|
"${toString lcfg.latitude}:${toString lcfg.longitude}"
|
|
|
|
else
|
|
|
|
lcfg.provider;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
description = "Redshift colour temperature adjuster";
|
|
|
|
wantedBy = [ "graphical-session.target" ];
|
|
|
|
partOf = [ "graphical-session.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
|
|
|
${cfg.package}${cfg.executable} \
|
|
|
|
-l ${providerString} \
|
|
|
|
-t ${toString cfg.temperature.day}:${toString cfg.temperature.night} \
|
|
|
|
-b ${toString cfg.brightness.day}:${toString cfg.brightness.night} \
|
|
|
|
${lib.strings.concatStringsSep " " cfg.extraOptions}
|
|
|
|
'';
|
|
|
|
RestartSec = 3;
|
|
|
|
Restart = "always";
|
|
|
|
};
|
2015-12-21 03:13:18 +01:00
|
|
|
};
|
2013-10-21 17:08:42 +01:00
|
|
|
};
|
2015-09-06 03:57:00 +02:00
|
|
|
|
2013-10-21 17:08:42 +01:00
|
|
|
}
|