Nix shell from within direnv stopped working with nixos 24.11

I updated to nixos 24.11 yesterday.

When I work within a direnv (version 2.23.3) calls to mktemp fail with an error since the $TEMPDIR variable is not correcly set.

Reproduction:

Create a dir with with a minimal shell.nix like

{pkgs ? import <nixpkgs> {} }:                                                                                
pkgs.mkShellNoCC{}    

enable direnv:

echo "use_nix"> .envrc
direnv allow

and run nix-shell.

Expected behavior:

nix shell is created.

Observed behavior:

I get an error like:

error: creating directory '/tmp/nix-shell-194386-0/nix-shell-196284-0': No such file or directory

I figured that this comes from the direnv call to mktemp which fails with a similar error when called directly.

within the direnv the $TEMPDIR is set to /tmp/nix-shell-XXXXXXXX/ while not being set outside the direnv.

  1. Does anybody has an Idea where this change in behaviour could originate from?
  2. How can I fix that calls to mktemp don’t fail within a direnv (it breaks cmake for me in some directories as well)

Should be use nix

Missing a leading { as well

Thanks, I added the missing {

Regarding use_nix or use nix they both work and are nearly identical see the implementation, one just logs that nix is used, I use the other version on purpose.

But that are probably both not the reasons for this behavior, the curly brace is part of the code, I just missed it when copy pasting.

Might be a direnv bug? `use nix` breaks `mktemp` with Nix 2.24+ on macOS · Issue #1345 · direnv/direnv · GitHub

1 Like

Seems to be it, I resolved it temporarily by switching to lorri and the switch to 24.11 seemed to have switched to the buggy version of direnv.