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

refactor: use pkgs.writeShellApplication #2

Merged

Conversation

nekowinston
Copy link
Contributor

@nekowinston nekowinston commented Mar 12, 2024

Following #1, I had a look through other todo notes, and this would be my approach.

Tried it on my dots again. Seems that only the formatting changed. (cfg.env changed, see my comments)

writeShellApplication already runs shellcheck for us: https://github.com/NixOS/nixpkgs/blob/52544c4a0a84552db4013a8858ade52eaf7ff0ca/pkgs/build-support/trivial-builders/default.nix#L243-L357

modules/default.nix Outdated Show resolved Hide resolved
{
NVIM_RPLUGIN_MANIFEST = "${config.neovim.build.rplugin}/rplugin.vim";
}
// (cfg.env or {});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current code produces

export FOO="${FOO:-bar}"

while runtimeEnv produces

FOO='bar'
export FOO

@willruggiano
Copy link
Owner

So this one is actually on purpose. The reason is that writeShellApplication prepends PATH arguments (export PATH="${lib.makeBinPath runtimeInputs}:$PATH") which means that paths can't be overridden (e.g. via direnv/devShell) if you include in them in paths :(

I had planned on submitting an upstream PR to allow appending rather than prepending to PATH, but guess I just forgot :/

@nekowinston
Copy link
Contributor Author

Interesting, I didn't think of this use case before, but that makes a lot of sense.

Would going back to the previous way of setting $PATH work? e092693

@willruggiano
Copy link
Owner

Interesting, I didn't think of this use case before, but that makes a lot of sense.

Would going back to the previous way of setting $PATH work? e092693

No, doing so is the equivalent of:

export PATH="${makeBinPath ...}:$PATH" # added by writeShellApplication
export PATH="$PATH:${makeBinPath ...}" # added by us

but when the second export hits, the damage has already been done by writeShellApplication.

@nekowinston
Copy link
Contributor Author

The first line

export PATH="${makeBinPath ...}:$PATH" # added by writeShellApplication

doesn't get added for me when runtimeInputs == [], see https://github.com/NixOS/nixpkgs/blob/52544c4a0a84552db4013a8858ade52eaf7ff0ca/pkgs/build-support/trivial-builders/default.nix#L330-L333

When I'm building my neovim.drv with e092693, I get:

#!/nix/store/0wzb184kckhmggq1nlvy5xk6rykp0jl1-bash-5.2-p21/bin/bash
set -o errexit
set -o nounset
set -o pipefail
NVIM_RPLUGIN_MANIFEST='/nix/store/6xyawv9vc956jxbmbb5km15r07z8bxjj-rplugin.vim/rplugin.vim'
export NVIM_RPLUGIN_MANIFEST

export PATH="$PATH:/nix/store/dycm8fa8rhxjyfra67s8mnqg4vmig3h3-fd-9.0.0/bin:..."
/nix/store/wfwz9ig0ipl21v1ngxhgndfgsix5h392-neovim-unwrapped-0.9.5/bin/nvim -u /nix/store/m9ji2sl0h44w3831xxpzkpzw6a7d4hk6-init.lua "$@"

And starting PATH=FOO ./result/bin/nvim +'echo $PATH' prepends $PATH for me: FOO:/nix/store/dycm8fa8rhxjyfra67s8mnqg4vmig3h3-fd-9.0.0/bin:....

...sorry if this is coming across as trying to force this PR, just trying to figure out if something changed recently, that leads to different behavior for my build.

@willruggiano
Copy link
Owner

The first line


export PATH="${makeBinPath ...}:$PATH" # added by writeShellApplication

doesn't get added for me when runtimeInputs == [], see https://github.com/NixOS/nixpkgs/blob/52544c4a0a84552db4013a8858ade52eaf7ff0ca/pkgs/build-support/trivial-builders/default.nix#L330-L333

When I'm building my neovim.drv with e092693, I get:


#!/nix/store/0wzb184kckhmggq1nlvy5xk6rykp0jl1-bash-5.2-p21/bin/bash

set -o errexit

set -o nounset

set -o pipefail

NVIM_RPLUGIN_MANIFEST='/nix/store/6xyawv9vc956jxbmbb5km15r07z8bxjj-rplugin.vim/rplugin.vim'

export NVIM_RPLUGIN_MANIFEST



export PATH="$PATH:/nix/store/dycm8fa8rhxjyfra67s8mnqg4vmig3h3-fd-9.0.0/bin:..."

/nix/store/wfwz9ig0ipl21v1ngxhgndfgsix5h392-neovim-unwrapped-0.9.5/bin/nvim -u /nix/store/m9ji2sl0h44w3831xxpzkpzw6a7d4hk6-init.lua "$@"

And starting PATH=FOO ./result/bin/nvim +'echo $PATH' prepends $PATH for me: FOO:/nix/store/dycm8fa8rhxjyfra67s8mnqg4vmig3h3-fd-9.0.0/bin:....

...sorry if this is coming across as trying to force this PR, just trying to figure out if something changed recently, that leads to different behavior for my build.

Cool I will try it out when I get home!

@willruggiano willruggiano reopened this Mar 13, 2024
@willruggiano willruggiano force-pushed the refactor/use-writeShellApplication branch from e092693 to 2c4fb98 Compare March 13, 2024 01:00
@willruggiano willruggiano merged commit abf58ad into willruggiano:main Mar 13, 2024
1 check passed
@nekowinston nekowinston deleted the refactor/use-writeShellApplication branch October 7, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants