jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
8.82k stars 207 forks source link

devbox failed to perform single-user installation of Nix #2372

Closed spookylukey closed 1 month ago

spookylukey commented 1 month ago

What happened?

devbox attempted to perform a single-user installation of Nix and failed, with the following output:

Nix is not installed. Devbox will attempt to install it.                                                                                                                                                                                                                        

Press enter to continue or ctrl-c to exit.                                                                                                                                                                                                                                      

Installing nix with: curl -L https://releases.nixos.org/nix/nix-2.24.7/install | sh -s
This may require sudo access.                                                                                                                                                                                                                                                   
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed                                                                                                                                                                                                   
100  4267  100  4267    0     0  43001      0 --:--:-- --:--:-- --:--:-- 43101
downloading Nix 2.24.7 binary tarball for x86_64-linux from 'https://releases.nixos.org/nix/nix-2.24.7/nix-2.24.7-x86_64-linux.tar.xz' to '/tmp/nix-binary-tarball-unpack.kjifIOGUts'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 22.5M  100 22.5M    0     0  7297k      0  0:00:03  0:00:03 --:--:-- 7299k
Note: a multi-user installation is possible. See https://nixos.org/manual/nix/stable/installation/installing-binary.html#multi-user-installation
performing a single-user installation of Nix...
directory /nix does not exist; creating it by running 'mkdir -m 0755 /nix && chown luke /nix' using sudo
copying Nix to /nix/store...

installing 'nix-2.24.7'
building '/nix/store/1qrr0lf1vfird6glzwviddsrycsd5hhz-user-environment.drv'...
error: opening lock file '/nix/var/nix/profiles/per-user/luke/profile.lock': No such file or directory
/tmp/nix-binary-tarball-unpack.kjifIOGUts/unpack/nix-2.24.7-x86_64-linux/install: unable to install Nix into your default profile
Error: exit status 1

Error: There was an internal error. Run with DEVBOX_DEBUG=1 for a detailed error message, and consider reporting it at https://github.com/jetify-com/devbox/issues

Steps to reproduce

On a pretty clean machine (very recent fresh installation of Linuxmint 22), I did this:

  1. Init a new project:

    mdkir test
    cd test
    devbox init
  2. Added my first dependency:

    devbox add python@3.12 

Result was the above.

Attempting to run again, I got this instead:

Error: Unable to find nix startup file. If /nix directory exists it's possible the installation did not complete successfully. Follow instructions at https://nixos.org/download.html for manual install.

If I remove /nix and try again, I get exactly the same error.

Command

add

devbox.json

{
    "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.13.5/.schema/devbox.schema.json",
    "packages": [],
    "shell": {
      "init_hook": [
        "echo 'Welcome to devbox!' > /dev/null"
      ],
      "scripts": {
        "test": [
          "echo \"Error: no test specified\" && exit 1"
        ]
      }
    }
  }

Devbox version

0.13.5

Nix version

No response

What system does this bug occur on?

Linux (x86-64)

Debug logs

time=2024-10-20T20:42:57.732+01:00 level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:125 msg="searching for config file (including parent directories)" path=.
time=2024-10-20T20:42:57.732+01:00 level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:146 msg="trying config file" path=devbox.json
time=2024-10-20T20:42:57.732+01:00 level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:133 msg="config file found" path=/home/luke/tmpstore/test/devbox.json dur=264.791µs
time=2024-10-20T20:42:57.732+01:00 level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:125 msg="searching for config file (including parent directories)" path=.
time=2024-10-20T20:42:57.732+01:00 level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:146 msg="trying config file" path=devbox.json
time=2024-10-20T20:42:57.732+01:00 level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:133 msg="config file found" path=/home/luke/tmpstore/test/devbox.json dur=80.796µs

Nix is not installed. Devbox will attempt to install it.

Press enter to continue or ctrl-c to exit.

Installing nix with: curl -L https://releases.nixos.org/nix/nix-2.24.7/install | sh -s
This may require sudo access.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4267  100  4267    0     0  44178      0 --:--:-- --:--:-- --:--:-- 44447
downloading Nix 2.24.7 binary tarball for x86_64-linux from 'https://releases.nixos.org/nix/nix-2.24.7/nix-2.24.7-x86_64-linux.tar.xz' to '/tmp/nix-binary-tarball-unpack.ke9rejrZ4a'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 22.5M  100 22.5M    0     0  7661k      0  0:00:03  0:00:03 --:--:-- 7662k
Note: a multi-user installation is possible. See https://nixos.org/manual/nix/stable/installation/installing-binary.html#multi-user-installation
performing a single-user installation of Nix...
directory /nix does not exist; creating it by running 'mkdir -m 0755 /nix && chown luke /nix' using sudo
copying Nix to /nix/store...

installing 'nix-2.24.7'
building '/nix/store/1qrr0lf1vfird6glzwviddsrycsd5hhz-user-environment.drv'...
error: opening lock file '/nix/var/nix/profiles/per-user/luke/profile.lock': No such file or directory
/tmp/nix-binary-tarball-unpack.ke9rejrZ4a/unpack/nix-2.24.7-x86_64-linux/install: unable to install Nix into your default profile
Error: exit status 1

time=2024-10-20T20:43:04.360+01:00 level=ERROR source=go.jetpack.io/devbox/internal/boxcli/midcobra/debug.go:68 msg="command error" stderr="" execid=f47073f263d140bfa21d785eb03c2a87 stack="exit status 1\ngo.jetpack.io/devbox/internal/nix.Install\n\tgo.jetpack.io/devbox/internal/nix/install.go:96\ngo.jetpack.io/devbox/internal/nix.EnsureNixInstalled\n\tgo.jetpack.io/devbox/internal/nix/install.go:172\ngo.jetpack.io/devbox/internal/boxcli.ensureNixInstalled\n\tgo.jetpack.io/devbox/internal/boxcli/setup.go:57\ngithub.com/spf13/cobra.(*Command).execute\n\tgithub.com/spf13/cobra@v1.8.0/command.go:968\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/cobra@v1.8.0/command.go:1115\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/cobra@v1.8.0/command.go:1039\ngo.jetpack.io/devbox/internal/boxcli/midcobra.(*midcobraExecutable).Execute\n\tgo.jetpack.io/devbox/internal/boxcli/midcobra/midcobra.go:61\ngo.jetpack.io/devbox/internal/boxcli.Execute\n\tgo.jetpack.io/devbox/internal/boxcli/root.go:116\ngo.jetpack.io/devbox/internal/boxcli.Main\n\tgo.jetpack.io/devbox/internal/boxcli/root.go:139\nmain.main\n\t./main.go:11\nruntime.main\n\truntime/proc.go:272\nruntime.goexit\n\truntime/asm_amd64.s:1700"
time=2024-10-20T20:43:04.360+01:00 level=ERROR source=go.jetpack.io/devbox/internal/boxcli/midcobra/debug.go:70 msg="command error" execid=f47073f263d140bfa21d785eb03c2a87 stack="exit status 1\ngo.jetpack.io/devbox/internal/nix.Install\n\tgo.jetpack.io/devbox/internal/nix/install.go:96\ngo.jetpack.io/devbox/internal/nix.EnsureNixInstalled\n\tgo.jetpack.io/devbox/internal/nix/install.go:172\ngo.jetpack.io/devbox/internal/boxcli.ensureNixInstalled\n\tgo.jetpack.io/devbox/internal/boxcli/setup.go:57\ngithub.com/spf13/cobra.(*Command).execute\n\tgithub.com/spf13/cobra@v1.8.0/command.go:968\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/cobra@v1.8.0/command.go:1115\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/cobra@v1.8.0/command.go:1039\ngo.jetpack.io/devbox/internal/boxcli/midcobra.(*midcobraExecutable).Execute\n\tgo.jetpack.io/devbox/internal/boxcli/midcobra/midcobra.go:61\ngo.jetpack.io/devbox/internal/boxcli.Execute\n\tgo.jetpack.io/devbox/internal/boxcli/root.go:116\ngo.jetpack.io/devbox/internal/boxcli.Main\n\tgo.jetpack.io/devbox/internal/boxcli/root.go:139\nmain.main\n\t./main.go:11\nruntime.main\n\truntime/proc.go:272\nruntime.goexit\n\truntime/asm_amd64.s:1700"
time=2024-10-20T20:43:04.360+01:00 level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:125 msg="searching for config file (including parent directories)" path=.
time=2024-10-20T20:43:04.360+01:00 level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:146 msg="trying config file" path=devbox.json
time=2024-10-20T20:43:04.361+01:00 level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:133 msg="config file found" path=/home/luke/tmpstore/test/devbox.json dur=234.462µs
DerArkeN commented 1 month ago

Does the normal installation from the official Nix Download work? sh <(curl -L https://nixos.org/nix/install) --no-daemon

spookylukey commented 1 month ago

I get the same error:

sh <(curl -L https://nixos.org/nix/install) --no-daemon                                                                                                                                                                                ~/devel/clients/FIRMA [08:05]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  4267  100  4267    0     0   6728      0 --:--:-- --:--:-- --:--:--  6728
downloading Nix 2.24.9 binary tarball for x86_64-linux from 'https://releases.nixos.org/nix/nix-2.24.9/nix-2.24.9-x86_64-linux.tar.xz' to '/tmp/nix-binary-tarball-unpack.s9R2CgPRGY'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 22.5M  100 22.5M    0     0  8018k      0  0:00:02  0:00:02 --:--:-- 8016k
Note: a multi-user installation is possible. See https://nixos.org/manual/nix/stable/installation/installing-binary.html#multi-user-installation
performing a single-user installation of Nix...
directory /nix does not exist; creating it by running 'mkdir -m 0755 /nix && chown luke /nix' using sudo
copying Nix to /nix/store......................................................
installing 'nix-2.24.9'
building '/nix/store/l9ab6qm37vw0g8vblfzrj387khq6qql1-user-environment.drv'...
error: opening lock file '/nix/var/nix/profiles/per-user/luke/profile.lock': No such file or directory
/tmp/nix-binary-tarball-unpack.s9R2CgPRGY/unpack/nix-2.24.9-x86_64-linux/install: unable to install Nix into your default profile

So this looks like an upstream issue - although one you maybe want to be aware of, as I can't be the only one who hits this.

DerArkeN commented 1 month ago

yes, this is a nix issue... but try this: mkdir -m 0755 -p /nix/var/nix/profiles/per-user/luke and running the installer again.

i actually only found this one issue that hasn't been resolved yet. https://github.com/cachix/devenv/issues/1225

spookylukey commented 1 month ago

OK, I think the issue was I had an existing ~/.nix-profile symlink:

/home/luke/.nix-profile -> /nix/var/nix/profiles/per-user/luke/profile

After removing this, the installation succeeded, without having to manually create the missing directory. I'm guessing I may have tried to install Nix in the past? My root system is a clean install of Linuxmint, but my home directory is anything but clean...

So I'm guessing this is really a Nix install bug, but not one that most people will trip up over, so I'm closing the ticket.

DerArkeN commented 1 month ago

Glad your issue could be resolved. The issue might have occured because you copied your home directory without uninstalling nix beforehand (removing /nix on a single-user installation) which kept the symlink in your home.