Skip to content

Commit

Permalink
devenv: override temp dirs after nix develop
Browse files Browse the repository at this point in the history
`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-<hash>` 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.
  • Loading branch information
sandydoo committed Dec 30, 2024
1 parent 991abff commit b32703d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/modules/top-level.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b32703d

Please sign in to comment.