Skip to content

ghc: mark broken for musl + integer-simple builds#130441

Merged
cdepillabout merged 9 commits intoNixOS:haskell-updatesfrom
cdepillabout:figure-out-ghc-integer-simple
Jul 24, 2021
Merged

ghc: mark broken for musl + integer-simple builds#130441
cdepillabout merged 9 commits intoNixOS:haskell-updatesfrom
cdepillabout:figure-out-ghc-integer-simple

Conversation

@cdepillabout
Copy link
Copy Markdown
Member

Motivation for this change

This PR correctly marks the GHC musl integer-simple builds as broken.

See #129606 (comment).

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Relase notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added the 6.topic: haskell General-purpose, statically typed, purely functional programming language label Jul 17, 2021
@cdepillabout cdepillabout force-pushed the figure-out-ghc-integer-simple branch from 0f1392b to 2bd7378 Compare July 17, 2021 09:34
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jul 17, 2021
@cdepillabout
Copy link
Copy Markdown
Member Author

cdepillabout commented Jul 17, 2021

@nh2 @sternenseemann I'd like to do the following two things with this PR:

  • correctly mark GHC as broken when compiling with musl and integer-simple
  • remove the jobs from our release-haskell.nix file that we know don't work (related to musl and integer-simple)

I meant to do this in #129606, but I couldn't figure out exactly what is expected to be working. I'm hoping you guys would be able to help me out with this.


Looking at the latest Hydra evaluation for #129606, we can see what is not working for GHC musl integer-simple:

https://hydra.nixos.org/eval/1686753?filter=integer-simple&compare=1686725

Here's a summary:

  • These are the jobs that are correctly building. We most likely want to keep them in our Hydra jobset:

    • pkgsStatic.haskell.packages.integer-simple.ghc8104.{hello,lens,random}.x86_64-linux (pkgsStatic implies musl, right?)
    • haskell.compiler.integer-simple.{ghc884,ghc8104,ghc901}.{aarch64-linux,x86_64-darwin,x86_64-linux} (these are non-musl. it makes sense that they are compiling)
  • These are the jobs that are just completely failing to compile. These are the jobs that are showing up on our build report (like haskellPackages: update stackage and hackage #129606 (comment)). This is mainly what I'd like to mark broken and remove from from our haskell-updates jobset as long as it is known not to work.

    • pkgsMusl.haskell.compiler.integer-simple.{ghc884,ghc8104,ghc901}.x86_64-linux
  • These are jobs that are timing out. Are these expected to work? Or are they known to timeout? Should I remove aarch64-linux from hydraPlatforms? Is it even possible to selectively remove things from hydraPlatforms based on build inputs? Should I instead just remove them from release-haskell.nix?

    • pkgsStatic.haskell.packages.integer-simple.ghc8104.{hello,lens,random}.aarch64-linux
  • These are jobs where a dependency failed to build. In this case, libiconv failed to build. I was under the impression that it wasn't possible to build static libraries/executables for x86_64-darwin. Are these expected failures? Or are these expected to work (assuming libiconv builds). Should I remove them from release-haskell.nix?

  • pkgsStatic.haskell.packages.integer-simple.ghc8104.{hello,lens,random}.x86_64-darwin


This is mostly for @sternenseemann, but maybe it makes sense for us to add a job like pkgsMusl.haskell.packages.ghc8104.{hello,lens,random}.x86_64-linux, since we have a similar job for pkgsStatic that is succeeding. (pkgsMusl should succeed everywhere pkgsStatic succeeds, right?)

We should probably also have a separate job for pkgsStatic.haskell.compiler.*.x86_64-linux, since we sort of have one for pkgsMusl.

Comment on lines 315 to 319
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost certainly incorrect and should not be merged as-is.

Two problems with this:

  1. For broken, I couldn't figure out what the logic should be.

    I think that GHC is broken when:

    • you're using integer-simple
    • you're compiling with musl
    • you're not linking libraries statically

    On Hydra, jobs like pkgsMusl.haskell.compiler.integer-simple.{ghc884,ghc8104,ghc901}.x86_64-linux are failing to compile, which should match this configuration.

    However, I think GHC is building correctly when:

    • you're using integer-simple
    • you're compiling with musl
    • you are linking libraries statically

    On Hydra, jobs like pkgsStatic.haskell.packages.integer-simple.ghc8104.{hello,lens,random}.x86_64-linux are build successfully (which should be using a GHC that matches this configuration).

    Is there some easy way to check whether or not libraries are being linked statically?

  2. I imagine hydraPlatforms is just incorrect here. It'd probably be better just remove the things we know not to be working in release-haskell.nix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some easy way to check whether or not libraries are being linked statically?

targetPlatform.isStatic

I imagine hydraPlatforms is just incorrect here. It'd probably be better just remove the things we know not to be working in release-haskell.nix.

Agreed, at the very least make meta into a rec set and do:

  ${if broken then "hydraPlatforms" else null} = lib.platforms.none;

or something like that.

@cdepillabout
Copy link
Copy Markdown
Member Author

cdepillabout commented Jul 18, 2021

@nh2 @sternenseemann The more I look into this, the more questions I end up having.

Here's two more questions:

  1. Why can I build something like:

    $ nix-build -A pkgsStatic.haskell.packages.integer-simple.ghc8104.hello
    /nix/store/gj51asyz7i4wxf5xj12lnnf8lpzk8371-hello-static-x86_64-unknown-linux-musl-1.0.0.2

    But I can't build the compiler:

    $ nix-build -A pkgsStatic.haskell.compiler.integer-simple.ghc8104
    error: assertion ((stdenv).targetPlatform == (stdenv).hostPlatform) failed at /home/illabout/git/nixpkgs/pkgs/development/compilers/ghc/8.10.2-binary.nix:15:1

    My guess is that this is because pkgsStatic.haskell.compiler.integer-simple.ghc8104 would be trying to build a completely statically-linked GHC? Whereas pkgsStatic.haskell.packages.integer-simple.ghc8104.hello is using a musl-enabled dynamically linked compiler to build a static library?

  2. In our Haskell compilers, it looks like there is some logic for deciding the boot GHC:

    # aarch64 ghc865Binary gets SEGVs due to haskell#15449 or similar
    # Musl bindists do not exist for ghc 8.6.5, so we use 8.10.* for them
    bootPkgs = if stdenv.isAarch64 || stdenv.isAarch32 || stdenv.targetPlatform.isMusl then
    packages.ghc8102BinaryMinimal
    else
    packages.ghc865Binary;

    What is this logic needed for? Why can't we just use ghc8102BinaryMinimal for everything? I would think that the boot GHC doesn't make a big difference on the resulting GHC (as long as the boot GHC has some minimal functionality), but maybe this is incorrect?

@cdepillabout cdepillabout force-pushed the figure-out-ghc-integer-simple branch 2 times, most recently from ea38ec1 to efc6f9b Compare July 18, 2021 06:20
@cdepillabout
Copy link
Copy Markdown
Member Author

Alright, I've tried to clean up the release-haskell.nix file.

Here's what I've done in this PR:

  • Stop building Haskell packages from pkgsStatic on aarch64 in the staticHaskellPackages job. These jobs appear to be timing out. This is in f5cd459f5cb0644 and f4af60afa4f07a5b0859. Here's an example on Hydra of one of these jobs timing out: https://hydra.nixos.org/build/147741210

  • Stop building pkgsMusl.haskell.compiler.integer-simple in release-haskell. As we discussed earlier, this just appears to not be supported. This is in 4b638f60991fb. I also marked these GHCs as broken in efc6f9b. This was my original motivation for this PR.

  • Build a couple haskell packages from pkgsMusl.haskellPackages. I think it makes sense to have this, since we have a similar thing for pkgsStatic. This is in 3981ec793e98. We can always remove this if it ends up failing. @nh2, would you like me to add these packages to your muslGHCs aggregate job? I imagine you might be interested if any of these Haskell packages fail to build on musl.

@sternenseemann
Copy link
Copy Markdown
Member

sternenseemann commented Jul 18, 2021

My guess is that this is because pkgsStatic.haskell.compiler.integer-simple.ghc8104 would be trying to build a completely statically-linked GHC? Whereas pkgsStatic.haskell.packages.integer-simple.ghc8104.hello is using a musl-enabled dynamically linked compiler to build a static library?

pkgsStatic is cross compiled, so the compiler derivation is pkgsStatic.buildPackages.haskell.compiler.ghc8104 which is neither statically linked nor uses musl at all.

What is this logic needed for? Why can't we just use ghc8102BinaryMinimal for everything? I would think that the boot GHC doesn't make a big difference on the resulting GHC (as long as the boot GHC has some minimal functionality), but maybe this is incorrect?

AFAIK this is mostly historically baggage. GHC's build system doesn't like to be reverse bootstrapped, so compiling 8.8.4 with 8.10.2 would normally fail. However at some point there were problems with the binary 8.6.5 on some platforms which lead to 8.10.2 being used and a patch introduced which allowed reverse bootstrapping. The condition was apparently introduced to avoid a full rebuild at the time.

Since reverse bootstrapping works well enough, I'd suggest we use 8.10.2 for everything in the future, so we can remove ghc865Binary which is a derivation of inferior quality as opposed to ghc8102Binary at this point.

@sternenseemann
Copy link
Copy Markdown
Member

sternenseemann commented Jul 18, 2021

  • Build a couple haskell packages from pkgsMusl.haskellPackages. I think it makes sense to have this, since we have a similar thing for pkgsStatic. This is in 3981ec7. We can always remove this if it ends up failing. @nh2, would you like me to add these packages to your muslGHCs aggregate job? I imagine you might be interested if any of these Haskell packages fail to build on musl.

Note that these packages are not actually built with the pkgsMusl.haskell.compiler.* GHCs (as explained for pkgsStatic above).

We'd need a different test to check if these compilers are working as intended.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With removePlatforms the need to specify the platforms explicitly should be removed and we could use accumulateDerivations again here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch. I fixed this in fb722f4.

@cdepillabout
Copy link
Copy Markdown
Member Author

cdepillabout commented Jul 19, 2021

@sternenseemann

AFAIK this is mostly historically baggage.

Ah, this makes sense. I didn't realize that GHC doesn't like to be reverse-bootstrapped.


pkgsStatic is cross compiled, so the compiler derivation is pkgsStatic.buildPackages.haskell.compiler.ghc8104 which is neither statically linked nor uses musl at all.

Note that these packages are not actually built with the pkgsMusl.haskell.compiler.* GHCs (as explained for pkgsStatic above).

I played around in the repl a little bit to try to confirm this:

nix-repl> pkgsStatic.haskell.compiler.integer-simple.ghc8104
error: assertion ((stdenv).targetPlatform == (stdenv).hostPlatform) failed at /home/illabout/git/nixpkgs/pkgs/development/compilers/ghc/8.10.2-binary.nix:15:1

nix-repl> pkgsStatic.buildPackages.haskell.compiler.integer-simple.ghc8104
«derivation /nix/store/7ys2bpnfvgn05pcqq0ma6dy5q2352imk-x86_64-unknown-linux-musl-ghc-8.10.4.drv»

nix-repl> pkgsStatic.haskell.packages.integer-simple.ghc8104.hello.passthru.compiler 
«derivation /nix/store/7ys2bpnfvgn05pcqq0ma6dy5q2352imk-x86_64-unknown-linux-musl-ghc-8.10.4.drv»

It looks like this compiler is a dynamically-linked musl GHC, although it is not the same compiler as pkgsMusl.haskell.compiler.ghc8104.

$ nix-build /nix/store/7ys2bpnfvgn05pcqq0ma6dy5q2352imk-x86_64-unknown-linux-musl-ghc-8.10.4.drv
/nix/store/bzbb6mrb9k53hcabzdq1rplsabvm78wb-x86_64-unknown-linux-musl-ghc-8.10.4
$ file /nix/store/bzbb6mrb9k53hcabzdq1rplsabvm78wb-x86_64-unknown-linux-musl-ghc-8.10.4/lib/x86_64-unknown-linux-musl-ghc-8.10.4/bin/ghc
/nix/store/bzbb6mrb9k53hcabzdq1rplsabvm78wb-x86_64-unknown-linux-musl-ghc-8.10.4/lib/x86_64-unknown-linux-musl-ghc-8.10.4/bin/ghc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/mkd3yc1qgkq35xpjy367p4l9zwa11bcn-musl-static-x86_64-unknown-linux-musl-1.2.2/lib/ld-musl-x86_64.so.1, not stripped
$ ldd /nix/store/bzbb6mrb9k53hcabzdq1rplsabvm78wb-x86_64-unknown-linux-musl-ghc-8.10.4/lib/x86_64-unknown-linux-musl-ghc-8.10.4/bin/ghc | grep -i libc
        libc.so => /nix/store/mkd3yc1qgkq35xpjy367p4l9zwa11bcn-musl-static-x86_64-unknown-linux-musl-1.2.2/lib/libc.so

For pkgsMusl:

nix-repl> pkgsMusl.haskell.compiler.ghc8104
«derivation /nix/store/313pagmnlqd7jw86jv5vccld7nwh4xws-ghc-8.10.4.drv»

nix-repl> pkgsMusl.buildPackages.haskell.compiler.ghc8104
«derivation /nix/store/313pagmnlqd7jw86jv5vccld7nwh4xws-ghc-8.10.4.drv»

nix-repl> pkgsMusl.haskellPackages.hello.passthru.compiler
«derivation /nix/store/313pagmnlqd7jw86jv5vccld7nwh4xws-ghc-8.10.4.drv»

It appears that both pkgsMusl.haskell.compiler.ghc8104 and pkgsMusl.buildPackages.haskell.compiler.ghc8104 are the same, and this is a musl-linked GHC:

$ nix-build /nix/store/313pagmnlqd7jw86jv5vccld7nwh4xws-ghc-8.10.4.drv
/nix/store/g42rbg25ify95a1k0057s3s3rkrxhaqz-ghc-8.10.4
$ file /nix/store/g42rbg25ify95a1k0057s3s3rkrxhaqz-ghc-8.10.4/lib/ghc-8.10.4/bin/ghc
/nix/store/g42rbg25ify95a1k0057s3s3rkrxhaqz-ghc-8.10.4/lib/ghc-8.10.4/bin/ghc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/pqnpr7frjq2d28yalzy9di409ph1gnim-musl-1.2.2/lib/ld-musl-x86_64.so.1, not stripped
$ ldd /nix/store/g42rbg25ify95a1k0057s3s3rkrxhaqz-ghc-8.10.4/lib/ghc-8.10.4/bin/ghc | grep -i libc
        libc.so => /nix/store/pqnpr7frjq2d28yalzy9di409ph1gnim-musl-1.2.2/lib/libc.so (0x00007f58ccb9d000)

So it looks like the GHCs used for building pkgsStatics.haskell.packages.*.hello and pkgsMusl.haskellPackages.hello are both musl-linked GHCs.

However, I think I understand what you're trying to say. I imagine it is possible for a non-musl-linked GHC to be able to create binaries that are linked to musl. The libc that GHC itself is built with shouldn't affect the binaries GHC is able to produce, right?? So, in theory, we should be able to have a normal glibc-linked GHC that is able to produce musl-linked Haskell binaries (or even completely statically-linked Haskell binaries)? Although at least right now, it appears this is not the case.

(As you probably can tell, I don't know anything about cross-compilation, so I'm definitely in over my head here. My original goal with this PR was just to get rid of the broken pkgsMusl.haskell.compiler.integer-simple lines from the build report in #130424 (comment), but I fear I've bitten off more than I can chew.)

Comment on lines 313 to 315
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so I think I gave you wrong advice on this since I was confused about pkgsMusl: In contrast to pkgsStatic it compiles natively using musl, so also buildPackages uses musl:

nix-repl> pkgsMusl.buildPackages.stdenv.hostPlatform.isMusl
true

nix-repl> pkgsStatic.buildPackages.stdenv.hostPlatform.isMusl
false

This means that the problem is not the target platform of GHC, but its host platform. The result is a simpler condition:

Suggested change
# integer-simple builds broken when compiling with non-static musl.
# See https://github.com/NixOS/nixpkgs/pull/129606#issuecomment-881323743.
broken = enableIntegerSimple && targetPlatform.isMusl && !targetPlatform.isStatic;
# integer-simple builds are broken when GHC links against musl.
# See https://github.com/NixOS/nixpkgs/pull/129606#issuecomment-881323743.
broken = enableIntegerSimple && hostPlatform.isMusl;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I rebased and made this fix in 67b38e144a681c34.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it just time out? I would have guessed it should work.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, I wasn't sure what was going on here.

With the current status of this PR, I removed this line:

diff --git a/pkgs/top-level/release-haskell.nix b/pkgs/top-level/release-haskell.nix
index 636f0f2b15e..14288b372cb 100644
--- a/pkgs/top-level/release-haskell.nix
+++ b/pkgs/top-level/release-haskell.nix
@@ -258,7 +258,7 @@ let
       pkgsMusl.haskellPackages =
         removePlatforms
           [
-            "aarch64-linux" # aarch64 does not appear to be supported
             "x86_64-darwin" # musl only supports linux
           ]
           {

I then reran hydra-eval-jobs:

$ hydra-eval-jobs -I . pkgs/top-level/release-haskell.nix

Here's the diff comparing running hydra-eval-jobs on release-haskell.nix with the current status of this PR vs. making the above change:

--- current-state    2021-07-24 14:28:55.013105845 +0900
+++ building-on-aarch64    2021-07-24 15:37:46.510185699 +0900
@@ -345373,6 +345373,9 @@
     "system": "x86_64-linux",
     "timeout": 36000
   },
+  "pkgsMusl.haskellPackages.hello.aarch64-linux": {
+    "error": "error: Failed to evaluate ghc-8.10.4: «unsupported»: is not supported on ‘aarch64-linux’"
+  },
   "pkgsMusl.haskellPackages.hello.x86_64-linux": {
     "description": "Hello World, an example package",
     "drvPath": "/nix/store/15dsk39ajxxk71fvp92jjp3cz56qafj8-hello-1.0.0.2.drv",
@@ -345390,6 +345393,9 @@
     "system": "x86_64-linux",
     "timeout": 36000
   },
+  "pkgsMusl.haskellPackages.lens.aarch64-linux": {
+    "error": "error: Failed to evaluate ghc-8.10.4: «unsupported»: is not supported on ‘aarch64-linux’"
+  },
   "pkgsMusl.haskellPackages.lens.x86_64-linux": {
     "description": "Lenses, Folds and Traversals",
     "drvPath": "/nix/store/5yxm6fhlaiq6lw29aypzx5rvir6qirq4-lens-4.19.2.drv",
@@ -345407,6 +345413,9 @@
     "system": "x86_64-linux",
     "timeout": 36000
   },
+  "pkgsMusl.haskellPackages.random.aarch64-linux": {
+    "error": "error: Failed to evaluate ghc-8.10.4: «unsupported»: is not supported on ‘aarch64-linux’"
+  },
   "pkgsMusl.haskellPackages.random.x86_64-linux": {
     "description": "Pseudo-random number generation",
     "drvPath": "/nix/store/k7fhjmvf6ygqm3izzc0i94d2j2rzxib0-random-1.2.0.drv",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I see why this happens: We can only natively bootstrap GHC with musl on x86_64-linux because we only have a musl bindist for this platform since upstream doesn't provide musl builds for aarch64.

With this in mind you probably should just clarify the comment and keep it as is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this up in 95cd2f7.

@sternenseemann
Copy link
Copy Markdown
Member

It looks like this compiler is a dynamically-linked musl GHC, although it is not the same compiler as pkgsMusl.haskell.compiler.ghc8104.

You are right, I got confused a bit and forgot that it is actually possible to natively compile using musl in nixpkgs. This is actually pretty good because it means our issue is not as weird as thought and the broken condition also becomes simpler: #130441 (comment)

So it looks like the GHCs used for building pkgsStatics.haskell.packages.*.hello and pkgsMusl.haskellPackages.hello are both musl-linked GHCs.

Not for pkgsStatic:

nix-repl> pkgsStatic.buildPackages.ghc == ghc
true

However, I think I understand what you're trying to say. I imagine it is possible for a non-musl-linked GHC to be able to create binaries that are linked to musl. The libc that GHC itself is built with shouldn't affect the binaries GHC is able to produce, right?? So, in theory, we should be able to have a normal glibc-linked GHC that is able to produce musl-linked Haskell binaries (or even completely statically-linked Haskell binaries)? Although at least right now, it appears this is not the case.

Yes, this is what happens for pkgsStatic at the moment!

It's btw quite easy to check these things at the source in pkgs/top-level/stage.nix since pkgsMusl and pkgsStatic are just reimports of nixpkgs with the *System args set differently. pkgsMusl uses localSystem without crossSystem if possible (so native compilation):

pkgsMusl = if stdenv.hostPlatform.isLinux then nixpkgsFun {
overlays = [ (self': super': {
pkgsMusl = super';
})] ++ overlays;
${if stdenv.hostPlatform == stdenv.buildPlatform
then "localSystem" else "crossSystem"} = {
parsed = stdenv.hostPlatform.parsed // {
abi = {
gnu = lib.systems.parse.abis.musl;
gnueabi = lib.systems.parse.abis.musleabi;
gnueabihf = lib.systems.parse.abis.musleabihf;
}.${stdenv.hostPlatform.parsed.abi.name}
or lib.systems.parse.abis.musl;
};
};
} else throw "Musl libc only supports Linux systems.";

pkgsStatic always uses crossSystem:

pkgsStatic = nixpkgsFun ({
overlays = [ (self': super': {
pkgsStatic = super';
})] ++ overlays;
crossOverlays = [ (import ./static.nix) ];
} // lib.optionalAttrs stdenv.hostPlatform.isLinux {
crossSystem = {
isStatic = true;
parsed = stdenv.hostPlatform.parsed // {
abi = {
gnu = lib.systems.parse.abis.musl;
gnueabi = lib.systems.parse.abis.musleabi;
gnueabihf = lib.systems.parse.abis.musleabihf;
}.${stdenv.hostPlatform.parsed.abi.name}
or lib.systems.parse.abis.musl;
};
} // lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") {
gcc.abi = "elfv2";
};
});
};

@nh2
Copy link
Copy Markdown
Contributor

nh2 commented Jul 22, 2021

We should really write a comment above pkgsMusl's and pkgsStatic's definitions to make abundantly clear that the former uses native compilation (just with a different libc), and the latter uses cross-compilation.

This confuses people regularly.

@nh2
Copy link
Copy Markdown
Contributor

nh2 commented Jul 22, 2021

The libc that GHC itself is built with shouldn't affect the binaries GHC is able to produce, right?? So, in theory, we should be able to have a normal glibc-linked GHC that is able to produce musl-linked Haskell binaries (or even completely statically-linked Haskell binaries)?

For native (non-cross) compilation as pkgsMusl does it, I am not sure if that is actually possible.

GHC installs not only the compiler, but also static libraries of its dependencies (say, libHSbytestring.a for bytestring). These are built using libc header files, so ABI information like struct field layout can make it in. If, say libHSbytestring.a was built against glibc's struct layout, you cannot then link that libHSbytestring.a into an executable with musl's libc.a; you may get segfaults if an ABI incompatibility is hit.

At leat that's my current understanding; maybe @bgamari or @angerman can state whether it's really on point.

For cross-compilation like pkgsStatic does it, that doesn't happen, because it strictly separates the .a for the build and host platforms, and you'd never link them together. While that gives cross more flexibility (e.g. also being able to actually to cross-compile to a different platform) it's also way more complex than just swapping the libc, and less things work ouf of the box in cross (which is why I use pkgsMusl for static-haskell-nix).

@sternenseemann
Copy link
Copy Markdown
Member

sternenseemann commented Jul 22, 2021

For native (non-cross) compilation as pkgsMusl does it, I am not sure if that is actually possible.

Well since libc is part of the platform for us, using a different libc for the built package and GHC would imply cross compilation per se.

@cdepillabout
Copy link
Copy Markdown
Member Author

@sternenseemann

So it looks like the GHCs used for building pkgsStatics.haskell.packages.*.hello and pkgsMusl.haskellPackages.hello are both musl-linked GHCs.

Not for pkgsStatic:

Ah, I didn't expect pkgsStatic.buildPackages.ghc to be different from pkgsStatic.buildPackages.haskell.compiler.ghc8104 (since they are the same for the normal top-level attributes). Although you're absolutely right:

nix-repl> ghc
«derivation /nix/store/qgp4692xsf4gjpm0ihjzq1wi0yydfh8l-ghc-8.10.4.drv»
nix-repl> haskell.compiler.ghc8104                          
«derivation /nix/store/qgp4692xsf4gjpm0ihjzq1wi0yydfh8l-ghc-8.10.4.drv»
nix-repl> pkgsStatic.buildPackages.ghc
«derivation /nix/store/qgp4692xsf4gjpm0ihjzq1wi0yydfh8l-ghc-8.10.4.drv»
nix-repl> pkgsStatic.buildPackages.haskell.compiler.integer-simple.ghc8104
«derivation /nix/store/7ys2bpnfvgn05pcqq0ma6dy5q2352imk-x86_64-unknown-linux-musl-ghc-8.10.4.drv»
nix-repl> pkgsStatic.buildPackages.haskell.compiler.ghc8104
«derivation /nix/store/62lbrqaqh68pa3bigd064midzsz922wb-x86_64-unknown-linux-musl-ghc-8.10.4.drv»
nix-repl> pkgsStatic.ghc              
«derivation /nix/store/62lbrqaqh68pa3bigd064midzsz922wb-x86_64-unknown-linux-musl-ghc-8.10.4.drv»

For pkgsMusl they are the same though (as you've explained above):

nix-repl> pkgsMusl.buildPackages.ghc
«derivation /nix/store/313pagmnlqd7jw86jv5vccld7nwh4xws-ghc-8.10.4.drv»
nix-repl> pkgsMusl.buildPackages.haskell.compiler.ghc8104
«derivation /nix/store/313pagmnlqd7jw86jv5vccld7nwh4xws-ghc-8.10.4.drv»
nix-repl> pkgsMusl.ghc                     
«derivation /nix/store/313pagmnlqd7jw86jv5vccld7nwh4xws-ghc-8.10.4.drv»
nix-repl> pkgsMusl.haskell.compiler.ghc8104               
«derivation /nix/store/313pagmnlqd7jw86jv5vccld7nwh4xws-ghc-8.10.4.drv»

Also, thanks for the pointers to pkgsMusl and pkgsStatic in stage.nix.

@nh2 Thanks for the clarification on pkgsMusl native compilation and pkgsStatic cross compilation. That all makes complete sense.

…before static

This is just a small reorganization.
These aarch64 builds appear to be timing out.
…ages

The statically-linked Haskell packages on Darwin are not currently
working because libiconv is not building statically on Darwin.

The statically-linked Haskell packages on aarch64 are timing out on Hydra.
integer-simple GHCs appear to be broken when linking against musl and
non-static-linking.
This is helpful to get a small cache going for people
who want musl-enabled packages.
@cdepillabout cdepillabout force-pushed the figure-out-ghc-integer-simple branch from fb722f4 to 75420df Compare July 24, 2021 05:44
@sternenseemann
Copy link
Copy Markdown
Member

sternenseemann commented Sep 18, 2021

I'm surprised this is a problem. I was under the impression that absolutely no Haskell stuff built with pkgsMusl recently

Niklas fixed a regression, the binary GHC started to segfault with musl due to a new ABI incompatibility. 20.05 was a long time ago and any number of things could have changed in upstream projects as well as nixpkgs. It doesn't really help that pkgsMusl tends to be a less tested codepath in nixpkgs as well.

integer-simple probably should work, it's just a matter of working out what the build system is doing. I think Niklas had a sound theory what the problem was and it may or may not be easy to fix.

@cdepillabout
Copy link
Copy Markdown
Member Author

@nomeata Oh, and I imagine you likely know this, but we of course would like pkgsMusl integer-simple to be working. If you wanted to investigate and potentially send a patch, we would definitely merge it in!

@nomeata
Copy link
Copy Markdown
Contributor

nomeata commented Sep 18, 2021

I am just a grateful user, and usually out of my depth fixing these problems, so the most I sometimes can do is cargo cult something based on random guesses or patches I see floating around

But with

~/build/nixpkgs $ git diff
diff --git a/pkgs/development/compilers/ghc/8.8.4.nix b/pkgs/development/compilers/ghc/8.8.4.nix
index e2a65a19791..cd7f5e709df 100644
--- a/pkgs/development/compilers/ghc/8.8.4.nix
+++ b/pkgs/development/compilers/ghc/8.8.4.nix
@@ -125,7 +125,7 @@ let
   # Splicer will pull out correct variations
   libDeps = platform: lib.optional enableTerminfo ncurses
     ++ [libffi]
-    ++ lib.optional (!enableIntegerSimple) gmp
+    ++ [gmp]
     ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
 
   toolsForTarget = [
@@ -343,7 +343,7 @@ stdenv.mkDerivation (rec {
 
     # integer-simple builds are broken when GHC links against musl.
     # See https://github.com/NixOS/nixpkgs/pull/129606#issuecomment-881323743.
-    broken = enableIntegerSimple && hostPlatform.isMusl;
+    # broken = enableIntegerSimple && hostPlatform.isMusl;
   };
 
   dontStrip = (targetPlatform.useAndroidPrebuilt || targetPlatform.isWasm);

it at least links Cabal and then makes progress with the build. Maybe building GHC now needs gmp around, even though it’s not using it? Or maybe the bootstrap GHC derivation should have a run-time dependency on gmp? … I’ll wait for this to finish and then report.

@sternenseemann
Copy link
Copy Markdown
Member

Yeah, iirc that was Nilkas' theory as well. Adding gmp to buildInputs (should maybe be nativeBuildInputs?) may be save to add in conjunction with disallowedRequisites to prevent gmp from leaking into the resulting GHC.

Can maybe look into this later after I've finished compiling GHCJS :p

@nomeata
Copy link
Copy Markdown
Contributor

nomeata commented Sep 18, 2021

Ha, with that, nix-build -A pkgsMusl.haskell.packages.integer-simple.ghc884.hello works indeed! Whether buildInputs or nativeBuildInputs I’ll leave to the experts :-)

nomeata added a commit to nomeata/nixpkgs that referenced this pull request Sep 18, 2021
as per discussion on
NixOS#130441 (comment) this
seems to be enough to make
```
nix-build -A pkgsMusl.haskell.packages.integer-simple.ghc884.hello
```
work again.

This is likely not the right patch (maybe `gmp` should be
`nativeBuildInput`? Or a propagated build input from the boot ghc?), but
this way I we can discuss (and I can pull the patch into my project...)
@nomeata
Copy link
Copy Markdown
Contributor

nomeata commented Sep 18, 2021

And my project (building a relatively large Haskell binary statically) also works again with that. So I think this can be solved.

Shall we continue the discussion on #138429?

@nh2
Copy link
Copy Markdown
Contributor

nh2 commented Sep 19, 2021

@nomeata For the background:

Not sure why integer-simple worked at some point in the past, but not after your improvements.

The reason why it worked was pure luck (as far as I can tell): In the past the ghc865-binary bindist bootstrap compiler was linked against glibc and then nixpkgs patched it to run with musl; its ldd showed it linked against 2 different libcs at the same time, and they have no binary compatibility. I think it only worked because the struct layout of the libc parts that GHC uses were coincidentally the same. As soon as a newer version of musl slightly changed something, we got the segfault you reported on #118731.

In my commit da1cf8c I deleted the no-longer-working glibc+musl binary patching hack, and instead used upstream GHC's musl-only bindist (no glibc involved) for all musl-related builds.

But that one nobody had made work with integer-simple yet, and I hadn't had time to figure out a solution in #129606 (comment).

@nomeata
Copy link
Copy Markdown
Contributor

nomeata commented Sep 19, 2021

Thanks! That makes sense. But it seems to be reach now? Or is a fix along the lines of #138429 the wrong direction?

@nh2
Copy link
Copy Markdown
Contributor

nh2 commented Sep 19, 2021

Looking at the latest Hydra evaluation for #129606, we can see what is not working for GHC musl integer-simple:

https://hydra.nixos.org/eval/1686753?filter=integer-simple&compare=1686725

Retaining here the actual error message from the build log in case Hydra cleans that up in the future:

[292 of 293] Compiling Distribution.Simple ( libraries/Cabal/Cabal/Distribution/Simple.hs, bootstrapping/Distribution/Simple.o )
[293 of 293] Compiling Main             ( utils/ghc-cabal/Main.hs, bootstrapping/Main.o )
Linking utils/ghc-cabal/dist/build/tmp/ghc-cabal ...
/nix/store/8i49006sm0m9d0kri4i4hg7yndn1646b-binutils-2.35.1/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
utils/genprimopcode/ghc.mk:19: utils/genprimopcode/dist/package-data.mk: No such file or directory
make[1]: *** [utils/ghc-cabal/ghc.mk:58: utils/ghc-cabal/dist/build/tmp/ghc-cabal] Error 1
make: *** [Makefile:124: all] Error 2

That is, the pkgsMusl.haskell.compiler.integer-simple.ghc8104 fails to build, very early:

The first thing that gets built is the Cabal library, and that one's binary ghc-cabal fails to link, with error ld: cannot find -lgmp.

So the situation is that we're building an integer-simple-GHC, using an integer-gmp-GHC.

During that build, a bootstrapping Cabal build is done, and that one needs gmp (the integer-simple-Cabal is built only later). The bootstrap-Cabal is compiled by the GHC passed into the nixpkgs derivation (so probably pkgsMusl.haskell.compiler.ghc8102BinaryMinimal, see here).

And that ghc8102BinaryMinimal GHC HQ musl bindist cannot do an -lgmp link, unless gmp is put into buildInputs of the build in which it is used (that is, e.g. in pkgsMusl.haskell.compiler.integer-simple.ghc8104, where the new draft PR #138429 puts it).


(Background interlude: GHC HQ could choose to build their musl compiler bindist [our pkgsMusl.haskell.compiler.ghc8102BinaryMinimal] with integer-gmp, or integer-simple. Both are valid options. And GHC switched that recently from GMP to integer-simple in the middle of the 8.10 series with PR "Use --integer-simple in 8.10 ci builds for alpine", and plans to do the same for the 9.* series with ticket "Add native BIGNUM_BACKED release jobs for alpine on 9.0 and 9.2" is about switching from one to another.)

From here, there are 2 alternative hypotheses:

  1. The pkgsMusl.haskell.compiler.ghc8102BinaryMinimal is compiled with gmp, thus producing outputs that need gmp. If so, the hypothesis is that it correctly passes -lgmp to the linker (we observe that), but -L/path/to/gmp/lib is not passed to the linker.
  • The lack of -L flags could be either because GHC itself does something wrong, or because the nix packaging of that binary compiler is wrong.
  1. The pkgsMusl.haskell.compiler.ghc8102BinaryMinimal is compiled with integer-simple. In that case neither it, nor the pkgsMusl.haskell.compiler.integer-simple.ghc8104 build system have anything to do with gmp, so here the hypothesis would be that something incorrectly adds the -lgmp flag.

Both hypotheses are consistent with the fact that PR #138429 fixes the build, probably because putting gmp into buildInputs makes -L/path/to/gmp happen via some mechanism.

To check which hypothesis to follow, let's check whether the GHC HQ musl bindist is linked against gmp or not:

$ NIX_PATH=nixpkgs=. nix-build --no-out-link -A pkgsMusl.haskell.compiler.ghc8102BinaryMinimal
/nix/store/46gsa77gx5vxk3lija8y3s54mgn5gx86-ghc-8.10.2-binary

$ ldd /nix/store/46gsa77gx5vxk3lija8y3s54mgn5gx86-ghc-8.10.2-binary/lib/ghc-8.10.2/bin/ghc | grep gmp
	libHSinteger-gmp-1.0.3.0-ghc8.10.2.so => /nix/store/46gsa77gx5vxk3lija8y3s54mgn5gx86-ghc-8.10.2-binary/lib/ghc-8.10.2/bin/../lib/x86_64-linux-ghc-8.10.2/libHSinteger-gmp-1.0.3.0-ghc8.10.2.so (0x00007f21012d8000)
	libgmp.so.10 => /nix/store/r4fnrxfbn9z7lpd359ij1r9wl2ccqdwq-gmp-6.2.1/lib/libgmp.so.10 (0x00007f2100b4b000)

# Alternatively:
$ cat /nix/store/46gsa77gx5vxk3lija8y3s54mgn5gx86-ghc-8.10.2-binary/lib/ghc-8.10.2/lib/settings | grep -i gmp
,("integer library", "integer-gmp")

Yes, it is.

So we are in hypothesis 1.

Thus I think we should investigate:

  • Is it true as suspected that ghc passes -lgmp but not -L/path/to/gmp/lib?
    • This could be confirmed with strace.
  • Given that pkgsMusl.haskell.compiler.ghc8102BinaryMinimal is a gmp-GHC, it should should remember which /path/to/gmp/lib it was configured with, and pass it as -L. But maybe it remembers that as some /usr/lib/gmp because it was built on Alpine by GHC HQ, and the nix-packaging of that binary compiler does not ensure that that is changed to the nix location of gmp.
    • In that case, the pkgsMusl.haskell.compiler.ghc8102BinaryMinimal derivation probably has to be fixed.

Doing a bit of that investigation myself here:

$ cat $(NIX_PATH=nixpkgs=. nix-build --no-out-link -A pkgsMusl.haskell.compiler.ghc8102BinaryMinimal)/lib/ghc-8.10.2/lib/package.conf.d/integer-gmp-1.0.3.0.conf
name:                 integer-gmp
version:              1.0.3.0
...
extra-libraries:      gmp
include-dirs:
    ${pkgroot}/../lib/x86_64-linux-ghc-8.10.2/integer-gmp-1.0.3.0/include
...

extra-libraries will make that -lgmp is passed. But there's nothing in there that'll ensure that -L flags are passed, and no /path/to/gmp/lib seems recorded anywhere by GHC itself.

On the nix side:

$ grep -R gmp $(NIX_PATH=nixpkgs=. nix-build --no-out-link -A pkgsMusl.haskell.compiler.ghc8102BinaryMinimal)
...
/nix/store/46gsa77gx5vxk3lija8y3s54mgn5gx86-ghc-8.10.2-binary/nix-support/propagated-build-inputs:/nix/store/yifn7mx0g40zzarb33fk6ms7s4s4krdr-gmp-6.2.1-dev 

$ cat /nix/store/yifn7mx0g40zzarb33fk6ms7s4s4krdr-gmp-6.2.1-dev/lib/pkgconfig/gmp.pc
....
libdir=/nix/store/r4fnrxfbn9z7lpd359ij1r9wl2ccqdwq-gmp-6.2.1/lib
...
Libs: -L${libdir} -lgmp

It looks like nix puts gmp.dev into propagated-build-inputs, which includes a pkg-config .pc file. But GHC does not use pkg-config for finding libraries (we have extra-libraries: gmpabove, which translates directly to-lgmp`).

The propagated-build-inputs exists because we have for 8.10.2-binary.nix:

  propagatedBuildInputs = ...
    ++ lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this

It has a handy comment on top (apparently I wrote it here):

# Because musl bindists currently provide no way to tell where
# libgmp is (see not [musl bindists have no .buildinfo]), we need
# to propagate `gmp`, otherwise programs built by this ghc will
# fail linking with `cannot find -lgmp` errors.
# Also, as of writing, the release pages of musl bindists claim
# that they use `integer-simple` and do not require `gmp`; however
# that is incorrect, so `gmp` is required until a release has been
# made that includes https://gitlab.haskell.org/ghc/ghc/-/issues/20059.
# (Note that for packaging the `-binary` compiler, nixpkgs does not care
# about whether or not `gmp` is used; this comment is just here to explain
# why the `gmp` dependency exists despite what the release page says.)
++ lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this

The mentioned note [musl bindists have no .buildinfo] says:

# We have to patch the GMP paths for the integer-gmp package.
# Note [musl bindists have no .buildinfo]
# Note that musl bindists do not contain them; unclear if that's intended;
# see: https://gitlab.haskell.org/ghc/ghc/-/issues/20073#note_363231
''
find . -name integer-gmp.buildinfo \
-exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${gmp.out}/lib@" {} \;

musl bindists do not contain them seems critical here. This explains the

no /path/to/gmp/lib seems recorded anywhere by GHC itself

I remarked further up.

Following the linked ticket, I pointed out

The musl bindist also does not have any .buildinfo files, so in nixpkgs we cannot patch integer-gmp.buildinfo to tell it where the paths are.

So that's probably the root cause of this problem.

It looks like GHC HQ did not intend to make the musl bindists with gmp-enabled, but accidentally did (and lacking said -L paths). The linked fix is not to add the -L paths / fix the .buildinfo files, but instead to switch the GHC musl bindist to not use gmp at all. According to Gitlab (and PR), that change is in ghc-8.10.6-release and onwards, but nixpkgs uses the older version ghc8102BinaryMinimal.

Summary

  • The GHC HQ 8.10.2 musl bindist is built gmp-enabled and passes -lgmp, but incorrectly has no .buildinfo to remember the -L/path/to/gmp path.
    • That problem doesn't exist for non-musl builds because the non-musl GHC HQ bindists have the .buildinfo, so there nixpkgs sed to override them has the intended effect of giving the correct -L/path/to/gmp as ${gmp.out}/lib.
  • My propagatedBuildInputs = lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this doesn't seem to do too much.
    • Maybe this needs to be gmp.out instead of gmp, so that not only gmp-dev shown above is propagated?
    • We need to check if it provides any benefit at all. It probably did something given that I added it, but it is also possible that I added it purely because it was logically correct based on the insight of the above tickets, and didn't notice that I should have used gmp.out instead of gmp because the latter only includes development libraries. Somebody has to try making that change.
      • Edit: It does make a difference (my comment below) -- it fixes other packages, but unclear why not the GHC build.
  • When we switch from ghc8102BinaryMinimal to ghc8107BinaryMinimal, probably the whole situation will change, because the latter will have nothing to do with gmp. So that should fix the pkgsMusl.haskell.compiler.integer-simple builds, but might break the pkgsMusl non-integer-simple builds.

Phew. This message got longer than I originally planned.

@nomeata
Copy link
Copy Markdown
Contributor

nomeata commented Sep 19, 2021

Wow, thanks a lot! Such comments are immensely helpful for those of use still learning (like me…)

@nomeata
Copy link
Copy Markdown
Contributor

nomeata commented Sep 19, 2021

Maybe this needs to be gmp.out instead of gmp, so that not only gmp-dev shown above is propagated?

That does not seem to work, I still get the linker error after building Cabal.

@nh2
Copy link
Copy Markdown
Contributor

nh2 commented Sep 19, 2021

That does not seem to work, I still get the linker error after building Cabal.

Indeed:

--- a/pkgs/development/compilers/ghc/8.10.2-binary.nix
+++ b/pkgs/development/compilers/ghc/8.10.2-binary.nix
@@ -154,7 +154,7 @@ stdenv.mkDerivation rec {
     # (Note that for packaging the `-binary` compiler, nixpkgs does not care
     # about whether or not `gmp` is used; this comment is just here to explain
     # why the `gmp` dependency exists despite what the release page says.)
-    ++ lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this
+    ++ lib.optionals stdenv.hostPlatform.isMusl [ gmp.out ]; # musl bindist needs this

Reading:

It looks like propagatedBuildInputs won't help us much, as it is mainly concerned with PATH.

Maybe there's other things it can help with -- happy for any pointers!

So far I've tested what happens when i remove it completely:

-    ++ lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this

First, pkgsMusl.haskell.compiler.ghc8102Binary fails the build in its installCheckPhase that tries to compile a Hello-World:

running install tests
[1 of 1] Compiling Main             ( main.hs, main.o, main.dyn_o )
Linking main ...
/nix/store/8i49006sm0m9d0kri4i4hg7yndn1646b-binutils-2.35.1/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
builder for '/nix/store/73z0l0x6fjv783lnmfbsn26xpd9d1mg8-ghc-8.10.2-binary.drv' failed with exit code 1

When I put it into buildInputs instead of propagatedBuildInputs:

-    ++ lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this
+    ;
+  buildInputs = [ gmp ];

then pkgsMusl.haskell.compiler.ghc8102Binary and its installCheckPhase build fine, but everything compiled with it fails to compile Setup.hs -> ./Setup:

# NIX_PATH=nixpkgs=. nix-build --no-out-link -A pkgsMusl.haskell.compiler.ghc8104      
these derivations will be built:
  /nix/store/6wfb45rx523w6d4jpvbc1ddmiwfg2rmj-ghc-8.10.2-binary.drv
  /nix/store/33ymd3y2104lca5gpb19fvkgji4pk5h6-happy-1.20.0.drv
  /nix/store/5c8xax4dvf731f3y11xggl82651fih20-hscolour-1.24.4.drv
  /nix/store/ab1cmk4pf2w18zzj7ywsf90ag5zk54yv-hscolour-1.24.4.drv
  /nix/store/wkrbajj3p6bi93fmn24v5k84h7va07im-alex-3.2.6.drv
  /nix/store/29x5r64p2q679nxrafin9h6p6nlxyp1q-ghc-8.10.4.drv
...
compileBuildpDriverPhase
setupCompileFlags: -package-db=/build/setup-package.conf.d -j16 +RTS -A64M -RTS -threaded -rtsopts
[1 of 1] Compiling Main             ( Setup.hs, /build/Main.o )
[1 of 1] Compiling Main             ( Setup.hs, /build/Main.o )
Linking Setup ...
Linking Setup ...
/nix/store/8i49006sm0m9d0kri4i4hg7yndn1646b-binutils-2.35.1/bin/ld: cannot find -lgmp
/nix/store/8i49006sm0m9d0kri4i4hg7yndn1646b-binutils-2.35.1/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
builder for '/nix/store/33ymd3y2104lca5gpb19fvkgji4pk5h6-happy-1.20.0.drv' failed with exit code 1

So propagatedBuildInputs = lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; does help for those, but:

  • It's unclear to me why they help here (via what mechanism).
  • It's unclear to me why that mechanism doesn't also help for the compiling-GHC problem in this ticket.

@nh2
Copy link
Copy Markdown
Contributor

nh2 commented Sep 19, 2021

According to Gitlab (and PR), that change is in ghc-8.10.6-release and onwards, but nixpkgs uses the older version ghc8102BinaryMinimal.

I have now reflected that in PR #138523 in our packaging of ghc8107BinaryMinimal, which still had the gmp dependency copy-pasted in propagatedBuildInputs.

@nh2
Copy link
Copy Markdown
Contributor

nh2 commented Sep 19, 2021

  • When we switch from ghc8102BinaryMinimal to ghc8107BinaryMinimal, probably the whole situation will change, because the latter will have nothing to do with gmp. So that should fix the pkgsMusl.haskell.compiler.integer-simple builds, but might break the pkgsMusl non-integer-simple builds.

I have made PR #138524, which switches ghc8102Binary -> ghc8107Binary as the bootstrap compiler.

If we're lucky, this will fix the problems.

I will need others to test if it works well though, as I don't have much time currently.

marcin-dziadus pushed a commit to dfinity/ic-hs that referenced this pull request Sep 20, 2021
* Experiment: Bump nixpkgs to latest master

This is to see if there are problems coming up. Some of the things in
nix/haskell-packages.nix can probably be cleaned up now.

Originally https://github.com/dfinity-lab/ic-ref/commit/dce1286a900525607fcc21171b82940e3ec3385f

* Bump again

Originally https://github.com/dfinity-lab/ic-ref/commit/b43f83609fd3a99e0a8ecd8700f4baee0c53b863

* Bump once more

Originally https://github.com/dfinity-lab/ic-ref/commit/a0746ed7be49c8f1619e5b75ba84d5c832730cf8

* Fix merge issue

* Fix path

* Back to master

* Try winter master

* Remove many haskell package changes

* More simplification and upstream cache use

* Update freeze file

* Less versionoverrides needed

* Remove nix/haskell-packages, more DNRY

* Fix patch handling

* Add .gitattributes to mark generated files as such

* s/	/        /

* Run github actions with ghc-8.10.7

* Fix docs jobs

* Fix docs jobs some more

* Update cabal.project

* Bump candid some more

* Checkout before setting up the cache

* Fix cabal keys

* Don’t set active-repositories in freeze file

* Rename workflow

* naersk changed it seems

* Try pkgsStatic, not pkgsMusl

as the latter doesn’t seem to work any more since
NixOS/nixpkgs#130441

* Fix static cborg build

* Try static-haskell-nix

* Revert "Try static-haskell-nix"

This reverts commit b375ad4.

* Revert "Try pkgsStatic, not pkgsMusl"

This reverts commit d1f64f1.

* Try pkgsMusl again

pulling in NixOS/nixpkgs#138429

* Update freeze file

* Right GHC version

* Try NixOS/nixpkgs#138524
nh2 added a commit to nh2/nixpkgs that referenced this pull request Sep 20, 2021
…endency.

GHC HQ switched the musl bindists from gmp to `integer-simple`
with GHC >= 8.10.6, but this was not reflected in the nixpkgs update:

* commit 6f12424: ghc: 8.10.5-binary -> 8.10.7-binary
  From PR NixOS#135453

See also NixOS#130441.
nh2 added a commit to nh2/nixpkgs that referenced this pull request Sep 20, 2021
sternenseemann pushed a commit that referenced this pull request Sep 23, 2021
…endency.

GHC HQ switched the musl bindists from gmp to `integer-simple`
with GHC >= 8.10.6, but this was not reflected in the nixpkgs update:

* commit 6f12424: ghc: 8.10.5-binary -> 8.10.7-binary
  From PR #135453

See also #130441.
sternenseemann added a commit to sternenseemann/nixpkgs that referenced this pull request Sep 23, 2021
This fixes musl+integer-simple, see NixOS#130441.

Co-Authored-By: sternenseemann <sternenseemann@systemli.org>
sternenseemann added a commit that referenced this pull request Sep 23, 2021
This fixes musl+integer-simple, see #130441.

Co-Authored-By: sternenseemann <sternenseemann@systemli.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: haskell General-purpose, statically typed, purely functional programming language 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants