given a fresh new system (mac)
when I install nix with curl https://nixos.org/nix/install | sh in the terminal
I cannot immediately use it. I need to open a new terminal so ~/.bash_profile or equivalent is ran
What does "cannot immediately use it" mean?
open a terminal
$ curl https://nixos.org/nix/install | sh
$ nix-env
nix-env: command not found
I don't see how we can fix this, given that a child process cannot change the environment of its parent.
Process A: curl https://nixos.org/nix/install | sh
fork on linux/darwin
curl, unzip and run install (Process B)
Process B:
all the heavy lifting
creates `$NIX_LINK/etc/profile.d/nix.sh` (both in linux/darwin)
// <-- source --^
@MasseGuillaume could you provide a minimal example how it would work? Child process in shell can't change environment in parent unless explicitly told so.
. /dev/stdin might work in some situations.
http://stackoverflow.com/questions/1279953/how-to-execute-the-output-of-a-command-within-the-current-shell
I also get nix-env: not found, when trying to build a Docker image with NixOS and a few packages. Am I doing something wrong?
Dockerfile:
FROM nixos/nix
RUN nix-channel --update && \
nix-env -i gcc && \
nix-env --switch-profile musl && \
nix-env -i musl && \
nix-env --switch-profile klibc && \
nix-env -i klibc && \
nix-env --switch-profile uclibc && \
nix-env -i uclibc && \
nix-env --switch-profile default
Hi @ all,
After following (complete) this step curl https://nixos.org/nix/install | sh.
Just Logout and Come back (Login).
Then open terminal and type nix-env
It should work.
@lovebdsobuj if you are using it as part of an automated script login in and out is not possible.
The only thing I can think to do here is to tell people what to do if they want to use Nix immediately. Basically in the usual "we're done" message, we print something like the following:
Nix has been added to your .profile file. To use it, launch a new shell. If you would like to use Nix in the current shell, run
source ~/.nix-profile/etc/profile.d/nix.shto get the Nix environment variables set up properly.
An alternative would be something like changing the incantation on the website to something like
source <(curl https://nixos.org/nix/install)
That gets gnarly though, because we now need to be sensitive to the host shell. The initial install script would need to become some sort of polyglot bash/sh/zsh/fish/tcsh hybrid, or we'd have to complicate the instructions and tell people to get different scripts based on their shell.
I use fish for 7 years.
We can do support of sh/bash/zsh/tcsh/ksh/csh all at once already. It is not a problem.
Mixing it with fish - is not realistic. Supporting branch of fish, just for lulz is also not realistic idea.
The install script should be written in pure POSIX sh, or bash. These options are brittle, but the other options are even moreso.
One idea would be to update the install instructions to do this after curl | sh. Not sure if it is ideal, but it seems to be a common problem:
On Linux and macOS, the easiest way to install Nix is to run the following shell command (as a user other than root):
curl https://nixos.org/nix/install | sh && source $HOME/.nix-profile/etc/profile.d/nix.sh
This script will download a distribution-independent binary tarball containing Nix and its dependencies, and unpack it in /nix.
This would make the installation process a little bit more fool-proof.
:+1:
Suggesting source $HOME/.nix-profile/etc/profile.d/nix.sh prominently in the install instructions seems like a good idea. Users have opened plenty of tickets here that boil down to them trying to execute Nix commands without having a proper environment.
Thanks @peti , this should be the way to source nix-env after installation.
馃憤
Suggesting
source $HOME/.nix-profile/etc/profile.d/nix.shprominently in the install instructions seems like a good idea. Users have opened plenty of tickets here that boil down to them trying to execute Nix commands without having a proper environment.
I highly recommend this. I saw this unconsciously as I was closing my terminal window, but I couldn't find the message anywhere in the docs to see what the command was. It should be somewhere in the installation instructions for sure.
This might be a dumb question, but am I supposed to add source $HOME/.nix-profile/etc/profile.d/nix.sh to my .bashrc or something? That's fine if so, but the recommendation in the installation process, as well as the discussion here seems to imply that everything will work after doing the command once, but I seem to need to do it for every new terminal window.
Closing because this is not something we can fix (except by symlinking nix-* into a directory already in $PATH, but I don't think we want to pollute the host OS like that).
Most helpful comment
:+1:
Suggesting
source $HOME/.nix-profile/etc/profile.d/nix.shprominently in the install instructions seems like a good idea. Users have opened plenty of tickets here that boil down to them trying to execute Nix commands without having a proper environment.