lilyball / nix-env.fish

Nix environment setup for the fish shell
The Unlicense
278 stars 15 forks source link

Support daemon installs #1

Closed jdelStrother closed 4 years ago

jdelStrother commented 4 years ago

I'm still new to nix, so this may be nonsensical, but having installed nix via sh <(curl https://nixos.org/nix/install) --daemon, I don't have a ~/.nix-profile/etc/profile.d/nix.sh.

Would something like this make sense? (Or, being the daemon profile script, maybe it goes against the grain to have it in here rather than /etc/fish/config.fish ?)

lilyball commented 4 years ago

I apologize for ignoring this PR, it looks like I never got an email about it.

What you propose looks like a reasonable patch, as long as the user never installs nix into their local user profile. If you run nix-env -iA nix then you'll likely end up with a ~/.nix-profile/etc/profile.d/nix.sh script and this plugin will then do a single-user install.

Earlier today I just filed https://github.com/NixOS/nix/issues/3630 asking for an official way to initialize a shell for both single-user and multi-user installs. In the meantime we may want to actually invert this test, looking for /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh first as it's a lot less likely that on a single-user install someone will manually install nix into a profile named default. Or maybe we could just check "is /nix owned by root?" or something like that. I'm hoping to get a more reliable answer in the above-linked issue.

lilyball commented 4 years ago

That said, an issue with adding multi-user support to this plugin is ideally multi-user support would be at the system level, not a per-user plugin. I suppose installs of non-nixpkgs fish could manually install this plugin into /etc/fish/conf.d but that won't work for nixpkgs fish. For nixpkgs fish you can add your own /etc/fish/nixos-env-preinit.fish that's responsible for setting up the environment (in particular PATH and NIX_PROFILES), that will cause nixpkgs-installed fish to do all of the necessary configuration automatically, but this is really a hack just to get fish working in NixOS and isn't really suitable for use outside of that.

The default nixpkgs install of fish does source /etc/fish/config.fish (this is controlled by the useOperatingSystemEtc flag that defaults to true) so you could copy this plugin into that file for a multi-user install (sourcing /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh instead), but this is a manual setup that can't be automated by a plugin.

Ultimately, having said all that, I guess a per-user plugin is the only reasonably portable approach to setting this up even in a multi-user install.

lilyball commented 4 years ago

I went ahead and pushed a commit that does basically what you have here but swapping the paths. I figure that's the safer approach.

Thank you for raising this issue and proposing a fix!