From b32703d9348a6f2f3ddece31d598a55dc488e979 Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 27 Dec 2024 12:03:27 +0400 Subject: [PATCH] devenv: override temp dirs after nix develop `nix develop` overrides all of the temp directories, which causes problems for module evaluation after the shell, for example `devenv up`. The temporary `nix-shell-` directory it creates is also unsafe to use as it might be garbage collected at a later point. The previous solution was to pick up the `DEVENV_RUNTIME` var, but that is not safe for nested devenvs and does not solve the the tmpdir issue. --- src/modules/top-level.nix | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/modules/top-level.nix b/src/modules/top-level.nix index e17d74ad3..ce108e054 100644 --- a/src/modules/top-level.nix +++ b/src/modules/top-level.nix @@ -186,16 +186,11 @@ in # - free to create as an unprivileged user across OSes default = let - runtimeEnv = builtins.getEnv "DEVENV_RUNTIME"; - hashedRoot = builtins.hashString "sha256" config.devenv.state; - # same length as git's abbreviated commit hashes shortHash = builtins.substring 0 7 hashedRoot; in - if runtimeEnv != "" - then runtimeEnv - else "${config.devenv.tmpdir}/devenv-${shortHash}"; + "${config.devenv.tmpdir}/devenv-${shortHash}"; }; tmpdir = lib.mkOption { @@ -268,6 +263,16 @@ in enterShell = '' export PS1="\[\e[0;34m\](devenv)\[\e[0m\] ''${PS1-}" + # override temp directories after "nix develop" + for var in TMP TMPDIR TEMP TEMPDIR; do + if [ -n "''${!var-}" ]; then + export "$var"=${config.devenv.tmpdir} + fi + done + if [ -n "''${NIX_BUILD_TOP-}" ]; then + unset NIX_BUILD_TOP + fi + # set path to locales on non-NixOS Linux hosts ${lib.optionalString (pkgs.stdenv.isLinux && (pkgs.glibcLocalesUtf8 != null)) '' if [ -z "''${LOCALE_ARCHIVE-}" ]; then