Quoting the manual:
$ nix-env --switch-profile /nix/var/nix/profiles/my-profile
$ nix-env --switch-profile /nix/var/nix/profiles/default
These commands switch to the my-profile and default profile, respectively. If the profile doesn’t exist, it will
be created automatically. On my system (3.15.0-linuxlite), if I do
nix-env --switch-profile /nix/var/nix/profiles/mad
there's no error but no profile is created in /nix/var/nix/profiles and the symlink ~/.nix-profile will point to the nonexistent /nix/var/nix/profiles/mad (and cease functioning)
Could you specify Nix version used?
Yesterday I had the problem w/ nix-1.11.2 but I'm also having it now, after upgrading to nix-1.11.9
I'm new to nix but not sure if this is the expected behavior:
➜ ~ nix-env --switch-profile /nix/var/nix/profiles/my-profile
➜ ~ nix-env --switch-profile /nix/var/nix/profiles/default
zsh: command not found: nix-env
➜ ~ rm .nix-profile
➜ ~ ln -s /nix/var/nix/profiles/default .nix-profile
➜ ~ nix-env
error: no operation specified
Try ‘nix-env --help’ for more information.
Until I use the default profile in ~/.nix-profile I'm able to use nix-env command.
I can confirm that at 1.11.11, nix-env --switch-profile ... does nothing useful if a profile does not already exist (regardless if the path exists beforehand or not). All that happens is the ~/.nix-profile symlink gets pointed to the non-existent or empty profile path, after which nix-env stops working because it's no longer accessible through PATH and ~/.nix-profile.
Have the same issue on OS X, using the nix-env in my nix install 1.09, and using the binary from 1.14
I can confirm this too.
Note that this is very confusing because the documentation has been saying for a while that non-existent profiles are created automatically.
These commands switch to the my-profile and default profile, respectively. If the profile doesn’t exist, it will be created automatically.
System details:
nix-env --version
nix-env (Nix) 1.11.15
nixos-version
17.09.1502.19879836d1 (Hummingbird)
I'm having the same trouble:
nix-env (Nix) 1.11.15
Does anyone know of a workaround?
I worked around it by manually installing nix itself into a new profile:
nix-env -p /nix/var/nix/profiles/coursera -i nix
After this I was able to switch to and from the new profile.
I wonder whether that should be the default behavior?
Still broken in 2.0.1
The profile is created automatically, however lazily, when something is added to the profile. I'm not sure Nix should automatically add itself to each profile.
Here is what can be done:
$ MYNIXENV=$(which nix-env)
$ $MYNIXENV --switch-profile /nix/var/nix/profiles/per-user/my-neat-profile
$ $MYNIXENV -i "$MYNIXENV"
My opinion, then, is the docs should probably provide this example and clarify that it is created automatically upon first use. Does this make sense?
Personally, I don't mind how exactly this is fixed.
I'd be content with a clarification in the docs as suggested.
Thanks
Your reminder about laziness got me thinking. I think this may be a
clearer example on how to create a profile and then switch to it. First,
specify a new profile name and install a package to that profile in one
step. Second, switch to the new profile.
$ nix-env --profile
/nix/var/nix/profiles/per-user/demo/my_neat_profile -i neovim
$ nix-env --switch-profile
/nix/var/nix/profiles/per-user/demo/my_neat_profile
On Mon, Apr 23, 2018 at 5:31 AM, Stefano Mazzucco notifications@github.com
wrote:
Personally, I don't mind how exactly this is fixed.
I'd be content with a clarification in the docs as suggested.
Thanks
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/NixOS/nix/issues/1396#issuecomment-383529720, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AEEct8YHE3xkTtA5JFHyaEFgcNPtzTzbks5tra2OgaJpZM4NqwKl
.
The documentation says:
nix-env {--switch-profile | -S} {path}
This operation makes path the current profile for the user. That is, the symlink ~/.nix-profile is made to point to path.
I am pretty sure that Nix does that. And once you actually install something into the profile, the target symlink will be created, too.
Am I missing something terribly obvious? Where is the bug this ticket is about?
@peti there is indeed no problem with docs or Nix. It is more of example, when intuition fails for some users. And best to see what intuition is - comparison with virtualenv.
virtualenv PATH is very very similar to nix-env --switch-profile PATH. Former creates PATH, which causes mental illusion that latter does so too. Both behaviors have pro arguments, but which should be default?
In my humble opinion, virtualenv PATH is not the same thing as nix-env --switch-profile PATH. The python command is more comparable to
nix-env --switch-profile PATH && nix-env -i python
..., i.e. it sets up a profile and installs something into it. And if you do that, then the PATH you've used in the command will be created by nix-env just like virtualenv would.
In any case, I don't see a compelling argument to change the behavior of nix-env. The behavior is sensible, IMHO, and it's documented correctly and quite clearly.
It _also_ isn't the case that nix-env --switch-profile PATH && nix-env -i python works though, unless I'm missing something.
After pointing ~/.nix-profile to a non-existent file, nix-env is no longer in $PATH, so nix-env -i python fails.
I reinstalled 2.0.2 and have the same (I believe) broken behavior.
I think the problem is when you run nix outside of nixos, when you do nix-env --switch-profile PATH, you lose access to the nix binary. It's actually a bit frustrating figuring out how to just switch back to your default profile. I think you should at least document that it does not indeed create the PATH and you should install nix into said profile for it to be useful (if you're not running nixos).
IMHO, and it's documented correctly and quite clearly.
the online manual, probably the entry point for people who aren't nix-using experts, says:
$ nix-env --switch-profile /nix/var/nix/profiles/my-profile $ nix-env --switch-profile /nix/var/nix/profiles/defaultThese commands switch to the my-profile and default profile, respectively. If the profile doesn’t exist, it will be created automatically.
(Bold added by me) which appears to contradict the manpage, and seems to imply that you can create a new profile with --switch-profile, especially when these example paths don't exist (only having a profiles/per-user folder and no default seem to be a long-standing bugs #1101 #905). Nowhere in the Profile chapter does it tell you how to create a new profile, or that you have to actually run a separate install command for the profile to be created.
But actually using this for a folder that doesn't exist breaks my installation (because nix-env is no longer accessible in thePATH - my (mac, --no-daemon) installer added ~/.nix-profile/etc/profile.d/nix.sh to my .bash_profile (which the manual says is the best way to set up the paths) but this script only adds ~/.nix-profile to the PATH for me.
So "The Bug" is a combination of:
--switch-profile switches the softlink away~/.nix-profile is added to path so moving the softlink means you cannot run nix-env to fix the problem@grahamc your suggestion works - altho I typically end up just using the path to the profile (/nix/var/nix/profiles...) since I end up in this situation after I've already broken my session by switching to a nonexistent profile (which is often just the default profile). but I don't think docs are the best way to approach this - I prefer a warning prompt when someone switches to a profile which does not exist, warning them that they'll be losing their access to nix-env and asking if they'd like to initialize it.
really, how often does a user switch to a profile and then want their ~/.nix-profile to point to a broken symlink? this is on the shortlist of things which prevent me from recommending nix to friends and coworkers. @peti could you help me understand the UX thoughts here? I get that behind-the-scenes side-effects can be annoying
maybe this could be handled by the newish plugin architecture? don't know too much about it
followed the doc, installed nix on another distro, met this very frustrating bug.
At least fix the unintuitive and/or misleading doc here:
https://nixos.org/nix/manual/#sec-profiles
+1
This is annoying bug.
For those on non-NixOS (Linux) here was the fix to get you back:
rm ~/.nix-profile
ln -s /nix/var/nix/profiles/per-user/$USER/profile ~/.nix-profile
hash -r
Most helpful comment
the online manual, probably the entry point for people who aren't nix-using experts, says:
(Bold added by me) which appears to contradict the manpage, and seems to imply that you can create a new profile with
--switch-profile, especially when these example paths don't exist (only having aprofiles/per-userfolder and no default seem to be a long-standing bugs #1101 #905). Nowhere in the Profile chapter does it tell you how to create a new profile, or that you have to actually run a separate install command for the profile to be created.But actually using this for a folder that doesn't exist breaks my installation (because
nix-envis no longer accessible in thePATH- my (mac,--no-daemon) installer added~/.nix-profile/etc/profile.d/nix.shto my.bash_profile(which the manual says is the best way to set up the paths) but this script only adds~/.nix-profileto the PATH for me.So "The Bug" is a combination of:
--switch-profileswitches the softlink away~/.nix-profileis added to path so moving the softlink means you cannot runnix-envto fix the problemexacerbated by the manual giving a different impression.