-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
nixos/redshift: use config file instead of passing parameters #108625
Conversation
With the following configuration: let
redshiftModuleRefactor = fetchTarball {
url = "https://github.com/thiagokokada/nixpkgs/archive/1bea263ca0937e4d7dd08b85545a2426223c7a79.tar.gz";
sha256 = "0gawqndyj2n23mhsp93rlacrfb8x86rr6hd7d9waknh6fpqbnixr";
};
in{
# Backport module from unstable.
imports = [
"${redshiftModuleRefactor}/nixos/modules/services/x11/redshift.nix"
];
disabledModules = [
"services/x11/redshift.nix"
];
location = {
latitude = -23.5;
longitude = -46.6;
};
services = {
redshift = {
enable = true;
temperature = {
day = 5500;
night = 3700;
};
gamma = {
day = 1.0;
night = 0.8;
};
package = pkgs.unstable.gammastep;
executable = "/bin/gammastep-indicator";
};
};
} I had the following result: ~
❯ systemctl cat --user redshift.service
# /nix/store/8bxr1gi8y9qa8ya4qya88vx97mzdm6g3-unit-redshift.service/redshift.service
[Unit]
Description=Redshift colour temperature adjuster
PartOf=graphical-session.target
[Service]
Environment="LOCALE_ARCHIVE=/nix/store/a2px4kdz1jm03f8ifr1pzir0csfmyrlv-glibc-locales-2.31/lib/locale/locale-archive"
Environment="PATH=/nix/store/z1qvlavy35wanw5k54fvvfffws5bvigj-coreutils-8.31/bin:/nix/store/3fvzxz59gacagpwyzpfdiinc1yv46hw1-findutils-4>
Environment="TZDIR=/nix/store/w1g27pgslf28nh1py1szj7lk4xksdhqq-tzdata-2020c/share/zoneinfo"
ExecStart=/nix/store/f38nk3a9qq415zhar429j7fr7czarvcg-gammastep-2.0.6/bin/gammastep-indicator -c /nix/store/xswxcml4r3fdzviyqwd399lpzsia>
Restart=always
RestartSec=3
~ 12s
❯ cat /nix/store/xswxcml4r3fdzviyqwd399lpzsia3v27-redshift.conf
[general]
temp-day=5500
temp-night=3700
fade=1
location-provider=manual
brightness-day=1.000000
brightness-night=1.000000
gamma-day=1.000000
gamma-night=0.800000
[manual]
lat=-23.500000
lon=-46.600000 For let
redshiftModuleRefactor = fetchTarball {
url = "https://github.com/thiagokokada/nixpkgs/archive/1bea263ca0937e4d7dd08b85545a2426223c7a79.tar.gz";
sha256 = "0gawqndyj2n23mhsp93rlacrfb8x86rr6hd7d9waknh6fpqbnixr";
};
in{
# Backport module from unstable.
imports = [
"${redshiftModuleRefactor}/nixos/modules/services/x11/redshift.nix"
];
disabledModules = [
"services/x11/redshift.nix"
];
location.provider = "geoclue2";
services = {
redshift = {
enable = true;
temperature = {
day = 5500;
night = 3700;
};
gamma = {
day = 1.0;
night = 0.8;
};
package = pkgs.unstable.redshift;
executable = "/bin/redshift-gtk";
};
};
} ❯ systemctl cat --user redshift.service
# /nix/store/9xqyys1w2lb6f9wma2zjjfyhr4hsjsc7-unit-redshift.service/redshift.service
[Unit]
Description=Redshift colour temperature adjuster
PartOf=graphical-session.target
[Service]
Environment="LOCALE_ARCHIVE=/nix/store/a2px4kdz1jm03f8ifr1pzir0csfmyrlv-glibc-locales-2.31/lib/locale/locale-archive"
Environment="PATH=/nix/store/z1qvlavy35wanw5k54fvvfffws5bvigj-coreutils-8.31/bin:/nix/store/3fvzxz59gacagpwyzpfdiinc1yv46hw1-findutils-4>
Environment="TZDIR=/nix/store/w1g27pgslf28nh1py1szj7lk4xksdhqq-tzdata-2020c/share/zoneinfo"
ExecStart=/nix/store/kx8r729wmn9nsm0plqiqv6gvkiah8jwy-redshift-1.12/bin/redshift-gtk -c /nix/store/6ffjf4pbb68ffx6xr0hy2dcjg5rkyi3x-reds>
Restart=always
RestartSec=3
~
❯ cat /nix/store/6ffjf4pbb68ffx6xr0hy2dcjg5rkyi3x-redshift.conf
[redshift]
temp-day=5500
temp-night=3700
fade=1
location-provider=geoclue2
brightness-day=1.000000
brightness-night=1.000000
gamma-day=1.000000
gamma-night=0.800000
|
CC @yegortimoshenko @globin @primeos (redshift/gammastep package maintainers). Also @sumnerevans @infinisil @michaelpj (last people to touch this module). |
type = types.float; | ||
default = 1.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also technically a breaking change. I can document it in release notes if necessary.
sectionString = if strings.hasInfix "gammastep" cfg.executable | ||
# https://gitlab.com/chinstrap/gammastep/-/commit/1608ed61154cc652b087e85c4ce6125643e76e2f | ||
then "[general]" | ||
else "[redshift]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really necessary since gammastep
still supports [redshift]
, but this avoids a warning at startup.
Not every option is exposed by redshift/gammastep parameters, for example gamma options are only exposed in configuration file. So this PR refactors this module to generate a configuration file and pass it to the redshift/gammastep using -c parameter. Also, it implements fade/gamma options not available in the previous version of this module (since it was not exposed by parameters). This is a slightly breaking change, since extraOptions was renamed to extraConfig and now accept a attribute set instead of a list of strings.
With the changes in 460e276, the following config file: {
location.provider = "geoclue2";
services = {
redshift = {
enable = true;
temperature = {
day = 5500;
night = 3700;
};
gamma = {
day = 1.0;
night = 0.8;
};
package = pkgs.unstable.redshift;
executable = "/bin/redshift-gtk";
extraConfig = {
randr = {
display = 0;
};
};
};
};
}
This worked great! Thanks for the suggestion @sumnerevans. Can you review again? |
type = types.listOf types.str; | ||
default = []; | ||
example = [ "-v" "-m randr" ]; | ||
extraConfig = mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed because this is technically not an option anymore, and extraConfig
seems to be the more standard name for this.
RestartSec = 3; | ||
Restart = "always"; | ||
Restart = "on-failure"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This avoids the service to keep restarting in case of an error in config (that may happen for example when setting a wrong extraConfig
value).
I don't believe I'm a maintainer for redshift nor do I use redshift locally anymore. Anyway if you're going to generate a configuration file it might be better to convert it to use a structured attribute set (i.e. If you don't know what I'm talking about, you can probably take a reference from https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/x11/picom.nix#L237. Nevermind you are using it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me. Not quite sure what about the gamma configuration though, it looks like it needs an external dependency (gammastep
) to work, though if it doesn't break the configuration parsing it's probably fine (though it will probably fall under unexpected behavior).
Nothing else for me to note except nitpicks which probably don't matter. Doesn't break system evaluation on my end.
You can probably put the entire configuration inside extraConfig
but I don't think it would provide any extra benefit unless you are using nixos-option
to view the attribute set.
BTW, Edit: Looking at gamma, never knew it supported |
see #50979 for prior art |
Redshift support setting each color channel individually in the following format: "0.8:07:0.8". So support this case too. Also, improve type checking in `extraConfig`.
Commit 36156ba adds support for setting I think this PR is pretty much ready to merge.
Huh... I think this other proposal is kinda abandoned? Well, if the original author still wants to merge I am okay with it too, but I think this PR is ready to merge and the other one still needs some fixes right? Anyway, it helped to improve the types of |
A few conventions that we use would include calling |
I think this will probably be my last bump, since I will probably rewrite this module in the future: NixOS/nixpkgs#108625 (comment)
@aanderse Didn't know we had a RFC for this (it is not merged and I didn't find it in https://github.com/NixOS/rfcs/, had to look on the open PRs). TIL. I was trying to keep this module was similar as the current module breaking as little as possible, but I think this RFC points is fair. Following it would mean probably a completely different module as the current one, and I think this is kinda what #50979 is. Well, will follow the #50979 PR for now and if the author doesn't answer in one or two weeks, I can probably try to open another PR following more closely RFC 42. |
BTW, should I close this PR or is there still interest in merging it? |
Let's wait and see if the other PR picks up or not. |
Asking more because I won't adapt this PR to follow RFC 42 since this will probably would be better made in another PR (it will be a full rewrite anyway). So if RFC 42 support is a must I don't see many reasons to keep this open. |
Please never mistake my opinions for a "must" 😆 |
Ok, so I will keep this open and if the maintainers of the module thinks this is good enough they can go and approve/merge. BTW, for me it is in a good enough state (RFC 42 really seems to make things more elegant, but I am using this module in my configuration and it works good enough for me). |
Substitute PR: #108739. |
Motivation for this change
Not every option is exposed by
redshift
/gammastep
parameters, for example gamma options are only exposed in configuration file. So this PR refactors this module to generate a configuration file and pass it to theredshift
/gammastep
using -c parameter.Also, it implements fade/gamma options not available in the previous version of this module (since it was not exposed by parameters).
This is a slightly breaking change, since
extraOptions
was renamed toextraConfig
and now accept a attribute set instead of a list of stringThings done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)