Skip to content

nix run unsets TMPDIR on macOS #7731

@roberth

Description

@roberth

Describe the bug

initNix() clears an environment variable. It shouldn't.

Steps To Reproduce

$ echo TMPDIR=$TMPDIR; nix run nixpkgs#bash -- -c 'echo TMPDIR=$TMPDIR'                                                           ~
TMPDIR=/var/folders/vh/whk9gn015sd7vkh2php03jf80000gn/T/
TMPDIR=

Expected behavior

Darwin:

$ echo TMPDIR=$TMPDIR; nix run nixpkgs#bash -- -c 'echo TMPDIR=$TMPDIR'                                                           ~
TMPDIR=/var/folders/vh/whk9gn015sd7vkh2php03jf80000gn/T/
TMPDIR=/var/folders/vh/whk9gn015sd7vkh2php03jf80000gn/T/

Linux (already works, but the variable isn't even set in my session NixOS):

$ (export TMPDIR=/tmp; echo TMPDIR=$TMPDIR; nix run nixpkgs#bash -- -c 'echo TMPDIR=$TMPDIR')
TMPDIR=/tmp
TMPDIR=/tmp

nix-env --version output

Additional context

Potential duplicate of #395, although the solution hinted here does not have as broad a scope.

Found while working on a PR to be linked below.

Priorities

Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcliThe old and/or new command line interfacemacosNix on macOS, aka OS X, aka darwinnew-cliRelating to the "nix" command

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions