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

nix script for the fish shell #1090

Closed
wants to merge 4 commits into from
Closed

Conversation

asymmetric
Copy link
Contributor

Second attempt at creating a nix-profile for fish.

I have successfullt used the fish the script, but I haven't tested the scripts/install-nix-from-closure.sh and scripts/local.mk parts - how would I go about doing that?

/cc @garbas

@asymmetric
Copy link
Contributor Author

asymmetric commented Oct 17, 2016

Oh, I hadn't seen #1087 ..

@domenkozar
Copy link
Member

Which one is more accurate? :)

@asymmetric
Copy link
Contributor Author

mine vs his :)

1,3c1,3
< if [ -n $HOME -a -n $USER ]
<     set -l __savedpath $PATH
<     set -xg PATH @coreutils@
---
> if set -q HOME; and set -q USER
>     set -l __savedpath "$PATH"
>     set -x PATH @coreutils@
8c8
<     set -l NIX_LINK $HOME/.nix-profile
---
>     set -l NIX_LINK "$HOME"/.nix-profile
10c10
<     set -l NIX_USER_PROFILE_DIR @localstatedir@/nix/profiles/per-user/$USER
---
>     set -l NIX_USER_PROFILE_DIR @localstatedir@/nix/profiles/per-user/"$USER"
12c12
<     mkdir -m 0755 -p $NIX_USER_PROFILE_DIR
---
>     mkdir -m 0755 -p "$NIX_USER_PROFILE_DIR"
14,15c14,15
<     if [ (stat --printf '%u' $NIX_USER_PROFILE_DIR) -ne (id -u) ]
<         echo "Nix: WARNING: bad ownership on $NIX_USER_PROFILE_DIR, should be "(id -u) >&2
---
>     if [ (stat --printf '%u' "$NIX_USER_PROFILE_DIR") != (id -u) ]
>         echo Nix: WARNING: bad ownership on "$NIX_USER_PROFILE_DIR", should be (id -u) > output.stderr
18,24c18,23
<     if [ -w $HOME ]
<         if not [ -L $NIX_LINK ]
<             echo "Nix: creating $NIX_LINK" >&2
<             if [ $USER != root ]
<                 ln -s $NIX_USER_PROFILE_DIR/profile $NIX_LINK
<                 if [ $status -ne 0 ]
<                     echo "Nix: WARNING: could not create $NIX_LINK -> $NIX_USER_PROFILE_DIR/profile" >&2
---
>     if [ -w "$HOME" ]
>         if not [ -L "$NIX_LINK" ]
>             echo Nix: creating "$NIX_LINK" > output.stderr
>             if [ "$USER" != root ]
>                 if not ln -s "$NIX_USER_PROFILE_DIR"/profile $NIX_LINK
>                     echo Nix: WARNING: could not create "$NIX_LINK" -> "$NIX_USER_PROFILE_DIR"/profile > output.stderr
28c27
<                 ln -s @localstatedir@/nix/profiles/default $NIX_LINK
---
>                 ln -s @localstatedir@/nix/profiles/default "$NIX_LINK"
33,34c32,33
<         if not [ -e $HOME/.nix-channels ]
<             echo 'https://nixos.org/channels/nixpkgs-unstable nixpkgs' > $HOME/.nix-channels
---
>         if not [ -e "$HOME"/.nix-channels ]
>             echo "https://nixos.org/channels/nixpkgs-unstable nixpkgs" > "$HOME"/.nix-channels
38,41c37,40
<         set -l __user_gcroots @localstatedir@/nix/gcroots/per-user/$USER
<         mkdir -m 0755 -p $__user_gcroots
<         if [ (stat --printf '%u' $__user_gcroots) -ne (id -u) ]
<             echo "Nix: WARNING: bad ownership on $__user_gcroots, should be "(id -u) >&2
---
>         set -l __user_gcroots @localstatedir@/nix/gcroots/per-user/"$USER"
>         mkdir -m 0755 -p "$__user_gcroots"
>         if [ (stat --printf '%u' "$__user_gcroots") != (id -u) ]
>             echo Nix: WARNING: bad ownership on "$__user_gcroots", should be (id -u) > output.stderr
45,51c44,48
<         set -l __nix_defexpr $HOME/.nix-defexpr
<         if [ -L $__nix_defexpr ]; rm -f $__nix_defexpr; end
<         mkdir -m 0755 -p $__nix_defexpr
<         if [ $USER != root ]
<             if not [ -L $__nix_defexpr/channels_root ]
<                 ln -s @localstatedir@/nix/profiles/per-user/root/channels "$__nix_defexpr"/channels_root
<             end
---
>         set -l __nix_defexpr "$HOME"/.nix-defexpr
>         [ -L "$__nix_defexpr" ]; and rm -f "$__nix_defexpr"
>         mkdir -m 0755 -p "$__nix_defexpr"
>         if [ "$USER" != root ]; and; not [ -L "$__nix_defexpr"/channels_root ]
>             ln -s @localstatedir@/nix/profiles/per-user/root/channels "$__nix_defexpr"/channels_root
58c55,58
<     set -xg NIX_PATH (string join : $NIX_PATH nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs)
---
>     if set -q NIX_PATH
>       set -x NIX_PATH "$NIX_PATH":
>     end
>     set -x NIX_PATH "$NIX_PATH"nixpkgs="$HOME"/.nix-defexpr/channels/nixpkgs
65,66c65,66
<         if [ -d "$i/lib/aspell" ]
<             set -xg ASPELL_CONF "dict-dir $i/lib/aspell"
---
>         if [ -d "$i"/lib/aspell ]
>             set -x ASPELL_CONF "dict-dir $i/lib/aspell"
71,72c71,72
<     if [ -e /etc/ssl/certs/ca-certificates.crt ] # NixOS, Ubuntu, Debian, Gentoo, Arch
<         set -xg SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt
---
>     if [ -e /etc/ssl/certs/ca-certiendcates.crt ] # NixOS, Ubuntu, Debian, Gentoo, Arch
>         set -x SSL_CERT_FILE /etc/ssl/certs/ca-certiendcates.crt
74c74
<         set -xg SSL_CERT_FILE /etc/ssl/ca-bundle.pem
---
>         set -x SSL_CERT_FILE /etc/ssl/ca-bundle.pem
76c76
<         set -xg SSL_CERT_FILE /etc/ssl/certs/ca-bundle.crt
---
>         set -x SSL_CERT_FILE /etc/ssl/certs/ca-bundle.crt
78,82c78,82
<         set -xg SSL_CERT_FILE /etc/pki/tls/certs/ca-bundle.crt
<     else if [ -e "$NIX_LINK/etc/ssl/certs/ca-bundle.crt" ] # fall back to cacert in Nix profile
<         set -xg SSL_CERT_FILE "$NIX_LINK/etc/ssl/certs/ca-bundle.crt"
<     else if [ -e "$NIX_LINK/etc/ca-bundle.crt" ] # old cacert in Nix profile
<         set -xg SSL_CERT_FILE "$NIX_LINK/etc/ca-bundle.crt"
---
>         set -x SSL_CERT_FILE /etc/pki/tls/certs/ca-bundle.crt
>     else if [ -e "$NIX_LINK"/etc/ssl/certs/ca-bundle.crt ] # fall back to cacert in Nix profile
>         set -x SSL_CERT_FILE "$NIX_LINK"/etc/ssl/certs/ca-bundle.crt
>     else if [ -e "$NIX_LINK"/etc/ca-bundle.crt ] # old cacert in Nix profile
>         set -x SSL_CERT_FILE "$NIX_LINK"/etc/ca-bundle.crt
85,86c85,86
<     if [ -n "$MANPATH" ]
<         set -xg MANPATH $NIX_LINK/share/man $MANPATH
---
>     if not set -q MANPATH
>         set -x MANPATH "$NIX_LINK"/share/man $MANPATH
89c89
<     set -xg PATH $NIX_LINK/bin $NIX_LINK/sbin $__savedpath
---
>     set -x PATH "$NIX_LINK"/bin "$NIX_LINK"/sbin $__savedpath

@nhooyr
Copy link

nhooyr commented Oct 30, 2016

This one has a mistake at line 58. It should be something like https://github.com/nhooyr/nix/blob/c8d56bdbe1cec2c2f6bd86f9a6f58f49b8500553/scripts/nix-profile.fish.in#L52-L58

The difference between this and mine is that I am using more precise quoting and some fish specific features where it makes sense.

@asymmetric
Copy link
Contributor Author

@nhooyr have you tried running the script? Where is the error?

BTW, string and join are both Fish specific features that you're not using where they make sense.

That said, I'm happy with either of our PRs getting merged :)

@nhooyr
Copy link

nhooyr commented Oct 30, 2016

Oh, no error. My bad. You had no quotes around $NIX_PATH on line 58 which is why it works fine. Thing is, I think there is value in being explicit by quoting $NIX_PATH, as it is not an array, it is a string. I've updated mine https://github.com/nhooyr/nix/blob/33097d955033bf7830444c1249e189abc623abdb/scripts/nix-profile.fish.in#L55

@florianjacob
Copy link

I'm a fish user as well, and can't wait to use fish as login shell. 😄
@asymmetric / @nhooyr are you two still around and interested in getting this merged?

@domenkozar I guess I could combine both PRs in a new one and triage the differing parts, if that's what is needed to go on with this?

@asymmetric
Copy link
Contributor Author

@florianjacob fixed conflicts, and updated to keep in sync with bash script.

@Ericson2314
Copy link
Member

https://github.com/oh-my-fish/plugin-foreign-env is pretty cool

@garbas
Copy link
Member

garbas commented Mar 1, 2017

@domenkozar could we get a call on this PR? I think @asymmetric and everybody else put quite some effort into this already and from what I can see it does not break anything. i suppose we can also cherry pick this into 0.11-release and 0.12-release branch.

@edolstra
Copy link
Member

edolstra commented Mar 1, 2017

The main issue is that it would be hard for me to maintain this, since I'm not a fish user...

@copumpkin
Copy link
Member

copumpkin commented Mar 1, 2017 via email

@nh2
Copy link
Contributor

nh2 commented May 2, 2017

@copumpkin That sounds like a good idea.

@asymmetric
Copy link
Contributor Author

@copumpkin I would need some help to do that. Is there any guides on how to approach the release.nix file?

@therealpxc
Copy link

therealpxc commented Jun 23, 2017

Some thoughts:

To get fish to work right as a login shell on NixOS, I had to do some tricks to make sure that 'Nixification' happens before configuration snippets are loaded during fish initialization.

Additionally, fish from Nixpkgs simply checks to see if $NIX_PROFILES is set before using it to load configuration snippets, completions, and functions bundled with packages installed to Nix profiles. If we source the nix.fish file added by this PR around here in the fish package in Nixpkgs, we'll get the same behavior on non-NixOS. This would also causefish installed from Nixpkgs to automatically 'nixify' the environment so that it could be used as a login shell for any user on the system. I think that would be a good thing, but I'd like to hear others' thoughts on it.

PS: I need to update my entry in the maintainers file (and relatedly, drop my maintainership of the Gazebo packages, as I no longer use them), but I would like to be one of the folks on the list for making sure this works.

PPS: I think the changes in this PR are independently valuable from the ones I'm proposing here. If any of my reasoning seems ill-motivated or my plans poorly conceived, that shouldn't stand in the way of this PR; it can be addressed in whatever PR I write for the changes I've just described instead.

@Anton-Latukha
Copy link

It needs shell -> fish tool developed.

@jduan
Copy link

jduan commented Dec 28, 2017

How do I get a copy of the generated nix-profile.fish file? I tried to source the nix-profile.fish.in file but it didn't work and my guess is that it's not the final version of the script. Thanks! I can't wait to try nix out!

@sebastien
Copy link

For those interested, I wrote a Python script that rewrites the .sh script to a .fish https://gist.github.com/sebastien/68b9025a300528ef02a8def6720fb55c

@ilyakooo0
Copy link

Could someone re-upload the python script

@asymmetric
Copy link
Contributor Author

Could be this one.

@asymmetric
Copy link
Contributor Author

I use the Home Manager fish module and have no issues, so I won't be updating this PR further.

If anyone's interested in it, feel free to fork.

@asymmetric asymmetric closed this May 11, 2020
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.

None yet