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

Add ability to configure executable for redshift service #99019

Merged
merged 1 commit into from Nov 3, 2020

Conversation

sumnerevans
Copy link
Member

@sumnerevans sumnerevans commented Sep 28, 2020

Motivation for this change

The redshift package provides a redshift executable as well as a redshift-gtk executable, however the redshift module only uses redshift and provides no option to change the executable.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Added ability to configure the executable that the redshift service
uses.
@sumnerevans
Copy link
Member Author

@infinisil I have seen you on other reviews for redshift. Can you talke a look or do I need somebody else to look?

@sumnerevans
Copy link
Member Author

@yegortimoshenko @globin it looks like you are listed as maintainers for redshift. Is this something that you could review? Thanks!

@rissson
Copy link
Member

rissson commented Oct 8, 2020

A better way of doing this I think, would simply to have an option that can but set to something like this: "${pkgs.redshift}/bin/redshift"

@sumnerevans
Copy link
Member Author

@rissson is your suggestion to make the executable parameter default to ${cfg.package}/bin/redshift and then use that in the ExecStart?

Do you know of any other examples of something similar to this? (I'm new to this, so I don't really know where to look.)

@rissson
Copy link
Member

rissson commented Oct 9, 2020

Yes, that's what I meant. I wasn't able to find another example of this, I'll leave a review as an example of how it could be done.

@FlorianFranzen FlorianFranzen mentioned this pull request Oct 17, 2020
10 tasks
Copy link
Member

@raboof raboof left a comment

Choose a reason for hiding this comment

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

This is quite nice!

Does it need to be so generic? Would there be a use case for any other variation than can be achieved with a boolean 'gtk' option?

In any case 👍

@sumnerevans
Copy link
Member Author

I guess it does not have to be so generic. I can change over to having a useGtk option maybe.

@infinisil
Copy link
Member

Actually, what if we did it like the shells: Have pkgs.redshift.binaryPath be "/bin/redshift" by setting that in a passthru. Then this module can just use ${cfg.package}${cfg.package.binaryPath or "/bin/redshift"} as the executable, and we won't need an additional option, meaning this is a one-line change. The user could then make it use the gtk version with:

{
  package = pkgs.redshift // { binaryPath = "/bin/redshift-gtk"; };
}

How the shells do this:

passthru = {
shellPath = "/bin/bash";
};
# Returns a system path for a given shell package
toShellPath = shell:
if types.shellPackage.check shell then
"/run/current-system/sw${shell.shellPath}"

@aanderse
Copy link
Member

@infinisil I like how your suggestion is generic and scales. Surely redshift won't be the last time we see this issue.

@sumnerevans
Copy link
Member Author

@infinisil I like that idea, but I'm a bit confused as to why an option is not required? Also, do I have to add that passthru set somewhere?

@jhgarner
Copy link

jhgarner commented Nov 2, 2020

As someone who currently uses a bit of a hack to accomplish this, I'm excited to see this get merged! I was wondering what the benefits were to the passthru solution vs having the executable option. It seems like the passthru option suffers from being non-discoverable since it would never show up when searching through available options on the Redshift module. Would the lack of discoverability be a big benefit for just using the executable option?

@infinisil
Copy link
Member

@sumnerevans This is all that's required for that to work:

diff --git a/nixos/modules/services/x11/redshift.nix b/nixos/modules/services/x11/redshift.nix
index 21b0b33553a..77a5eb3b32b 100644
--- a/nixos/modules/services/x11/redshift.nix
+++ b/nixos/modules/services/x11/redshift.nix
@@ -114,7 +114,7 @@ in {
       partOf = [ "graphical-session.target" ];
       serviceConfig = {
         ExecStart = ''
-          ${cfg.package}/bin/redshift \
+          ${cfg.package}${cfg.package.binaryPath or "/bin/redshift"} \
             -l ${providerString} \
             -t ${toString cfg.temperature.day}:${toString cfg.temperature.night} \
             -b ${toString cfg.brightness.day}:${toString cfg.brightness.night} \

With this you could set this in your configuration.nix:

{ pkgs, ... }: {
  services.redshift.package = pkgs.redshift // { binaryPath = "/bin/redshift-gtk"; };
}

@jhgarner Yeah discoverability won't be great with this. So I think the current approach might be better after all.

In addition, what we need here is different than the shell packages I talked about above: The shell packages have one canonical binary path, meaning users shouldn't ever need to change that binary path. However in redshift's case, there are multiple binaries, and users are expected to switch between them. This is another reason for making this a separate option.

I'll just go ahead and merge this now, I think there are good enough reasons for doing so.

@infinisil infinisil merged commit 8a7ea52 into NixOS:master Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants