-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature request: Add support for Bernstein chained wrappers #18
Comments
While I don't really use these programs, the usecase is definitely interesting, and would fit nicely in the interface of wrapper-manager. I think we can already start discussing the api for it, maybe something like this?
|
Oh yes! That looks sensible. Also worth considering is whether the wrapper itself has optional command line flags that the user might want to inject before the wrapped command.
So it would be ergonomic if the API was flexible enough to account for both without needing to first wrap the two input derivations separately. Something like this: wrappers.my-chromium = {
basePackage = pkgs.tmux;
flags = [ "--kiosk" ];
# More standard wrapping functionality options here
...
under = pkgs.boxxy;
underFlags = [ "--immutable" ];
}; To complicate it further, it's good form to include a
While most programs of this style do support Say we add a new boolean attr {
inherit basePackage flags ... under noHyphenSeparator;
underFlags = underFlags ++ (lib.lists.optional
(!noHyphenSeparator) "--");
} Then again, it's not a huge deal when it comes to nix, since the path of the |
I feel like we could set the double hyphen unconditionally and wait for somebody to complain about that |
Good point! Agreed 😄 |
If you want to write the implementation in a separate PR I'd be happy to review. But I have other projects on the top of my stack for me to implement this. |
Would this feature also allow running something like |
While the common use case for
nixkpkgs.makeWrapper
is to add arguments to the end of a command line string or change environment variables, I think it would make sense to also provide plumbing for creating "Bernstein chain"-style wrappers. These are the ones where you pass your program as an argument to a wrapping command, which then invokes it for you in some way. Like so:Instead of
you run
Common examples are
su
,sudo
andssh
, but more relevant for Nix andhome-manager
are programs likenixGL
orboxxy
. The first of which in particular seems to have a recurring demand within the community for a good way to create wrappers:While the above threads have many proposed solutions, I think it would be nice to consolidate efforts, especially with the special care needed to ensure things like
.desktop
files point to the wrapper script (something which is overlooked in at least some of said solutions).Findings and my suggested solution
It's not at all obvious at first, but Nix's
nixpkgs.makeWrapper
does allow you to write these sorts of prefix wrappers, if you use themakeWrapper
/makeShellWrapper
function rather than the more specializedwrapProgram
/wrapShellProgram
. These versions allow you to specify a different name of the wrapped program than the one you are wrapping.Here is an example I wrote to wrap programs with
boxxy
on my machine (though it is really generic enough to factor the actual wrapper program out already):The important line is
Let's instantiate it with a concrete program to be wrapped, just to aid in the discussion:
To summarize what it does, since it is a bit backwards compared to normal usage of the library, it creates a wrapper script (
$out/bin/chromium
) -- not with the originalchromium
binary as input, but with the wrapper one. Then, it adds the originalchromium
binary as the first argument to this command.Since you already use the
makeWrapper
package inwrapper-manager
, I think it would be elegant to reuse its functionality like this. For example by providing a version of the derivation withmakeWrapper
instead ofwrapProgram
, plus a convenience function that then pre-fills the output name, argv0 and the first argument like above.The text was updated successfully, but these errors were encountered: