nix-installer icon indicating copy to clipboard operation
nix-installer copied to clipboard

After removing 0.8.0 and installing 0.9.0, many `nix profile` commands fail

Open mitchmindtree opened this issue 1 year ago • 13 comments

I'm testing the Nix installation flow (with v0.9.0) using nix-installer for a fresh Ubuntu LTS user in a VM. Here's the command used to install:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix/tag/v0.9.0 | sh -s -- install

After installation succeeds and a new terminal is opened, commands like nix shell and nix run appear to work fine, however many nix profile commands fail. E.g.

$ nix profile install nixpkgs#hello
error: opening directory '/nix/var/nix/profiles/per-user/mindtree': No such file or directory

Similarly, nix profile upgrade, nix profile rollback, nix profile history all give the same error.

When inspecting the /nix/var/nix/profiles/per-user/ directory, it appears that the nix-installer only creates the root subdirectory, but no directory for the current user.

Could it be the case that nix-installer does try to create this directory for the current user, but due to the required escalated privileges during installation, this user is always root? Perhaps the fix is to add a subdirectory not only for root, but for $USER as well?

I tested this remedy by running the following:

$ sudo mkdir /nix/var/nix/profiles/per-user/mindtree
$ sudo chown mindtree /nix/var/nix/profiles/per-user/mindtree

where mindtree is the current user.

Following this, the nix profile commands appeared to work without issue.

mitchmindtree avatar May 24 '23 05:05 mitchmindtree

Hmmm that's quite odd, I wonder how our systems differ...

image

I'm going to try to add some better testing around this and see if I can root out the issue.

Hoverbear avatar May 24 '23 16:05 Hoverbear

In theory Nix 2.15 should be making your Nix profile in $HOME/.nix-profile, not /nix/var/nix/profiles/per-user/...

Hoverbear avatar May 24 '23 16:05 Hoverbear

I also ran into this problem yesterday, happy to help with any tests I can run on my end to help debug this.

msfjarvis avatar May 24 '23 18:05 msfjarvis

I'm going to do some more experimenting since we now have multiple reports! Thanks so much.

Could you let me know if it was also on Ubuntu LTS?

Hoverbear avatar May 24 '23 20:05 Hoverbear

I'm going to do some more experimenting since we now have multiple reports! Thanks so much.

Could you let me know if it was also on Ubuntu LTS?

This was on Linux Mint 21.1, which is using the Ubuntu 22.04 LTS package base.

msfjarvis avatar May 24 '23 20:05 msfjarvis

In theory Nix 2.15 should be making your Nix profile in $HOME/.nix-profile, not /nix/var/nix/profiles/per-user/...

Interesting, I noticed that .nix-profile was there, thought it was just a symlink to /nix/var/nix/profiles/per-user/$USER which didn't exist.

I ran /nix/nix-installer uninstall and noticed that the .nix-profile file still remained, so this time I manually deleted it to see if it would get recreated by the installer.

This time, I noticed that the installer didn't add any .nix-profile file itself.

I tried running nix profile install nixpkgs#hello, and this time it worked!

I checked $HOME/.nix-profile and it looks like Nix has created the file, though this time with the following symlink: .nix-profile -> /home/mindtree/.local/state/nix/profiles/profile.

I've been re-using this VM to /nix/nix-installer uninstall and then re-install again from scratch over and over. The current installer I'm using is v0.9.0, whereas I've previously run v0.8.0 on this same VM. Is it possible that a previous version of the installer used an older version of Nix that behaved different w.r.t. creating $HOME/.nix-profile? :thinking:

mitchmindtree avatar May 24 '23 20:05 mitchmindtree

Can confirm the same observation, uninstalling with v0.8.0, deleting $HOME/.nix-profile and reinstalling with v0.9.0 does indeed work correctly. In previous tests I had skipped the .nix-profile deletion and encountered the broken behaviour.

msfjarvis avatar May 24 '23 20:05 msfjarvis

Yup I can confirm this:

ana@ephemeral-ubuntu:~$ curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix/tag/v0.8.0 | sh -s -- install
info: downloading installer https://install.determinate.systems/nix/tag/v0.8.0/nix-installer-x86_64-linux
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
Nix install plan (v0.8.0)
Planner: linux (with default settings)

Planned actions:
* Create directory `/nix`
* Fetch `https://releases.nixos.org/nix/nix-2.13.3/nix-2.13.3-x86_64-linux.tar.xz` to `/nix/temp-install-dir`
* Create build users (UID 30000-30032) and group (GID 30000)
* Create a directory tree in `/nix`
* Move the downloaded Nix into `/nix`
* Setup the default Nix profile
* Place the Nix configuration in `/etc/nix/nix.conf`
* Configure the shell profiles
* Configure Nix daemon related settings with systemd
* Remove directory `/nix/temp-install-dir`


Proceed? ([Y]es/[n]o/[e]xplain): y
 INFO Step: Create directory `/nix`
 INFO Step: Provision Nix
 INFO Step: Configure Nix
 INFO Step: Configure Nix daemon related settings with systemd
 INFO Step: Remove directory `/nix/temp-install-dir`
Nix was installed successfully!
To get started using Nix, open a new shell or run `. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh`

ana@ephemeral-ubuntu:~$ ls -lah .nix-profile
ls: cannot access '.nix-profile': No such file or directory
ana@ephemeral-ubuntu:~$ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
ana@ephemeral-ubuntu:~$ ls -lah .nix-profile
ls: cannot access '.nix-profile': No such file or directory
ana@ephemeral-ubuntu:~$ nix run nixpkgs#hello
Hello, world!
ana@ephemeral-ubuntu:~$ ls -lah .nix-profile
ls: cannot access '.nix-profile': No such file or directory
ana@ephemeral-ubuntu:~$ nix profile install nixpkgs#hello
ana@ephemeral-ubuntu:~$ ls -lah .nix-profile
lrwxrwxrwx 1 ana ana 42 May 25 10:23 .nix-profile -> /nix/var/nix/profiles/per-user/ana/profile
ana@ephemeral-ubuntu:~$ /nix/nix-installer uninstall
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
Nix uninstall plan (v0.8.0)

Planner: linux (with default settings)

Planned actions:
* Unconfigure Nix daemon related settings with systemd
* Unconfigure the shell profiles
* Remove the Nix configuration in `/etc/nix/nix.conf`
* Unset the default Nix profile
* Remove the directory tree in `/nix`
* Remove Nix users and group
* Remove the directory `/nix`


Proceed? ([Y]es/[n]o/[e]xplain): y
 INFO Revert: Remove directory `/nix/temp-install-dir`
 INFO Revert: Configure Nix daemon related settings with systemd
 INFO Revert: Configure Nix
 INFO Revert: Provision Nix
 INFO Revert: Create directory `/nix`
Nix was uninstalled successfully!

ana@ephemeral-ubuntu:~$ ls -lah .nix-profile
lrwxrwxrwx 1 ana ana 42 May 25 10:23 .nix-profile -> /nix/var/nix/profiles/per-user/ana/profile
ana@ephemeral-ubuntu:~$ curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix/tag/v0.9.0 | sh -s -- install
info: downloading installer https://install.determinate.systems/nix/tag/v0.9.0/nix-installer-x86_64-linux
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
Nix install plan (v0.9.0)
Planner: linux (with default settings)

Planned actions:
* Create directory `/nix`
* Fetch `https://releases.nixos.org/nix/nix-2.15.0/nix-2.15.0-x86_64-linux.tar.xz` to `/nix/temp-install-dir`
* Create group `nixbld` (GID 30000)
* Create a directory tree in `/nix`
* Move the downloaded Nix into `/nix`
* Setup the default Nix profile
* Place the Nix configuration in `/etc/nix/nix.conf`
* Configure the shell profiles
* Configure Nix daemon related settings with systemd
* Remove directory `/nix/temp-install-dir`


Proceed? ([Y]es/[n]o/[e]xplain): y
 INFO Step: Create directory `/nix`
 INFO Step: Provision Nix
 INFO Step: Configure Nix
 INFO Step: Configure Nix daemon related settings with systemd
 INFO Step: Remove directory `/nix/temp-install-dir`
Nix was installed successfully!
To get started using Nix, open a new shell or run `. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh`

ana@ephemeral-ubuntu:~$ nix profile install nixpkgs#hello
error: opening directory '/nix/var/nix/profiles/per-user/ana': No such file or directory
ana@ephemeral-ubuntu:~$ ls -lah .nix-profile
lrwxrwxrwx 1 ana ana 42 May 25 10:23 .nix-profile -> /nix/var/nix/profiles/per-user/ana/profile

Now to decide how to deal with it... Short of scanning all users home directories for that file and removing it, I'm not sure how we'd repair it...

Hoverbear avatar May 25 '23 17:05 Hoverbear

After chatting with @edolstra I think we might try to improve the error which nix offers here.

Hoverbear avatar Jun 23 '23 19:06 Hoverbear

I've also been running into this the last few months, the (very easy) workaround worked. Iirc a macos upgrade broke my nix install, so I reinstalled

hybras avatar Aug 28 '23 02:08 hybras

Hiya, I'm facing this issue but unsure how to fix. Any suggestions? Thanks!

> nix profile install nixpkgs#nix-direnv
error: opening directory '/nix/var/nix/profiles/per-user/ravis': No such file or directory

shriv avatar Feb 18 '24 23:02 shriv

I figured it out. I just needed to remove the old .nix-profile and re-run the profile daemon. The nix profile installs now run without errors at least..!

> rm .nix-profile
> . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh

shriv avatar Feb 19 '24 01:02 shriv

I figured it out. I just needed to remove the old .nix-profile and re-run the profile daemon. The nix profile installs now run without errors at least..!

> rm .nix-profile
> . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh

Can confirm that this resolved the issue for me

sambacha avatar Mar 23 '24 05:03 sambacha