-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
adding support for a nix.fish script along side $HOME/.nix-profile/etc/profile.d/nix.sh #440
Comments
mind you, i'm still debugging/tweaking this to work right : ) |
I'm thinking it would be better to split the script in a setup part and an It would also be nice if the environment loading part just read a See also #452 On Sun Jan 11 2015 at 3:16:18 AM Carter Tazio Schonwald <
|
I can't yet vouch for the script itself, but I'm a fish shell user as well and would love to have an officially supported version of the environment setup script. |
I wrote a bash script that sources the existing #!/usr/bin/env bash
# Usage from fish: "eval (./nix_fish_env) 2>/dev/null"
# Abort if nix isn't installed
if ! [ -f ~/.nix-profile/etc/profile.d/nix.sh ]; then
exit
fi
# Unset variables that will be loaded from nix init
unset PATH
unset SSL_CERT_FILE
# Load environment from nix init
source ~/.nix-profile/etc/profile.d/nix.sh
# Remove trailing `:` from PATH
PATH="${PATH%:}"
# Read PATH and NIX_PATH into arrays
IFS=: read -a PATH_ARRAY <<< "$PATH"
IFS=: read -a NIX_PATH_ARRAY <<< "$NIX_PATH"
# Echo fish commands to export environment variables
echo set -x PATH ${PATH_ARRAY[@]} \$PATH \;
echo set -x NIX_PATH ${NIX_PATH_ARRAY[@]} \;
if [ -f "$SSL_CERT_FILE" ]; then
echo set -x SSL_CERT_FILE \'$SSL_CERT_FILE\' \;
fi |
So what's the next action on this? I presume your problem is solved, but On Fri, Apr 24, 2015 at 11:45 PM Cameron Spickert [email protected]
|
I would like to see this distributed by default. |
I don't know if anything's changed here, but I just ran into this. I'm looking to try out Nix in OS X, and I also use fish as my system shell. Is there anything preventing this fish profile script from being added? |
+1, would love to have this! |
Well, merging this would create a bit of a maintainability problem, since any future change to the bash profile script would have to be propagated to the fish script, and I don't know fish... |
@edolstra just running into this as well and would love to see fish support. I can see the issue with maintainability but most of fish syntax is quite easy to translate from bash, especially if you already have an example as above. (e.g. you have But you could also add it with the caveat that it is not fully tested and if any change breaks the existing fish script I am sure a fish user would step up to fix it. |
Okay, if somebody wants to make a PR, I'll merge it. |
Any update on this? I can make a PR if it wasn't done yet and still needed. |
Just FYI, @cspickert's script still works. Maybe something like that would be easier to maintain as compared to completely duplicating everything in fish. |
Doesn't #626 fix this? |
Yeah, it does. However, there was an idea to auto-generate nix.fish from the run of nix.sh. Not sure what way is better. |
fish is able to convert bash's PATH to an array, I believe. Perhaps it can/will convert |
@cspickert's script produces fish's config. It doesn't expect to be called by fish. But I got your idea. Just tried and this works: #!/usr/bin/env bash
source ~/.nix-profile/etc/profile.d/nix.sh
fish The big downside is that it starts a new shell. |
Whoa! Sourcing the next script from fish sets all needed variables: eval (bash -c "source ~/.nix-profile/etc/profile.d/nix.sh; fish --command 'echo set -x NIX_PATH \"\$NIX_PATH\"\;; echo set -x PATH \"\$PATH\"\;; echo set -x SSL_CERT_FILE \"\$SSL_CERT_FILE\"'") It's a bit convoluted, but what it does is simply: Now I realize it's not too different from @cspickert's script and has many drawbacks (doesn't handle whitespaces, is influenced by .bashrc, etc) |
@rasendubi running your command almost crashed my machine (the shell must've gotten in some infinite loop presumably), I had to force kill the |
To avoid ( cspickert/fish#1 ) |
@cvogt You actually should just unset |
I finished writing a Python script that automatically converts the nix profile to a Fish script. See https://gist.github.com/sebastien/18a7eb71fdd34f6a0f825e69f9461d01 Run the script and you'll have if test -d $HOME/.nix-profile; and test -d /nix
source ~/.config/fish/nix.fish
end |
For those who are using multi-user setup and need to convert
if test -d /nix
source ~/.config/fish/nix-daemon.fish
end |
I made an alternate fish script that runs the original nix.sh, looks at https://gist.github.com/mikeplus64/ef220937525e473f1769147c68ffddeb |
Here is @rasendubi’s snippet modified to not run fish in order to prevent loop in eval (bash -c "source ~/.nix-profile/etc/profile.d/nix.sh; echo export NIX_PATH=\"\$NIX_PATH\"; echo export PATH=\"\$PATH\"; echo export SSL_CERT_FILE=\"\$SSL_CERT_FILE\"") |
In order to save other people the pain, I'd like to point out that the SSL_CERT_FILE variables in the above one-liners should actually be NIX_SSL_CERT_FILE as set in nix.sh. Using them as is will break things. At the very least, it'll break rustup and cargo. So Whether that actually is the best approach or whether using @sebastien's script or something like https://github.com/edc/bass is better, I don't know. It would be nice if we could have a standard fish script, and I think it would be great to come to an agreement over whether nix should be bundled with a generated fish script, a handwritten fish script, or whether using something like bass should be recommended. |
so whats the current state of play for this? |
@lilyball your Fish plugin saved me, thanks! ❤️ |
@lilyball This works for me with nix installed fish too despite what the readme for it says, at least with everything I have tried so far. |
@analyticd You're right, the README is slightly misleading. What I was trying to say is that Nix-installed Fish on NixOS doesn't need this, but it does everywhere else, including Nix-installed Fish on systems other than NixOS. I'll tweak the wording. |
To be precise, I think non-NixOS systems that install |
They do. The mechanism that means this isn't necessary is the presence of This file is set up by the nixos fish module, not by the fish package (which makes sense because the fish package can't write to the system |
Actually one caveat: If the |
Is there still no official support for initing the nix environment for fish? How should I as a noob evaluate which of the scripts provided in this thread fits the bill for me? (MacOS, fish, single user, nix) |
@golddranks AFAIK the other approaches just get you the nix environment and don't get you the rest of the fish stuff (e.g. completions, vendor scripts, etc). My plugin was designed for precisely your setup: https://github.com/lilyball/nix-env.fish |
(If you don't use a fish plugin manager you can just copy the script into your own ~/.config/fish/conf.d folder as well |
Thank you! Seems to work well! |
I can confirm that this is still an issue. I'm on macOS and tried to install Nix directly as per the website's instructions. It failed until I dropped to ZSH and now I can't use anything Nix-related in Fish. |
@yonkeltron Once you had nix installed for ZSH, did you try installing the fish script linked by @lilyball above? Seems to work for me (single or multi user install). I’m running Linux not macOS though. |
I've just upgraded to Catalina and ran the multiuser install. @lilyball's fisher plugin works, though for me it needs tweaking since I don't have a ~/.nix-profile/etc directory (lilyball/nix-env.fish#1) |
So ... the whole issue still stands. What is needed to get fish support for nix /Nixpkgs etc into upstream? Or is this being actively addressed? Thx |
I just pushed a new commit to my plugin that should make it work on multi-user installs. I don't have a (non-NixOS) multi-user install to test with though. |
Thanks @lilyball - works well for me on a multiuser macOS Catalina install. |
I marked this as stale due to inactivity. → More info |
Not sure if it’s hit nixpkgs-unstable yet, but NixOS/nixpkgs#111978 was merged recently that adds a |
Should be fixed by #7014. Do reopen if it's not the case :) |
hey all,
to complement the nix.sh script, because I use fish as my root shell,
i had to write a nix.fish
https://gist.github.com/cartazio/21523fb72db0227611ac is that file
and inline here too
How would I go about upstreaming this and (future) fish scripting support?
I understand some of this stuff is generated from various templates?
thanks!
The text was updated successfully, but these errors were encountered: