nh2 / static-haskell-nix

easily build most Haskell programs into fully static Linux executables
388 stars 36 forks source link

Cannot build static-stack for stack(source code) v2.1.3 #81

Closed thautwarm closed 4 years ago

thautwarm commented 4 years ago

Environment

Ubuntu 16.04(Virtualbox)

System GHC: (base) redy@redy-VirtualBox:~/Desktop/static-haskell-nix/static-stack$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.10.3 (installed directly from apt)

Reproduction

  1. clone Stack, checkout to tag v2.1.3 to ~/Desktop/stack.
  2. clone this project to ~/Desktop/stack-haskell-nix, get in and git submodule init && git submodule update --recursive
  3. cd static-stack , $(nix-build --no-link -A fullBuildScript --argstr stackDir /home/redy/Desktop/stack):
...
building '/nix/store/l12csrx3ngsvd8pqz8x7hbwgmx838p6v-nix-prefetch-scripts.drv'...

Ensuring git version is >= 2 ...
Ensuring cabal version is >= 2 ...
stack2nix: haskell.compiler.ghc822 failed to build via nix:
error: attribute 'ghc822' in selection path 'haskell.compiler.ghc822' not found

CallStack (from HasCallStack):
  error, called at src/Stack2nix/Util.hs:79:22 in stack2nix-0.2.3-6XVhBtEop6H39w4gsmgj0D:Stack2nix.Util
nh2 commented 4 years ago

Hi, that's right, you need to build with Stack's stack-lts-12.yaml file because ghc822 is no longer in nixpkgs; see how my CI script does it:

https://github.com/nh2/static-haskell-nix/blob/38ef5a4e00b5f6fb421014829320d85899483874/.buildkite/pipeline.yml#L58

Alternatively you can use an older commit of static-haskell-nix.

nh2 commented 4 years ago

I've updated the README accordingly in https://github.com/nh2/static-haskell-nix/commit/95fa110091dff2bf6dace3921c18a26c264d776e, sorry that I didn't document it there when I made the CI fix!

thautwarm commented 4 years ago

Thanks, I'm trying with this configuration.

Besides, I'd ask if I change cabalPackageName in default.nix to my project name, and point the path of my local project, will it be a correct way to build my stack project into static executable?

nh2 commented 4 years ago

@thautwarm Pretty much yes, but start with the template from static-stack2nix-builder-example (https://github.com/nh2/static-haskell-nix/tree/master/static-stack2nix-builder-example), which is made for this purpose, not with static-stack (which is also based on that template but already a bit specialised).

If you encounter any problems with building your project, file me an issue!

thautwarm commented 4 years ago

@nh2 Thanks! As building once costs quite a long time your convince means a lot to me.

A small question:

Does this exactly mean I can use lts-13.26? Or should I change it to compiler = "lts-13.26"?

https://github.com/nh2/static-haskell-nix/blob/95fa110091dff2bf6dace3921c18a26c264d776e/static-stack2nix-builder-example/default.nix#L9

I'm new to Nix, and it's very kind of you to give helps.

nh2 commented 4 years ago

Hey,

no the compiler is correct. It contains the GHC version matching the one in the Stackage LTS you are using, for example for lts-13.26 visit https://www.stackage.org/lts-13.26 and it shows at the top

LTS Haskell 13.26 (ghc-8.6.5)

so ghc865 is the right one.

building once costs quite a long time

If you use my cachix (https://github.com/nh2/static-haskell-nix#binary-caches-for-faster-building-optional) then you may save a lot of time because you will not need to build big parts (like GHC) from source.

thautwarm commented 4 years ago

Thanks, in fact I know that but still not sure... Also I'm using cachix but I'm not sure if it is working because I still need to wait for quite a few minutes before a build exception got raised(my project relies on a big one, which raises errors like incorrect locale)