GithubHelp home page GithubHelp logo

nix-env.fish's Introduction

nix-env.fish

Sets up the Nix environment for a non-NixOS Fish shell.

Beyond just setting up $PATH and the various $NIX_* environment variables, this also sets up $fish_function_path and $fish_complete_path to include any Nix-installed Fish functions/completions, and sources any Nix-installed Fish conf.d.

Install

Any Fish package manager should be able to install this.

fisher install lilyball/nix-env.fish

Manual install

You can install this manually by copying or symlinking the conf.d/nix-env.fish file into your ~/.config/fish/conf.d/ folder.

nix-env.fish's People

Contributors

lilyball avatar pyoio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nix-env.fish's Issues

breaks on fish 3.3.0

I get this error message:

set: Did you mean 'set PATH $PATH <....my whole path...>'?```
(the whole path is in semicolon form).
Latest nix-env installed from fisher 4.3.0, fish 3.3.0 from homebrew on MacOS 11.4

not working?

New to fish & nix (!!!) but couldn't get this to work:

peter@strix ~> fisher list
jorgebucaran/fisher
lilyball/nix-env.fish

peter@strix ~> ls -l .nix-profile/bin/
total 1772
-r-xr-xr-x 1 peter peter 1812696 Jan 1 1970 nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-build -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-channel -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-collect-garbage -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-copy-closure -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-daemon -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-env -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-hash -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-instantiate -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-prefetch-url -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-shell -> nix
lrwxrwxrwx 1 peter peter 3 Jan 1 1970 nix-store -> nix

peter@strix ~> echo $PATH
/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /snap/bin

peter@strix ~> ls -l .config/fish/conf.d/
total 8
-rw-rw-r-- 1 peter peter 6886 Apr 17 21:32 nix-env.fish

peter@strix ~> echo $SHELL
/usr/bin/fish
peter@strix ~>

peter@strix ~> fish --version
fish, version 3.2.2

nothing ends up in my $PATH and i'm unable to execute nix-shell 😢

Package in `nixpkgs`

It'd be great if this was available under nixpkgs#fishPlugins, given the use-case.

Sourcing home-manager env vars

Hi,

I just discovered your project today looking for options to manage my configs a bit more tightly with home-manager. It helped me solved a good portion of the issues I was solving with direnv, so thanks!
One thing that I'm looking at solving is sourcing /.nix-profile/etc/profile.d/hm-session-vars.sh which is generated by home-manager and contains bash style variables that are set and exported for the user when set in their (home-manager) config.

A small example:

home.sessionVariables = {
  BAT_THEME = "Dracula";
};

Would create a file /.nix-profile/etc/profile.d/hm-session-vars.sh with contents of:

# Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1

export BAT_THEME="Dracula"

Is it possible to enable that in this project or should I seek for help in home-manager?

Thanks!

PATH variable keeps growing in nested shells

Thank you for this plugin.

I've just noticed that in nested shells, the PATH variable continues to grow.

> set --show PATH | grep nix
$PATH[6]: |/Users/charego/.nix-profile/bin|
$PATH[7]: |/nix/var/nix/profiles/default/bin|

> exec fish
> set --show PATH | grep nix
$PATH[1]: |/Users/charego/.nix-profile/bin|
$PATH[2]: |/nix/var/nix/profiles/default/bin|
$PATH[14]: |/Users/charego/.nix-profile/bin|
$PATH[15]: |/nix/var/nix/profiles/default/bin|

> exec fish
> set --show PATH | grep nix
$PATH[1]: |/Users/charego/.nix-profile/bin|
$PATH[2]: |/nix/var/nix/profiles/default/bin|
$PATH[9]: |/Users/charego/.nix-profile/bin|
$PATH[10]: |/nix/var/nix/profiles/default/bin|
$PATH[16]: |/Users/charego/.nix-profile/bin|
$PATH[17]: |/nix/var/nix/profiles/default/bin|

I'm not sure if this should be considered a bug with nix-env.fish or with the script that nix-env.fish sources and replays. In my case, I'm running a multi-user install on MacOS and nix-env.fish is sourcing the nix-daemon.sh script.

Here is the relevant snippet from this plugin:

set -l nix_profile_path /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
...
# Source the nix setup script
# We're going to run the regular Nix profile under bash and then print out a few variables
for line in (command env -u BASH_ENV bash -c '. "$0"; for name in PATH "${!NIX_@}"; do printf "%s=%s\0" "$name" "${!name}"; done' $nix_profile_path | string split0)
  set -xg (string split -m 1 = $line)
end

Here is the relevant snippet from nix-daemon.sh:

# Only execute this file once per shell.
if [ -n "${__ETC_PROFILE_NIX_SOURCED:-}" ]; then return; fi
__ETC_PROFILE_NIX_SOURCED=1

export NIX_PROFILES="/nix/var/nix/profiles/default $HOME/.nix-profile"
...
export PATH="$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"

I'm able to "fix" the problem by updating nix-daemon.sh to check for duplicates:

# Prepend profile binaries to PATH if not already present.
for i in $NIX_PROFILES; do
  if [ -d "$i/bin" ] && [[ ":$PATH:" != *":$i/bin:"* ]]; then
    export PATH="$i/bin${PATH:+":$PATH"}"
  fi
done

But notice the script already has its own guard at the top, which doesn't work for us. So should this be guarded against by nix-env.fish, or is it something we need to push upstream? Thanks!

Multiuser mode is always assumed

dffcee7 adds a check for whether to use daemon/multiuser mode by checking whether /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh exists. But that always triggers, since nix-daemon.sh is a part of the nixpkgs.nix package, which is always installed for single-user installs:

 teo  ~  stat (nix path-info nixpkgs.nix)/etc/profile.d/nix-daemon.sh                                                                                                                                                
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
  File: /nix/store/43822pavpsvlnx6cfph58pxnhndjnmdd-nix-2.3.6/etc/profile.d/nix-daemon.sh
  Size: 1334            Blocks: 8          IO Block: 4096   regular file
Device: 10303h/66307d   Inode: 16648927    Links: 1
Access: (0444/-r--r--r--)  Uid: ( 1000/     teo)   Gid: ( 1000/     teo)
Access: 2020-06-08 09:34:44.325693143 +0200
Modify: 1970-01-01 01:00:01.000000000 +0100
Change: 2020-06-08 09:33:37.459140843 +0200
 Birth: 2020-06-08 09:33:37.359135320 +0200

Multi User detection fails if ls is an alias

Hi there,

first of all, thank you very much for this great solution for running nix with fish.
I just came accross a little problem when installing through fisher on a multi-user environment.
In my case ls is an alias for exa which leads to line 26 not being able to detect whether or not /nix/store is owned by root.
A quick fix was to simply change ls to /bin/ls in my case.

Maybe you could add that for the future?

Have a nice day!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.