Skip to content
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

nix-env doesn't auto-create per-user profile? #414

Closed
wmertens opened this issue Dec 11, 2014 · 10 comments · Fixed by #452
Closed

nix-env doesn't auto-create per-user profile? #414

wmertens opened this issue Dec 11, 2014 · 10 comments · Fixed by #452

Comments

@wmertens
Copy link
Contributor

If your nix-env was originally set up by https://github.com/NixOS/nix/blob/master/scripts/nix-profile.sh.in#L5-L9 then your ~/.nix-profile will point to /nix/var/nix/profiles/default.

If you then use nix-env -i ... and you don't have write access to that directory, it will fail to update your environment instead of creating a new environment under /nix/var/nix/profiles/per-user/$USER/.

It will also not give you any indication of what's happening, all you get is error: opening lock file ‘/nix/var/nix/profiles/default.lock’: Permission denied

Is this expected behavior? If so, what would be the best way to improve the error message?

@wmertens
Copy link
Contributor Author

I think it would make most sense if nix-env checked for a writeable profile and if not gave an error message like You need to have a writeable profile, run <xxx> to set it up.

@wmertens
Copy link
Contributor Author

wmertens commented Jan 5, 2015

@edolstra any thoughts on this? Would you accept a PR as described above?

@kirelagin
Copy link
Member

It would be totally nice to have a more verbose error message as suggested.
Also is it possible to create this default profile from the installation script / make install?

@benley
Copy link
Member

benley commented Jan 6, 2015

The way NixOS handles it is to create the profile directory from the system login script. Compare the nix-profile.sh linked above (which is the one from the deb) with this bit of the nixos shell module: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/programs/shell.nix#L23-L62

It handles non-root users rather differently. It seems to me that the deb setup is incorrect except in the case of single-user nix installs - which is what the packages claim to support, after all.

On my ubuntu systems I've replaced /etc/profile.d/nix.sh with a tweaked version that seems to be working well for me: https://gist.github.com/benley/e4a91e8425993e7d6668

wmertens added a commit to wmertens/nix that referenced this issue Jan 21, 2015
Use the same logic as NixOS' profile and environment setup. Closes NixOS#414
@wmertens
Copy link
Contributor Author

@benley thanks for the pointers, I made a PR for a better nix-only version.

@robinbb
Copy link

robinbb commented Mar 27, 2015

+1

@bgamari
Copy link
Contributor

bgamari commented Aug 12, 2018

The error in the case that a user lacks a writeable profile is still awful:

error: opening lock file '/nix/var/nix/profiles/default.lock': Permission denied

It would be great if this could be a bit more descriptive, as suggested by @wmertens.

@markasoftware
Copy link

I just installed NixOS 18.04, upgraded to 19.03, then added a user via users.users in configuration.nix. They had no .nix-profile and nix-env -iA nixos.hello didn't automatically create it.

@mbrgm
Copy link
Member

mbrgm commented Aug 16, 2019

@markasoftware Were you able to fix this?

@markasoftware
Copy link

@mbrgm Yes, actually, although I can't guarantee my problem was the same as yours! I discovered that the problem was in how I was switching users. After adding the new user to configuration.nix and running nixos-rebuild switch, I was switching to the user by running su my-user-name. However, the correct form is su - my-user-name. I had always thought the - was just to protect against usernames that looked like options, but it actually changes the behavior of su substantially and makes it set certain important environment variables which nixos-env needs to operate correctly.

tebowy pushed a commit to tebowy/nix that referenced this issue Jul 11, 2024
The stdenv phases don’t actually do anything (at least not anymore),
and our justfile doesn’t behave the same as our docs.

This patch removes the stdenv phases from the docs, documents our
usage of just, and makes `just setup` heed `$mesonFlags`.

Fixes NixOS#413.
Fixes NixOS#414.

Change-Id: Ieb0b2a8ae420526238b5f9a73d7849ec6919995d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants