-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
fish: fix environment clobbering and improve initialization #24314
Conversation
@therealpxc, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jgillich, @rnhmjoj and @Profpatsch to be potential reviewers. |
This looks awesome. |
It sure does, my friend!
But my nix-shell-fu is weak. What's the most natural way to have the shell drop to fish instead of bash as soon as you enter it? Is it some neat little shebang trick? |
nix-shell --command 'fish' should work. You can also use the nix integration of direnv, which provides fish shell support. |
Hey, folks! I made some additional changes. The most important is the first, imo, but here they are
I would like to make the support for fish hooks a little more general/streamlined instead of just having packages that use them by copying their fish scripts to magic paths, but I'm not yet sure how. I would also like to make something like a custom fish package that links in all the snippets, functions, and completions it wants so that we can take advantage of these features on non-NixOS. I have some ideas, but if you have any suggestions they would be much appreciated. I've still got more cleaning up to do and I'm not yet sure that everything works perfectly right, but I would appreciate your feedback and thoughts. |
I looked into #18946, I think the solution is rather simple: Although I have to admit, I have no idea why If we're going to parse the initialization variable for bash and zsh in fish, that makes me wonder why we're not doing the same in all shell modules (or just use a common variable). |
I think using a common variable for checking whether the NixOS environment has been sourced would be a good idea. Right now the behavior for other shells is to clobber environments set up by one another, which seems like an oversight. |
I made some silly mistakes earlier. The most recent version fixes them and I can confirm that and vendor_functions.d, vendor_completions.d, vendor_conf.d all get linked in correctly now. |
Btw, @jgillich , what were your plans for the |
ping pong bump bleep |
pkgs/shells/fish/default.nix
Outdated
# set -l profiles (echo \$NIX_PROFILES | ${coreutils}/bin/tr ' ' '\n')[-1..1] | ||
# set fish_complete_path \$profiles"/share/fish/vendor_completions.d" \$fish_complete_path | ||
# end | ||
# EOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this if it is not needed anymore.
pkgs/shells/fish/default.nix
Outdated
EOF | ||
'' + '' | ||
tee -a $out/share/fish/__fish_build_paths.fish < ${./__fish_build_paths.suffix.fish} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is tee used in both cases and not cat
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because to do the same thing with cat one would need to explicitly use temporary files (you can't use cat to read from a file and modify the same file in-place), I think. I went with it because it was the method in place when I started working on this code. I'm aiming to replace it with a better way of handling fish configurations via Nix, but I think that work is properly out of scope for this PR. (See pending comment in the main thread for this PR)
Hey, @nagisa ! Sorry this thing hasn't seen much activity for a little while. I've been playing with some related changes on my personal Nixpkgs fork, and I currently lack clean commits for all the changes I wanted to make to this. Those changes will take a bit longer for me to work out in full and probably ought to be in another pull request anyway. But I will try in the next few hours to clean up this PR by removing things related to my more experimental work and all commented-out code to get this into a suitable state for merging ASAP. I'll push the number of commits back down, too. |
Handling fish configuration in NixOS using the Here's the state of the union: I don't love this way of putting the config files together either, but changing it for this update seems out of scope. I'm working on other changes right now on my messy, personal Nixpkgs branch. I'd like to see those changes merged eventually some day soon too, but the basic idea is using Nix to represent a complete fish configuration (completions folder with files, snippets folder with files, functions folder with files, main config file, etc.) through buildEnv. Those fish-config paths in the Nix store can then be used in the following ways (1-3 are the important ones imo)
I'm currently working on a solution that does all of that, and in doing it I'm generating the configuration files in a more Nix-native way (using builtins for writing files and so on, then pulling them all together with buildEnv) than using bash/tee hacks in a postPatchPhase). Right now I am testing to make sure that I generate those fish-config environments correctly, and I think that part is done except for oh-my-fish support (which I'll add later) but I haven't switched the fish package over to using them yet. Does this seem like a reasonable approach? For users uninterested in use cases 2-4, these changes will have no effect except adding a Nix store path for the default fish configuration used in the default fish package. But that's just symlinks, it shouldn't even really take up more space. Anyway, that effort is why I'm not super concerned about style issues related to the way config files are generated in the NixOS module for fish at this time. |
a494f53
to
b49cc43
Compare
I've cleaned thing up a little. Please let me know what you think. I followed the suggestion of @jgillich with using |
nixos/modules/programs/fish.nix
Outdated
end | ||
|
||
if status --is-interactive | ||
# if our parent shell didn't source the login config, do it | ||
status --is-interactive; and not set -q __fish_nixos_login_config_sourced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variable names are switched around - the "login" one should belong to the status --is-login
block, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ay ay, this is mixed up in several ways. Thanks for pointing that out. I'll get that fixed right away.
Thanks for your review @faho ! I'm embarrassed for not catching that earlier, but I'm glad you found it. :-) FWIW: I've been running this version of the NixOS module for fish and the fish package on my two NixOS machines (my laptop on my multimedia machine) and it successfully initializes my omf config. Using fish as in |
@Mic92 Given that this PR is the source of the above warnings and the mosh failure above (both hitting me), shouldn't it be reverted out of 17.03? |
The warnings are annoying, but before this PR some OMF configurations
result in unusable shells (possibly a broken login manager, as happens with
SDDM) and nix-shell doesn't work with Fish on NixOS. Those seemed urgent to
me, and I developed against 17.03 also because that's what I ran. I'm sorry
it ended up causing such trouble! :-(
I'll have to think about how to handle this better in the future.
I'm about to go on vacation with my family, and I'll have no internet
access for a week in a few hours. I'd hate for my PR to break your workflow
and then be unaccountable to you while your system is broken.
I am not sure I'll be able to get my laptop online (I'm writing this from
my phone, which cannot tether) but in case it is possible, can I get some
more info about the mosh issue? That sounds serious.
…On Mon, May 15, 2017, 10:47 AM Sean Parsons ***@***.***> wrote:
@Mic92 <https://github.com/mic92> Given that this PR is the source of the
above warnings and the mosh failure above (both hitting me), shouldn't it
be reverted out of 17.03?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#24314 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADCJbq1ExppjXdqlJoM1y2MXfNPt_ekzks5r6I-wgaJpZM4MpDCu>
.
|
The mosh issue is just the one listed just above #25789. It's not urgent for me, just might be inconvenient because I tend to use it on the train. @therealpxc The work is appreciated though, trust me, I'm not whinging about it! I just thought I should raise the possibility of a revert just because it may block others. |
@therealpxc So I've just started seeing this with git annex:
I'm surmising it's the same thing as what's going on with mosh, which makes me think it's a general issue with non interactive shells. |
It must be because we decided to do the preinit configuration for login
shells only. Changing that is an easy fix to test, but I won't have the
right kind of connectivity to fix it until next week unless they're selling
WiFi access on this ship. :-\
…On Mon, May 15, 2017, 12:58 PM Sean Parsons ***@***.***> wrote:
@therealpxc <https://github.com/therealpxc> So I've just started seeing
this with git annex:
Please make sure you have the correct access rights
and the repository exists.
fish: Unknown command 'git-receive-pack /home/sean/'
fish: git-receive-pack '/home/sean/'
^
fatal: Could not read from remote repository.
I'm surmising it's the same thing as what's going on with mosh, which
makes me think it's a general issue with non interactive shells.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#24314 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADCJblzOBIuwKQ9Lu5NiuK_9aQ8DMlNZks5r6K5pgaJpZM4MpDCu>
.
|
@therealpxc I'll have a looky see and give it a bash myself. |
Thanks, good luck. Let me know if you run into any issues along the way!
…On Mon, May 15, 2017, 1:15 PM Sean Parsons ***@***.***> wrote:
@therealpxc <https://github.com/therealpxc> I'll have a looky see and
give it a bash myself.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#24314 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADCJbhrkvKodhsGeUSMkXavW5QKCmOW9ks5r6LJ6gaJpZM4MpDCu>
.
|
This apparently fix the problem with mosh. |
Excellent! I believe this will break Fish for nix-shell again unless we add
a simple provision to prevent clobbering the environment on every shell
init. We can do this in a similar way to how it is done in the Fish module
for NixOS. I believe @seanparsons is working on this as we speak.
…On Mon, May 15, 2017, 1:30 PM Michele Guerini Rocco < ***@***.***> wrote:
diff --git a/pkgs/shells/fish/default.nix b/pkgs/shells/fish/default.nix
index 32b7694ba3..35a548eaac 100644
--- a/pkgs/shells/fish/default.nix
+++ b/pkgs/shells/fish/default.nix
@@ -46,8 +46,7 @@ let
fishPreInitHooks = ''
# source nixos environment if we're a login shell
- builtin status --is-login
- and test -f /etc/fish/nixos-env-preinit.fish
+ test -f /etc/fish/nixos-env-preinit.fish
and source /etc/fish/nixos-env-preinit.fish
test -n "$NIX_PROFILES"
This apparently fix the problem with mosh.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#24314 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADCJbmB8lMcZe6Z_-FH6uJxB01gNCFVRks5r6LXMgaJpZM4MpDCu>
.
|
Also note that stable branches are dead ends – normally the code only moves the other way (master -> stable) via cherry-picks. |
@vcunat these commits are in both branches by now. |
@Mic92 At the risk of asking a stupid question, that's only in your fork right? |
@seanparsons No. Here it is on master, and here it is on 17.03. The fixes for the issues related to this PR are available in two commits in a new PR. Feel free to cherry-pick them for your own use. |
@therealpxc I think we've got our wires crossed, I'm referring to the commits that fix this issue that are in the PR. The stuff you're linking to is from March. |
sourced (this fixes issue #25789: #25789 (comment) and the issue with git-annex mentioned here #24314 (comment) )
sourced (this fixes issue #25789: #25789 (comment) and the issue with git-annex mentioned here #24314 (comment) ) (cherry picked from commit 3f91e0d)
I was hoping someone could help me with my attempt to add pass autocompletions. By way of experiment I started by overriding the current pass derivation with a {
pass_with_completions = lib.overrideDerivation pass (oldAttrs: {
preInstall = ''
# fish completions
mkdir -p "$out/share/fish/vendor_completions.d"
cp "src/completion/pass.fish-completion" "$out/share/fish/vendor_completions.d/pass.fish"
'';
});
} In the above I have attempted following the same approach used for adding |
Are you on NixOS, or Nix with non-NixOS? |
I'm on NixOS. I'm not using Fish as a login shell. |
Ah! So this feature depends on the NixOS module for fish, which is only active when The reason is that the Nix environment has to be sourced from the However, the good news the
|
Thank you so much @therealpxc for solving my problem and taking the time to teach me something in the process. I appreciate it! |
No problem at all! I'm happy to know concretely that this feature I added has a user besides me. ;-) I don't contribute as often as I'd like to, but I am intermittently working on some more Nix-related |
fish: fix environment clobbering and improve initialization
sourced (this fixes issue NixOS#25789: NixOS#25789 (comment) and the issue with git-annex mentioned here NixOS#24314 (comment) ) (cherry picked from commit 3f91e0d)
Motivation for this change
fixing this bug
Things done
(nix.useSandbox on NixOS,
or option
build-use-sandbox
innix.conf
on non-NixOS)
nix-shell -p nox --run "nox-review wip"
./result/bin/
)