Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redshift add early startup option, rewrite to use toINI and add more options #57975

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 77 additions & 10 deletions nixos/modules/services/x11/redshift.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ in {
'';
};

method = mkOption {
type = types.nullOr (types.enum [ "drm" "randr" "vidmode" "dummy" ]);
default = null;
description = ''
Method to use for making the adjustments.
'';
};

methodOptions = mkOption {
type = types.attrsOf types.str;
default = {};
description = ''
Additional method specific options to pass to redshift.
'';
example = {
crtc = "0";
};
};

temperature = {
day = mkOption {
type = types.int;
Expand Down Expand Up @@ -85,6 +104,16 @@ in {
};
};

fade = mkOption {
type = types.nullOr types.bool;
default = null;
apply = lib.mapNullable (f: if f then 1 else 0);
description = ''
Enable fading between color temperatures when redshift
starts or stops.
'';
};

package = mkOption {
type = types.package;
default = pkgs.redshift;
Expand All @@ -94,6 +123,15 @@ in {
'';
};

extraConfig = mkOption {
type = types.attrsOf types.string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type = types.attrsOf types.string;
type = types.attrsOf types.lines;

default = {};
description = ''
Additional options to append to the [redshift]
section of the configuration file (see man redshift).
'';
};

extraOptions = mkOption {
type = types.listOf types.str;
default = [];
Expand All @@ -103,6 +141,16 @@ in {
<command>redshift</command>.
'';
};

earlyStartup = mkOption {
type = types.bool;
default = false;
description = ''
Start redshift before the graphical interface is up.
This will automatically set the method to "drm".
'';
};

};

config = mkIf cfg.enable {
Expand All @@ -121,23 +169,42 @@ in {

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

services.redshift.method = mkIf cfg.earlyStartup "drm";

systemd.user.services.redshift =
let
providerString =
if cfg.provider == "manual"
then "${cfg.latitude}:${cfg.longitude}"
else cfg.provider;
in
allOptions = {
redshift = {
temp-day = cfg.temperature.day;
temp-night = cfg.temperature.night;
brightness-day = cfg.brightness.day;
brightness-night = cfg.brightness.night;
location-provider = cfg.provider;
adjustment-method = cfg.method;
fade = cfg.fade;
} // cfg.extraConfig;
manual = {
lat = cfg.latitude;
lon = cfg.longitude;
};
} // lib.optionalAttrs (!builtins.isNull cfg.method) {
"${cfg.method}" = cfg.methodOptions;
};
configFile = lib.generators.toINI {}
( lib.filterAttrsRecursive (n: v: v != null) allOptions );
target =
if cfg.earlyStartup
then "basic.target"
else "graphical-session.target";
in
{
description = "Redshift colour temperature adjuster";
wantedBy = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
wantedBy = [ target ];
partOf = [ target ];
serviceConfig = {
ExecStart = ''
${cfg.package}/bin/redshift \
-l ${providerString} \
-t ${toString cfg.temperature.day}:${toString cfg.temperature.night} \
-b ${toString cfg.brightness.day}:${toString cfg.brightness.night} \
-c ${builtins.toFile "redshift-config" configFile} \
${lib.strings.concatStringsSep " " cfg.extraOptions}
'';
RestartSec = 3;
Expand Down