DeterminateSystems / zero-to-nix

Zero to Nix is your guide to learning Nix and flakes. Created by Determinate Systems.

Home Page:https://zero-to-nix.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Haskell flake template doesn't play nicely with stack lts-20.16

matto-mercury opened this issue · comments

I'm using the DeterminateSystems/zero-to-nix#haskell-dev flake template as explained on https://zero-to-nix.com/start/nix-develop, with my global stack config set up to use lts-20.16 as its resolver. This causes problems:

~/Code/plaid 
14:53:30 $ nix flake init --template "github:DeterminateSystems/zero-to-nix#haskell-dev"
wrote: /home/matto/Code/plaid/flake.lock
wrote: /home/matto/Code/plaid/flake.nix
~/Code/plaid 
14:54:33 $ ls
flake.lock  flake.nix
~/Code/plaid 
14:55:10 $ nix develop
~/Code/plaid 
[nix] 14:55:20 $ stack new Plaid
error: attribute 'ghc927' missing

       at «string»:1:43:

            1| with (import <nixpkgs> {}); let inputs = [haskell.compiler.ghc927 git gcc gmp]; libPath = lib.makeLibraryPath inputs; stackExtraArgs = lib.concatMap (pkg: [ ''--extra-lib-dirs=${lib.getLib pkg}/lib''   ''--extra-include-dirs=${lib.getDev pkg}/include'' ]) inputs; in runCommand ''myEnv'' { buildInputs = lib.optional stdenv.isLinux glibcLocales ++ inputs; STACK_PLATFORM_VARIANT=''nix''; STACK_IN_NIX_SHELL=1; LD_LIBRARY_PATH = libPath;STACK_IN_NIX_EXTRA_ARGS = stackExtraArgs; LANG="en_US.UTF-8";} ""
             |                                           ^
       Did you mean one of ghc92, ghc924, ghc925, ghc90 or ghc902?
(use '--show-trace' to show detailed location information)

I remembered this working before, so I checked the resolver for the working version's local stack.yaml and found lts-20.10. Resetting my global resolver to lts-20.10 worked fine, until I tried to build:

~/Code/plaid/Plaid 
[nix] 15:19:05 $ stack build Plaid
error: attribute 'ghc927' missing

       at «string»:1:43:

            1| with (import <nixpkgs> {}); let inputs = [haskell.compiler.ghc927 git gcc gmp]; libPath = lib.makeLibraryPath inputs; stackExtraArgs = lib.concatMap (pkg: [ ''--extra-lib-dirs=${lib.getLib pkg}/lib''   ''--extra-include-dirs=${lib.getDev pkg}/include'' ]) inputs; in runCommand ''myEnv'' { buildInputs = lib.optional stdenv.isLinux glibcLocales ++ inputs; STACK_PLATFORM_VARIANT=''nix''; STACK_IN_NIX_SHELL=1; LD_LIBRARY_PATH = libPath;STACK_IN_NIX_EXTRA_ARGS = stackExtraArgs; LANG="en_US.UTF-8";} ""
             |                                           ^
       Did you mean one of ghc92, ghc924, ghc925, ghc90 or ghc902?
(use '--show-trace' to show detailed location information)

Again, changing the resolver in the project's stack.yaml to lts-20.10 fixed the issue.

I don't know where to begin debugging this, so it's possible that something unrelated on my machine is messing things up, but it looks to me at first glance like the haskell flake template doesn't play nicely with recent stack resolvers by way of GHC versioning.

Seems likely that this is a stack problem... I suppose it'd be nice to extend the example with a workaround but I would be sympathetic to not wanting to do that.
https://github.com/commercialhaskell/stack/blob/9faba78b7d094d69cd4d6dc85856ebd82fab3b4a/src/Stack/Nix.hs#L87-L117