devenv: Devenv hangs forever

Describe the bug Hello! I have a problem with Devenv on MacOS (Sonoma 14.6). When I try to init devenv it hangs at the devenv init step:

devenv init                                           
• Creating devenv.nix
• Creating devenv.yaml
• Creating .envrc
• Creating .gitignore
direnv: loading ~/ops-stuff/repos/github-management/.envrc
direnv: loading https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc (sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0=)
direnv: using devenv
direnv: .envrc changed, reloading
direnv: ([direnv export zsh]) is taking a while to execute. Use CTRL-C to give up.||

It hangs forever if you don’t press Ctrl-C. I checked what it runs underneath the hood via ps and ran the same command with an extra verbose.

/nix/store/z1zrijdcxzx5a8yf4prggamg6k41hcmi-nix-2.21-devenv/bin/nix --show-trace --extra-experimental-features nix-command --extra-experimental-features flakes --option warn-dirty false --keep-going --max-jobs 4 --option eval-cache false eval .#devenv.cachix --json -vvvvvvvv
evaluating file '<nix/derivation-internal.nix>'
using cache entry '{"_what":"gitLastModified","rev":"0a41d25e85caeb81211a5742b47a9a986edf35d2"}' -> '{"lastModified":1722604605}'
evaluating file '/.devenv.flake.nix'

And it stuck on the evaluating file /.devenv.flake.nix. The same thing happens if I’m trying to run any command. For example if I run devenv info:

devenv info -v
• Running command: /nix/store/z1zrijdcxzx5a8yf4prggamg6k41hcmi-nix-2.21-devenv/bin/nix --show-trace --extra-experimental-features nix-command --extra-experimental-features flakes --option warn-dirty false --keep-going --max-jobs 4 --option eval-cache false flake metadata
• Running command: /nix/store/z1zrijdcxzx5a8yf4prggamg6k41hcmi-nix-2.21-devenv/bin/nix --show-trace --extra-experimental-features nix-command --extra-experimental-features flakes --option warn-dirty false --keep-going --max-jobs 4 --option eval-cache false eval --raw .#info

And it hangs forever. Same thing if I run the command manually:

/nix/store/z1zrijdcxzx5a8yf4prggamg6k41hcmi-nix-2.21-devenv/bin/nix --show-trace --extra-experimental-features nix-command --extra-experimental-features flakes --option warn-dirty false --keep-going --max-jobs 4 --option eval-cache false eval --raw .#info -vvvvvvvvvvv
evaluating file '<nix/derivation-internal.nix>'
using cache entry '{"_what":"gitLastModified","rev":"030722876accf9f65d17616d6d435f982c0ceb2f"}' -> '{"lastModified":1722513473}'
evaluating file '/.devenv.flake.nix'

I tried re-install nix and devenv but it didn’t help. To reproduce devenv init Examples are above.

Version OS: MacOS Sonoma (14.6)

devenv version
devenv 1.0.8 (aarch64-darwin)

Nix version: 2.24.1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 23
  • Comments: 34 (6 by maintainers)

Commits related to this issue

Most upvoted comments

It seems there’s a problem with the latest versions of Nix. I’ve completely uninstalled Nix And installed the older 2.21.4 version via: sh <(curl -L https://releases.nixos.org/nix/nix-2.21.4/install) And it doesn’t hang now and seems to be working.

OK I have figured out what the problem is: for some reason the nix-devenv Nix is reporting protocol 38, which it absolutely is not compliant with, which is then causing protocol negotiation to explode. Either this is a poorly thought out patch in devenv-nix, or a failure on the part of CppNix to increment protocol versions when they make protocol changes.

I am going to go look at the devenv-nix patches and we are going to find out which one it is.

Consider the client side:

Thread 1 "nix" hit Breakpoint 2, nix::RemoteStore::initConnection (this=0x7b7bf0, conn=...) at src/libstore/remote-store.cc:67
67	{
(gdb) n
70	        conn.from.endOfFileError = "Nix daemon disconnected unexpectedly (maybe it crashed?)";
(gdb)
71	        conn.to << WORKER_MAGIC_1;
(gdb)
72	        conn.to.flush();
(gdb) info proc
process 2114582
cmdline = '/nix/store/kanbarzg39qkbq5shvj326c6yxsxkfbv-nix-devenv-2.21.0pre20240614_31b9700/bin/nix --store unix:///home/jade/lix/devenv-haunting/daemon-socket store ping'
cwd = '/home/jade/lix/devenv-haunting'
exe = '/nix/store/kanbarzg39qkbq5shvj326c6yxsxkfbv-nix-devenv-2.21.0pre20240614_31b9700/bin/nix'
(gdb) n
75	            TeeSource tee(conn.from, saved);
(gdb)
73	        StringSink saved;
(gdb)
76	            unsigned int magic = readInt(tee);
(gdb)
73	        StringSink saved;
(gdb)
75	            TeeSource tee(conn.from, saved);
(gdb)
73	        StringSink saved;
(gdb)
75	            TeeSource tee(conn.from, saved);
(gdb)
73	        StringSink saved;
(gdb)
76	            unsigned int magic = readInt(tee);
(gdb)
77	            if (magic != WORKER_MAGIC_2)
(gdb) n
87	        conn.from >> conn.daemonVersion;
(gdb)
88	        if (GET_PROTOCOL_MAJOR(conn.daemonVersion) != GET_PROTOCOL_MAJOR(PROTOCOL_VERSION))
(gdb) p conn.daemonVersion
$10 = 294
(gdb) p/x conn.daemonVersion
$11 = 0x126
(gdb) n
90	        if (GET_PROTOCOL_MINOR(conn.daemonVersion) < 10)
(gdb)
92	        conn.to << PROTOCOL_VERSION;
(gdb)
94	        if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 14) {
(gdb)
96	            conn.to << 0;
(gdb) n
364	    return sink;
(gdb) n
99	        if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 11)
(gdb) n
100	            conn.to << false; // obsolete reserveSpace
(gdb) n
102	        if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 33) {
(gdb) n
103	            conn.to.flush();
(gdb) n
104	            conn.daemonNixVersion = readString(conn.from);
(gdb) list -
89	            throw Error("Nix daemon protocol version not supported");
90	        if (GET_PROTOCOL_MINOR(conn.daemonVersion) < 10)
91	            throw Error("the Nix daemon version is too old");
92	        conn.to << PROTOCOL_VERSION;
93	
94	        if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 14) {
95	            // Obsolete CPU affinity.
96	            conn.to << 0;
97	        }
98
(gdb) list +
99	        if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 11)
100	            conn.to << false; // obsolete reserveSpace
101	
102	        if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 33) {
103	            conn.to.flush();
104	            conn.daemonNixVersion = readString(conn.from);
105	        }
106	
107	        if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 35) {
108	            conn.remoteTrustsUs = WorkerProto::Serialise<std::optional<TrustedFlag>>::read(*this, conn);

And the server side:

Thread 1 "nix" hit Breakpoint 1, nix::WorkerProto::BasicServerConnection::handshake (to=..., from=..., localVersion=localVersion@entry=294,
    supportedFeatures=std::set with 0 elements) at src/libstore/worker-protocol-connection.cc:191
191	    if (magic != WORKER_MAGIC_1)
(gdb) n
193	    to << WORKER_MAGIC_2 << localVersion;
(gdb)
194	    to.flush();
(gdb)
195	    auto clientVersion = readInt(from);
(gdb) n
200	    std::set<WorkerProto::Feature> clientFeatures;
(gdb) n
197	    auto protoVersion = std::min(clientVersion, localVersion);
(gdb) p clientVersion
$1 = 294
(gdb) p/x clientVersion
$2 = 0x126
(gdb) p/x localVersion
$3 = 0x126
(gdb) n
200	    std::set<WorkerProto::Feature> clientFeatures;
(gdb)
197	    auto protoVersion = std::min(clientVersion, localVersion);
(gdb)
200	    std::set<WorkerProto::Feature> clientFeatures;
(gdb)
201	    if (GET_PROTOCOL_MINOR(protoVersion) >= 38) {
(gdb) p 0x26
$4 = 38
(gdb) n
202	        clientFeatures = readStrings<std::set<WorkerProto::Feature>>(from);
(gdb) list -
187	    WorkerProto::Version localVersion,
188	    const std::set<WorkerProto::Feature> & supportedFeatures)
189	{
190	    unsigned int magic = readInt(from);
191	    if (magic != WORKER_MAGIC_1)
192	        throw Error("protocol mismatch");
193	    to << WORKER_MAGIC_2 << localVersion;
194	    to.flush();
195	    auto clientVersion = readInt(from);
196	
(gdb) list +
197	    auto protoVersion = std::min(clientVersion, localVersion);
198	
199	    /* Exchange features. */
200	    std::set<WorkerProto::Feature> clientFeatures;
201	    if (GET_PROTOCOL_MINOR(protoVersion) >= 38) {
202	        clientFeatures = readStrings<std::set<WorkerProto::Feature>>(from);
203	        to << supportedFeatures;
204	        to.flush();
205	    }
206	
(gdb)
legend: C -> S; S <- C

-> WORKER_MAGIC_1
S: (ok)
<- WORKER_MAGIC_2 localVersion (0x100 | 38)
C: (read magic) (read conn.daemonVersion)
-> PROTOCOL_VERSION (0x100 | 38, I assume)
S: (read clientVersion)
-> 0 (obsolete cpu affinity)
-> false (obsolete reserveSpace)
C: ATTEMPT <- daemonNixVersion (string)
S: ATTEMPT <- readStrings clientFeatures (WHAT?!)
S: ATTEMPT -> supportedFeatures

Server here *should* be eating the nonsense ints (cpu affinity, reserveSpace)
that the client is sending it, but is instead attempting to do a feature
negotiation.

Going to look into this today/tomorrow. Thanks a lot @lf-

Can confirm the same as above (w.r.t. versions) on a pretty vanilla Ubuntu 24.04.

Some additional info:

  • root has no issue using devenv on the exact same multi-user nix installation whereas it fails for non-previleged users;
  • according to gdb, nix hangs forever in a call to read in the libc6 bundled by Nix.

As @rfhayashi mentioned (thanks!), downgrading Nix to 2.23.3 fixes everything.

Silly me! I didn’t even realise I could do that!

# NixOS
nix = {
  package = pkgs.nixVersions.nix_2_23;
}

Just in-case anyone else wasn’t aware either 👍🏻

I’ve also managed to reproduce the issue in nix 2.24.0 and 2.24.1 in Linux (Debian). It worked using 2.23.3. This only happens using the multi-user installation, the single-user works ok.

Still broken for me (darwin)

image

Actually nevermind. The first init just took a very long time.

Nix newbie here, this only works running NixOS? Otherwise, I have to re-run the installer and specify an older version somehow?

Yeap, you have to uninstall (https://nix.dev/manual/nix/2.24/installation/uninstall) and install again using sh <(curl -L https://releases.nixos.org/nix/nix-2.23.3/install) --daemon

Is there any workaround for us to get a working devenv while this is being fixed?

The workaround is to downgrade Nix to 2.23.3

Funnily enough, I running as root still does not hang, but now gives a HTTP 502 from github when downloading the .tar.gz from cachix/devenv-nixpkgs.

Running as root is expected to not get this problem because it’s not using the nix protocol, it scribbles over the store without using the daemon.

Ok so here’s the part where you kind of cry: I would advise getting debug info from both the nix client and the nix daemon, then gdb both of them and run them in lock step. Nix protocol desyncs are a nightmare.

it’s happening with me too image

$ devenv version
devenv 1.0.8 (x86_64-linux)
$ nixos-version 
24.11pre-git (Vicuna)
$ nix --version
nix (Nix) 2.24.1

CleanShot 2024-09-13 at 19 59 56@2x

Can confirm it has been fixed. Thanks @domenkozar !!

This is a broken patch to devenv-nix: https://github.com/domenkozar/nix/commit/537b7de306a52ed4b35799cfc180e3aa39d0e07a is not safe to pick without the other protocol changes made prior to it, which seem to be missing as observed above (the client should be sending client features).

Looks like it might be resolved as of 2.24.3 today.

I had devenv hanging in 2.24.2 and 2.24.1 but since upgrading just now it’s fixed for me.

Anyone else tried 2.24.3?

It doesn’t work, sadly:

CleanShot 2024-08-20 at 20 21 59@2x

Seems like they have fixed this, hopefully: https://github.com/NixOS/nix/issues/11258