nh2 / static-haskell-nix

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

Stack build fails with "called without required argument text" #53

Closed david-janssen closed 4 years ago

david-janssen commented 4 years ago

Excuse me if this is me simply not grokking something, but I can't seem to build my little project, which can be found here (including the "default.nix" file I am currently using.: https://github.com/david-janssen/kmonad

I run into "anonymous function at /nix/store/hash-stack2nix-output.nix called without required argument 'text'"

error: while evaluating the attribute 'static_package' at /nix/store/9f4057hjy1b4d3aawzlqxi6gl3lijchc-source/static-stack2nix-builder/default.nix:63:10:
while evaluating the attribute 'haskellPackages.kmonad' at undefined position:
while evaluating anonymous function at /nix/store/9f4057hjy1b4d3aawzlqxi6gl3lijchc-source/survey/default.nix:1133:35, called from undefined position:
while evaluating 'isProperHaskellPackage' at /nix/store/9f4057hjy1b4d3aawzlqxi6gl3lijchc-source/survey/default.nix:83:28, called from /nix/store/9f4057hjy1b4d3aawzlqxi6gl3lijchc-source/survey/default.nix:1134:15:
while evaluating 'isDerivation' at /nix/store/c3xdy7989a3x52jqg98gwzbiwv8gcv49-source/lib/attrsets.nix:305:18, called from /nix/store/9f4057hjy1b4d3aawzlqxi6gl3lijchc-source/survey/default.nix:84:5:
while evaluating 'callPackage' at /nix/store/c3xdy7989a3x52jqg98gwzbiwv8gcv49-source/pkgs/development/haskell-modules/make-package-set.nix:114:22, called from /nix/store/23pn22vxxcgnrp62a20sa0jgz9vky60v-stack2nix-output.nix:20431:18:
while evaluating 'callPackageWithScope' at /nix/store/c3xdy7989a3x52jqg98gwzbiwv8gcv49-source/pkgs/development/haskell-modules/make-package-set.nix:74:37, called from /nix/store/c3xdy7989a3x52jqg98gwzbiwv8gcv49-source/pkgs/development/haskell-modules/make-package-set.nix:114:28:
while evaluating 'makeOverridable' at /nix/store/c3xdy7989a3x52jqg98gwzbiwv8gcv49-source/lib/customisation.nix:67:24, called from /nix/store/c3xdy7989a3x52jqg98gwzbiwv8gcv49-source/pkgs/development/haskell-modules/make-package-set.nix:97:8:
while evaluating 'drvScope' at /nix/store/c3xdy7989a3x52jqg98gwzbiwv8gcv49-source/pkgs/development/haskell-modules/make-package-set.nix:87:18, called from /nix/store/c3xdy7989a3x52jqg98gwzbiwv8gcv49-source/lib/customisation.nix:69:12:
anonymous function at /nix/store/23pn22vxxcgnrp62a20sa0jgz9vky60v-stack2nix-output.nix:20432:10 called without required argument 'text', at /nix/store/c3xdy7989a3x52jqg98gwzbiwv8gcv49-source/pkgs/development/haskell-modules/make-package-set.nix:87:27

I am not entirely sure how to interpret the output above the error message, but I would half expect to find the 'text' package occuring somewhere around here:

+ cabal2nix --subpath . --system x86_64-linux --compiler ghc-8.6.5 cabal://test-framework-quickcheck2-0.3.0.5
+ cabal2nix --subpath . --system x86_64-linux --compiler ghc-8.6.5 cabal://testing-feat-1.1.0.0
+ cabal2nix --subpath . --system x86_64-linux --compiler ghc-8.6.5 cabal://texmath-0.11.2.2
+ cabal2nix --subpath . --system x86_64-linux --compiler ghc-8.6.5 cabal://testing-type-modifiers-0.1.0.1
+ cabal2nix --subpath . --system x86_64-linux --compiler ghc-8.6.5 cabal://text-builder-0.6.5.1
+ cabal2nix --subpath . --system x86_64-linux --compiler ghc-8.6.5 cabal://text-binary-0.2.1.1

but I can't seem to find it anywhere either.

Am I missing something obvious?

nh2 commented 4 years ago

Hey, sorry for the trouble.

The problem is certainly related to the fact that text is usually a package that comes with ghc (such packages are usually null in nixpkgs). For some reason, two of them (text and stm) aren't available at all in the stack2nix output for your project.

I don't have a full solution just yet, but you can work around it by adding the versions of text and stm that are in your resolver: lts-14.7 as explicit extra-deps to stack.yaml:

--- a/stack.yaml
+++ b/stack.yaml
@@ -1,3 +1,6 @@
 resolver: lts-14.7
 packages:
 - .
+extra-deps:
+- text-1.2.3.1
+- stm-2.5.0.0

Then the build will evaluate, and succeed.

I've made a PR with these changes in https://github.com/david-janssen/kmonad/pull/1

Let's not close the issue yet, until we have a proper fix.

david-janssen commented 4 years ago

No trouble at all.

This fix most certainly fixes the problem. I can run the compilation, it finishes, and it produces a binary I can run both under the NixOS environment in which I compiled it, as well as an Ubuntu in a virtualbox, so I consider this a definite win.

I am not sure why this is 'not a full solution'. Does having to add text and stm to extra-deps compromise the binary in any way? Per your request I will leave this issue open. Is there anything I can do to help to provide you with more information on why my stack2nix output didn't contain those packages?

nh2 commented 4 years ago

Glad it's working for you!

I am not sure why this is 'not a full solution'. Does having to add text and stm to extra-deps compromise the binary in any way?

No, it's just annoying that one would have to explicitly specify a version that's technically already implied by resolver. It's unintuitive (and thus you filed this issue).

I must investigate why stack2nix omits text and stm it from the generated nix file when they aren't given explicitly.

qrilka commented 4 years ago

@nh2 I have looked into this and my understanding is that we have 2 main causes here:

So a proper fix could be in fixing stack2nix but that one is a legacy thing so is a bit problematic. From the othe side haskell.nix should give a much better coverage (with GHC versions, package revisions, etc.) but its way to large of an effort to fix this issue.

nh2 commented 4 years ago

@qrilka Thanks for looking into this!

I have some questions:

stack2nix doesn't deal with boot packages properly, you were the last one adding boot packages in input-output-hk/stack2nix#167 but even that change didn't add text for example.

Hmm, that's because none of the sources I linked in https://github.com/input-output-hk/stack2nix/pull/167/files#diff-c3960d8b4ffe3afc0f4919f1df01bcc9R43 says that text is a boot package. The part in stack only has it in ghcjsBootPackages, which seems ghcjs specific.

And https://gitlab.haskell.org/ghc/ghc/wikis/commentary/libraries/version-history lists ~none for text for current GHCs~ ah that's wrong, I read the table in the wrong direction.

  • Stackage moved to use Stack-based builder [...] packages need to be explicitly defined

I'm still not quite sure how exactly it happens. I'm using a pinned stack so its "resolution mechanism" must be the same. Do you mean there's a concrete change in build-constraints.yaml that I should look at?

nh2 commented 4 years ago

@david-janssen Thanks to the hint by @qrilka I've pushed a fix by making a fix to stack2nix at https://github.com/input-output-hk/stack2nix/pull/172.

Please try with latest master, you should no longer need the extra-deps with that.

qrilka commented 4 years ago

@nh2 regarding boot packages Stack has https://github.com/commercialhaskell/stackage-content/blob/master/stack/global-hints.yaml As for changes in Stackage - it build-constraints.yaml thase are not quite explicit but could be noticed e.g. in https://github.com/commercialhaskell/stackage/pull/4326/files#diff-b42a893675b90dbfa12fe0ce6064f0baR3806 and with text in lts-13 it was just included automatically as a dependency of other packages, in lts-14 the new Stack curator tool doesn't do this automatic inclusion and global (or boot) packages get pruned (see e.g. https://www.snoyman.com/blog/2019/01/mismatched-global-packages for related rdetials), thus https://github.com/commercialhaskell/lts-haskell/blob/master/lts-14.7.yaml doesn't include text as a snapshot package but it does include it in system-info.core-packages. Hope this makes things a bit more clear.

david-janssen commented 4 years ago

Can confirm: this fixed everything.