# Stack tries to create temporary folder in drive root?

**URL:** <https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155>\
**Category:** Learn\
**Created:** [May 23, 2025, 6:49pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155 "2025-05-23T18:49:28Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://discourse.haskell.org/u/Pat)\
**Post date:** [May 23, 2025, 6:49pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/1 "2025-05-23T18:49:28Z")

</div>

This is a very newbie question, so, my apologies, but I am at my wit’s end trying to figure this out.

I’m using stack version 3.1.1 for windows and, try as I might, I cannot avoid getting the following error:  
Already downloaded msys2-20240727.  
Already downloaded 7z.dll.  
Already downloaded 7z.exe.  
C:\stack-tmp-ee8f5b455efe402d: CreateDirectory “\\?\C:\stack-tmp-ee8f5b455efe402d”: permission denied (Access is denied.)

I believe I’ve set appropriate values for TMP which my reading said was where the temp directory should be. So, if anyone has any help for me, I’d be grateful.

Is there a way to get stack to print out the environment variables it’s using?  
Am I setting the wrong environment variables.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![mpilgrem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpilgrem/32/2529_2.png) [@mpilgrem](https://discourse.haskell.org/u/mpilgrem)\
**Post date:** [May 23, 2025, 7:55pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/2 "2025-05-23T19:55:25Z")

</div>

On Stack’s environment, command `stack config env`. See:

- [config - The Haskell Tool Stack](https://docs.haskellstack.org/en/stable/commands/config_command/#the-stack-config-env-command)

It looks like Stack is trying to create a temporary directory in a location where it does not have permission. I’ll check Stack’s code, but I am surprised that it is trying to do that in the root of the C:\ drive.

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://discourse.haskell.org/u/Pat)\
**Post date:** [May 23, 2025, 8:07pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/3 "2025-05-23T20:07:50Z")

</div>

Thank you; that would be great. I’m not familiar enough with the layout of Stack to even know where to look in the code!

---

<div class="post-metadata">

**Author:** ![mpilgrem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpilgrem/32/2529_2.png) [@mpilgrem](https://discourse.haskell.org/u/mpilgrem)\
**Post date:** [May 23, 2025, 8:14pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/4 "2025-05-23T20:14:48Z")

</div>

Having looked at Stack’s code, Stack should be creating that temporary directory in ~~~the configured ‘local programs’ directory.~~~ [EDIT1: That’s not correct; see below.] That is configured in a Stack configuration file using the `local-programs-path` key: [Non-project specific configuration - The Haskell Tool Stack](https://docs.haskellstack.org/en/stable/configure/yaml/non-project/#local-programs-path)

Command `stack path --programs` to see what Stack understands to be the configured location. See: [path - The Haskell Tool Stack](https://docs.haskellstack.org/en/stable/commands/path_command/)

EDIT1: Strike that. Having looked at Stack’s verbose output, it seems to be doing something different … update to follow.

EDIT2: Correction: `Stack.Setup.withUnpackedTarball7z` has (extract):

```haskell
  withRunInIO $ \run ->
  -- We use a temporary directory in the same drive as that of 'destDir' to
  -- reduce the risk of a filepath length of more than 260 characters, which can
  -- be problematic for 7-Zip even if Long Filepaths are enabled on Windows. We
  -- do not use the system temporary directory as it may be on a different
  -- drive.
    withTempDir destDrive tmpName $ \tmpDir ->
      run $ do
        liftIO $ ignoringAbsence (removeDirRecur destDir)
        run7z tmpDir archiveFile
        ...

```

Stack is trying to create a temporary directory in C:\ because of an understood limitation with 7-Zip.

EDIT3: That 7-Zip limitation may be ancient history looking at 9.32 alpha of 2013-12-01: [https://www.7-zip.org/history.txt](https://www.7-zip.org/history.txt)

EDIT4: Since September 2022, new installations of Stack will have used 7-Zip 22.01.

EDIT5: I don’t know if it is yet safe (in mid-2025) to assume that Stack (and, consequently, 7-Zip) is being used on a Windows system with long file paths enabled.

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://discourse.haskell.org/u/Pat)\
**Post date:** [May 23, 2025, 8:29pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/5 "2025-05-23T20:29:51Z")

</div>

I really appreciate the help - I’ll look into this

programs is set, as I planned to C:\SEI\Tools\bin\x86\_64-windows

---

<div class="post-metadata">

**Author:** ![mpilgrem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpilgrem/32/2529_2.png) [@mpilgrem](https://discourse.haskell.org/u/mpilgrem)\
**Post date:** [May 23, 2025, 10:24pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/6 "2025-05-23T22:24:18Z")

</div>

To document this, I have added something to the Windows-specific part of: [setup - The Haskell Tool Stack](https://docs.haskellstack.org/en/stable/commands/setup_command/#__tabbed_1_2)

EDIT1: However, Stack likely needs to be cleverer than it currently is being. I’ll raise an issue and look at a fix.

EDIT2: I think this is now fixed in the `master` branch version of Stack (if not using GHCup to manage versions of Stack: `stack upgrade --source-only --git`.) I would be good if somebody who does not have permission to create a folder in the root of `C:\` could test it is a fix. There is a Windows binary distribution here: [https://github.com/commercialhaskell/stack/actions/runs/15221475103/artifacts/3189164997](https://github.com/commercialhaskell/stack/actions/runs/15221475103/artifacts/3189164997) or [https://github.com/commercialhaskell/stack/actions/runs/15230682209/artifacts/3191270032](https://github.com/commercialhaskell/stack/actions/runs/15230682209/artifacts/3191270032)

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://discourse.haskell.org/u/Pat)\
**Post date:** [May 24, 2025, 8:51pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/7 "2025-05-24T20:51:39Z")

</div>

The added documentation is useful but not helpful. You’re correct that I typically run as a regular user and not as administrator - it’s a safety policy that makes a lot of sense to me.

Is there a way to enable long file paths? If not, is my only solution to run as admin?

---

<div class="post-metadata">

**Author:** ![mpilgrem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpilgrem/32/2529_2.png) [@mpilgrem](https://discourse.haskell.org/u/mpilgrem)\
**Post date:** [May 24, 2025, 8:54pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/8 "2025-05-24T20:54:32Z")

</div>

See my edited post above. I think this is now fixed in the `master` branch version of Stack, and it would be good if you could test that.

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://discourse.haskell.org/u/Pat)\
**Post date:** [May 24, 2025, 9:12pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/9 "2025-05-24T21:12:32Z")

</div>

So this is very naive - are there instructions on how to build stack? In the past I have just downloaded a Windows binary! Or is there a link to a new binary using your modification?

Thanks

---

<div class="post-metadata">

**Author:** ![mpilgrem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpilgrem/32/2529_2.png) [@mpilgrem](https://discourse.haskell.org/u/mpilgrem)\
**Post date:** [May 24, 2025, 9:39pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/10 "2025-05-24T21:39:20Z")

</div>

I’ve added links above to binary distributions (in an archive file).

Each time Stack’s `integration-tests` GitHub workflow completes, as part of the CI at its GitHub repository, it creates binary distributions as an artefact.

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://discourse.haskell.org/u/Pat)\
**Post date:** [May 28, 2025, 5:56pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/11 "2025-05-28T17:56:38Z")

</div>

Sorry for being slow to follow up. I tried the stack upgrade command both as administrator and as a regular user, in both cases I ended up with “git: readCreateProcess: does not exist (No such file or directory)”

Both links lead me to the git version of 404 Not found otherwise I’d download and install a version

---

<div class="post-metadata">

**Author:** ![mpilgrem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpilgrem/32/2529_2.png) [@mpilgrem](https://discourse.haskell.org/u/mpilgrem)\
**Post date:** [May 29, 2025, 10:09pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/12 "2025-05-29T22:09:12Z")

</div>

I don’t know why the URL’s do not work for you - can I check that you are logged into GitHub when you access them?

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://discourse.haskell.org/u/Pat)\
**Post date:** [May 30, 2025, 6:14pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/13 "2025-05-30T18:14:43Z")

</div>

Thanks; I wasn’t signed in. I have downloaded the updated version and will test it out and let you know

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://discourse.haskell.org/u/Pat)\
**Post date:** [May 30, 2025, 7:22pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/14 "2025-05-30T19:22:28Z")

</div>

Thank you, thank you, thank you. I tried the first link: the 64-bit version and everything works as expected.

The fix is perfect and has enabled me to make progress on my original task!

---

<div class="post-metadata">

**Author:** ![mpilgrem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpilgrem/32/2529_2.png) [@mpilgrem](https://discourse.haskell.org/u/mpilgrem)\
**Post date:** [May 30, 2025, 11:16pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/15 "2025-05-30T23:16:43Z")

</div>

I aim to release new versions of Stack around calendar quarter ends, unless nothing much has happened. So, this should be available in a released version of Stack in about a month’s time.

---

<div class="post-metadata">

**Author:** ![drbean](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@drbean](https://discourse.haskell.org/u/drbean)\
**Post date:** [April 16, 2026, 9:29am UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/16 "2026-04-16T09:29:04Z")

</div>

This appears to have interoperatability problems running `stack install turtle` in a MSYS2 shell. Perhaps because MSYS2 is setting TMP envar to /tmp.

```haskell
drbean@ESPRIMO MSYS ~/turtle
$ stack install turtle

Warning: Trouble loading CompilerPaths cache:

         Error: [S-8196]
         Compiler file metadata mismatch, ignoring cache.
         HasCallStack backtrace:
           collectBacktraces, called at libraries\ghc-internal\src\GHC\Internal\Exception.hs:169:13 in ghc-internal:GHC.Internal.Excep
tion
           toExceptionWithBacktrace, called at libraries\ghc-internal\src\GHC\Internal\IO.hs:260:11 in ghc-internal:GHC.Internal.IO
           throwIO, called at src\UnliftIO\Exception.hs:441:20 in unliftio-0.2.25.1-JcxvxdKc0Ho9WcM1iVvrDp:UnliftIO.Exception

C:\WINDOWS\ghc7176_tmp_0_0: CreateDirectory "\\\\?\\C:\\WINDOWS\\ghc7176_tmp_0_0": permission denied (アクセスが拒否されました。)

Error: [S-6374]
       While building simple Setup.hs (scroll up to its section to see the error) using:
       C:\ghcup\bin\ghc-9.14.1.exe -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is S
tackSetupShim.mainOverride -package Cabal-3.16.0.0 C:\Users\drbean\AppData\Roaming\stack\setup-exe-src\setup-O_vy6YIf.hs C:\Users\drbe
an\AppData\Roaming\stack\setup-exe-src\setup-shim-O_vy6YIf.hs -o C:\Users\drbean\AppData\Roaming\stack\setup-exe-cache\x86_64-windows\
tmp-Cabal-simple_O_vy6YIf_3.16.0.0_ghc-9.14.1.exe
       Process exited with code: ExitFailure 1

But run in a Windows cmd shell:

    C:\Users\drbean\turtle>\ghcup\bin\stack.exe install turtle

Warning: Stack is not using a Stack-supplied MSYS2.
[1 of 3] Compiling Main ( C:\Users\drbean\AppData\Roaming\stack\setup-exe-src\setup-O_vy6YIf.hs, C:\Users\drbean\AppData\Roaming\stack\setup-exe-src\setup-O_vy6YIf.o )
[2 of 3] Compiling StackSetupShim ( C:\Users\drbean\AppData\Roaming\stack\setup-exe-src\setup-shim-O_vy6YIf.hs, C:\Users\drbean\AppData\Roaming\stack\setup-exe-src\setup-shim-O_vy6YIf.o )
[3 of 3] Linking C:\\Users\\drbean\\AppData\\Roaming\\stack\\setup-exe-cache\\x86_64-windows\\tmp-Cabal-simple_O_vy6YIf_3.16.0.0_ghc-9.14.1.exe
turtle> configure (lib + exe)
Configuring turtle-0.1.0.0...
turtle> build (lib + exe) with ghc-9.14.1
Preprocessing library for turtle-0.1.0.0...
Building library for turtle-0.1.0.0...
[1 of 2] Compiling Lib
[2 of 2] Compiling Paths_turtle
Preprocessing executable 'turtle-exe' for turtle-0.1.0.0...
Building executable 'turtle-exe' for turtle-0.1.0.0...
[1 of 2] Compiling Main
[2 of 2] Compiling Paths_turtle
[3 of 3] Linking .stack-work\dist\505eed1c\build\turtle-exe\turtle-exe.exe
turtle> copy/register
Installing library in C:\Users\drbean\turtle\.stack-work\install\111e7964\lib\x86_64-windows-ghc-9.14.1-bd8b\turtle-0.1.0.0-LODE549nfonHFTMblztAkN
Installing executable turtle-exe in C:\Users\drbean\turtle\.stack-work\install\111e7964\bin
Registering library for turtle-0.1.0.0...
Copying from C:\Users\drbean\turtle\.stack-work\install\111e7964\bin\turtle-exe.exe to
C:\Users\drbean\AppData\Roaming\local\bin\turtle-exe.exe.
Copied executables to C:\Users\drbean\AppData\Roaming\local\bin\:
* turtle-exe.exe

Warning: Installation path C:\Users\drbean\AppData\Roaming\local\bin not found on the PATH environment variable.

C:\Users\drbean\turtle>

```

MSYS2 somewhere is setting TMP envar to /tmp for its own tmp files. The Windows envars:

```haskell
`C:\Users\drbean\turtle>echo %TEMP%
C:\Users\drbean\AppData\Local\Temp

```

```haskell
C:\Users\drbean\turtle>echo %TMP%
C:\Users\drbean\AppData\Local\Temp`

```

A lot of windows tmp files are there.

I have a C:\tmp directory with my permissions of user. One cygwin(?) app is using it.

Running `stack install turtle` again in the MSYS2 shell, I get,

```haskell
C:\WINDOWS\: openBinaryTempFileWithDefaultPermissions: permission denied (Permission denied)

```

---

<div class="post-metadata">

**Author:** ![mpilgrem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpilgrem/32/2529_2.png) [@mpilgrem](https://discourse.haskell.org/u/mpilgrem)\
**Post date:** [April 16, 2026, 7:13pm UTC](https://discourse.haskell.org/t/stack-tries-to-create-temporary-folder-in-drive-root/12155/17 "2026-04-16T19:13:00Z")

</div>

I’ll comment on this shortly, but under its own Topic.
