Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack ghci fails with permissions error for multiple users #5203

Closed
rosekunkel opened this issue Feb 26, 2020 · 7 comments
Closed

stack ghci fails with permissions error for multiple users #5203

rosekunkel opened this issue Feb 26, 2020 · 7 comments
Assignees

Comments

@rosekunkel
Copy link

General summary/comments

stack ghci creates the directory /tmp/haskell-stack-ghci if it doesn't exist, which it uses to store ghci-script files that load the appropriate modules for each project. If multiple users try to use stack ghci, only the first user to do so will succeed, because /tmp/haskell-stack-ghci will be owned by them. Any other user who tries to run stack ghci will get a permissions error. This could be fixed by using a user-specific temporary directory instead (e.g. ~/.cache). The relevant code is here:

stack/src/Stack/Ghci.hs

Lines 437 to 450 in 605f74d

tmpDirectory <-
(</> relDirHaskellStackGhci) <$>
(parseAbsDir =<< liftIO getCanonicalTemporaryDirectory)
ghciDir <- view ghciDirL
ensureDir ghciDir
ensureDir tmpDirectory
macrosOptions <- writeMacrosFile ghciDir pkgs
if ghciNoLoadModules
then execGhci macrosOptions
else do
checkForDuplicateModules pkgs
isIntero <- checkIsIntero
scriptOptions <- writeGhciScript tmpDirectory (renderScript isIntero pkgs mainFile ghciOnlyMain extraFiles)
execGhci (macrosOptions ++ scriptOptions)

Steps to reproduce

  1. Create two users, a and b, and install stack in each of their home directories.
  2. Run stack ghci as user a in their home directory.
  3. Exit GHCi and switch to user b.
  4. Run stack ghci as user b in their home directory.

Expected

GHCi should start normally in user b's global project.

Actual

Starting GHCi fails with:

Configuring GHCi with the following packages: 
/tmp/haskell-stack-ghci/2a3bbd58: createDirectory: permission denied (Permission denied)

Stack version

$ stack --version
Version 2.1.3, Git revision 636e3a759d51127df2b62f90772def126cdf6d1f (7735 commits) x86_64 hpack-0.31.2

Method of installation

  • From the Arch official repositories
@rosekunkel
Copy link
Author

I can write a pull request to fix this, I just want to make sure that my suggested solution (using ~/.cache) is acceptable. I would probably have to add a dependency on https://hackage.haskell.org/package/xdg-basedir if that's ok.

@tmcdonell
Copy link

We have run into this as well. *sigh* A workaround is to set the environment variable TMPDIR to something unique for each user.

The getXdgDirectory function since directory-1.2.3.0 can be used without adding an extra dependency.

@AlijonovMukhammaddiyor
Copy link

Can you please give an example of how to do ?

@davidsd
Copy link

davidsd commented Nov 13, 2021

I just ran into this as well, in a case where a collaborator and I were both trying to use stack ghci on the login node of a shared cluster. It would be great to fix it.

@mauke
Copy link

mauke commented May 9, 2023

Argh. I just ran into this issue at work.

It's been 3 years and it's still broken. Can't you at least include the user id in the directory name, like /tmp/haskell-stack-ghci-${UID}?

@mpilgrem mpilgrem self-assigned this May 9, 2023
@mpilgrem
Copy link
Member

mpilgrem commented May 9, 2023

@mauke, I will have a stab at fixing this.

mpilgrem added a commit that referenced this issue May 10, 2023
Fix #5203 Put GHCi configuration scripts in a user-specific location
@mpilgrem
Copy link
Member

@mauke, I think the version of Stack in the rc/v2.11 release candidate branch now behaves as you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants