[Haskell-cafe] Problematic fixed "stack ghci" temporary script (parent) directory

Viktor Dukhovni ietf-dane at dukhovni.org
Sun Oct 6 19:40:28 UTC 2019

On Sun, Oct 06, 2019 at 11:06:26AM -0600, Michael Sloan wrote:

> You can override the temporary directory by setting the TMPDIR environment
> variable.
> To have this apply to all of your stack invocations, consider putting an
> alias in your .bashrc, something like:
> $ alias stack="TMPDIR=~/.local/tmp ~/.local/bin/stack"

Thanks, though I am inclined for the fancier[1]:

	stack() { (
		dir=$(mktemp -d /tmp/stack.XXXXXX) || exit 1
		trap '/bin/rm -rf $dir; exit' EXIT HUP INT QUIT TERM
		TMPDIR=$dir $HOME/.local/bin/stack "$@"
	); }

    [1] Note mktemp(1) is not covered by the Single Unix Specification,
    so portability is not assured, the below should work on at least
    BSD Systems and Linux.

> > I don't see the same behaviour with "stack script", though
> > if I create a script to run in "/tmp", then ghc is, somewhat
> > unexpectely, executed with "-i/tmp/", which also has security
> > implications...

But I probably still need to take care to avoid building single-use
throw-away scripts for "stack script" in /tmp:

    $ script=$(mktemp /tmp/script.XXXXXX)
    $ ... generate content of $script ...
    $ stack script "$script"

since it seems that the above will search /tmp for dependencies.


More information about the Haskell-Cafe mailing list