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

nixos/shells-pkgs: added environment.shellPkgs option #110762

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

pasqui23
Copy link
Contributor

Motivation for this change

Nowadays nixpkgs contains several packages containing snippets to be added to shells initializations, however those snippets are often in disparate places and need to read the package before knowing the specific path to be sourced.

This option allow for a programmatic addition of shell snippets, as simply as environment.sessionPackages

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.

@aanderse
Copy link
Member

After a quick read through I'm left wanting an example of when you might use this option. Just out of curiosity.

@pasqui23
Copy link
Contributor Author

@aanderse the reason being that most shell plugins contain the script to be sourced in several non standard locaation and often one need to look at the specific nix file. My approach instead is as easy as environment.systemPackages.
I've also pushed some changes to packages so that they can use the new framework.

@aanderse
Copy link
Member

Oh get it now. Thanks for explaining.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/465

@pasqui23 pasqui23 requested review from sternenseemann, mweinelt and Ma27 and removed request for mweinelt March 6, 2021 10:37
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/485

Copy link
Member

@sternenseemann sternenseemann left a comment

Choose a reason for hiding this comment

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

Cool idea! My thoughts are the following:

  • The code is a bit hard to read. More comments explaining and less aliases for stuff we know would be nice :)
  • I feel like this module is too magic. I'd prefer it if environment.shellPkgs was namespaced per Shell (i. e. environment.shellPkgs.fish, …), alternatively programs."${shell}".shellPkgs` could also be interesting. This would have the following benefits in my eyes:
    • Users generally want to install stuff for a specific shell, not specific stuff for all shell which then only supports one shell anyways.
    • If someone wants to install a zsh package, but uses say fish, with environment.shellPkgs it may be confusing why it didn't work. If it was namespaced we could add an assertion to make sure that doesn't happen or make evaluation fail.
  • The extra output is a neat idea, but also not nice that we duplicate everything effectively. Maybe there is an alternative solution like (ab)using passthru and adding a supportedShells list or something.
  • Needs documentation in the nixpkgs manual, so packagers know how to package a shell package to support this.

Just my 2 cents, let me know what you think on those points!

@pasqui23
Copy link
Contributor Author

@sternenseemann Added documentation ,programs.${sh}.shellPkgs options and clarified the code as you requested.

${lib.concatMapStrings
(
sh: ''
$out/bin/direnv hook ${sh} > $${sh}_interactiveShellInit
Copy link
Member

Choose a reason for hiding this comment

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

$${foo} escapes the ${foo}.

Suggested change
$out/bin/direnv hook ${sh} > $${sh}_interactiveShellInit
$out/bin/direnv hook ${sh} > ''$${sh}_interactiveShellInit

@stale
Copy link

stale bot commented Sep 22, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 22, 2021
@pasqui23
Copy link
Contributor Author

Still developing it

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 22, 2021
@pasqui23
Copy link
Contributor Author

Still waiting on @sternenseemann ,@Ma27 or @mweinelt to review this

Those need to have extra outputs called `${shell}_${phase}` where:
* shell refers to the specific shell it needs to be included (either bash, fish or zsh).
* phase refers to when the file will be sourced, this can be one of:
* * `interactiveShellInit`,if it needs to be included in the interactive shell initialization
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
* * `interactiveShellInit`,if it needs to be included in the interactive shell initialization
* * `interactiveShellInit` if it needs to be included in the interactive shell initialization

Comment on lines +26 to +31
outputs = [ "out" "interactiveShellInit_zsh"];

installPhase = ''
install -Dm0644 fzf-zsh.plugin.zsh $out/share/zsh/plugins/fzf-zsh/fzf-zsh.plugin.zsh
install -Dm0644 fzf-zsh.plugin.zsh $interactiveShellInit_zsh
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be a better design to only have the interactiveShellInit output and subdirectories for bash, fish and zsh. This would also be easier to extend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've chosen this design for a couple of reason:

  1. It allow users of, say, zsh to not pay for fish plugins
  2. It allows programs,zsh,shellPkgs to contain only packages with zsh plugins
  3. In the immediate future I intend to create (either here or on home-manager) a module that allows me to manage zsh plugins to be loaded and managed by zplugin to improve parsing even further.
  4. Especially point 3 require IFD with your design

In short I need to filter plugins by shell without IFD and I can't do that with per shell subdirs

Copy link
Contributor Author

Choose a reason for hiding this comment

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


# replace the build phase to use the GNUMakefile instead
buildPhase = ''
make BASH_PATH=$BASH_PATH
'';

outputs = [ "out" ] ++ map (sh: "${sh}_interactiveShellInit");
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have once the shells at the end and here at the front? Not very consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok now I get it,it was an error

@mweinelt mweinelt removed their request for review November 25, 2021 20:50
@pasqui23 pasqui23 force-pushed the shplugins branch 5 times, most recently from 0d0fae3 to 85fc860 Compare November 25, 2021 21:43
@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 8, 2023
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
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