commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.99k stars 844 forks source link

compiler-tools-bin path is changing (if nix is enabled) if you add a shell-file attribute (breaks intero) #4950

Open dysinger opened 5 years ago

dysinger commented 5 years ago

General summary/comments (optional)

When using Nix with Stack and with the setting of

nix:
  enable: true
  packages: [ zlib ]

(in ~/.stack/global-project/stack.yml) then stack path --compiler-tools-bin gives a result of /home/tim/.stack/compiler-tools/x86_64-linux-nix/ghc-8.6.5/bin (notice x86_64-linux-nix)

BUT if I add a shell-file attribute (and remove packages)

nix:
  enable: true
  shell-file: shell.nix

(in ~/.stack/global-project/stack.yml) then cd ~/.stack/global-project ; stack path --compiler-tools-bin gives a result of /home/tim/.stack/compiler-tools/x86_64-linux/ghc-8.6.5/bin (notice x86_64-linux) but if you just leave the ~/.stack/global-project/stack.yml file alone cd ~ ; stack path --compiler-tools-bin gives a result of /home/tim/.stack/compiler-tools/x86_64-linux-nix/ghc-8.6.5/bin (notice x86_64-linux-nix)

Steps to reproduce

  1. Add and remove a shell-file to your nix section of stack.yml
  2. Watch the stack path --compiler-tool-bin setting change (depending on what directory you are in: project, non-project or ~/.stack/global-project dirs)

Expected

I expect that if I'm on NixOS and I set Nix to enable: true that the complier-tools-bin path wouldn't change.

Actual

This switching around the compiler-tool-bin dir breaks intero's self-installing into crumbling bits as it installs intero into /home/tim/.stack/compiler-tools/x86_64-linux-nix/ghc-8.6.5/bin (sometimes global compiler-tools-bin path) but then checks if the executable is on disk in /home/tim/.stack/compiler-tools/x86_64-linux/ghc-8.6.5/bin (project's compiler-tools-bin path)

The same problems happen when a local project has the same changes happening to it's local stack.yml

Stack version

1.9.3

Method of installation

nixpkgs

dysinger commented 5 years ago

/cc @chrisdone as it relates to intero

dysinger commented 5 years ago

Related @acowley has patched his emacs to stop trying to dynamically install intero on Nix

dysinger commented 5 years ago

Reviewing the code:

This is happening because of Stack.Nix line #78

Where in only adds the STACK_PLATFORM_VARIANT='nix' if you don't use a shell-file. If I add this environment variable to my local shell.nix then it stops wobbling back and forth (global vs project)

I think the solution is to always put in the environment for nix projects.

dysinger commented 5 years ago

An example of a shell.nix that works with currently deployed stack.

with (import <nixpkgs> {});                                                                                              

haskellPackages.shellFor {                                                                                                              
  packages = ps: with ps; [                                                                                                             
    # ADD THIS LOCAL PROJECT'S ENVIRONMENT TO OUR SHELL                                                                                 
    my-project
  ];                                                                                                                                    

  # ADD HOOGLE & INDEX ALL HASKELL PACKAGES                                                                                             
  withHoogle = true;                                                                                                                    

  # ADD ALL THE OTHER GOOD HASKELL DEV TOOLS                                                                                            
  nativeBuildInputs = with haskellPackages; [                                                                                           
    cabal-install                                                                                                                       
    cabal2nix                                                                                                                           
    ghcid                                                                                                                               
    hindent                                                                                                                             
    hlint                                                                                                                               
    hpack                                                                                                                               
    intero                                                                                                                              
    pointfree                                                                                                                           
    stack                                                                                                                               
  ];                                                                                                                                    

  # STACK INJECTS THIS VARIABLE WHEN YOU DON'T USE A shell.nix FILE.                                                                    
  # THIS SETTING CHANGES SOME COMPUTED PATHS LIKE `compiler-tools-bin`                                                                  
  # See https://github.com/commercialhaskell/stack/issues/4950                                                                          
  STACK_PLATFORM_VARIANT = "nix";                                                                                                       
}                                                                                                                                       
dysinger commented 5 years ago

Me (above): "I think the solution is to always put in the environment for nix projects."

Maybe this works as intended. I'm not familiar enough with Stack internals these days.

mattaudesse commented 5 years ago

Sorry for the lack of response + thanks for the thorough details @dysinger!

I'm not really familiar enough to comment on this corner of stack either but it seems like @qrilka might be a good bet based on how many nix-related questions I've seen him answer.

Good luck!