lunaris/minirepo

Question: Is changing ghc version built possible ?

Closed this issue · 2 comments

573 commented

I'm trying to get anything else than version ghc-8.6.5 using this default.nix:

# NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/830ef6422f643d5c639fd79bca834c726787ec51.tar.gz nix-build --no-link -A staticHaskell.ghc
let
  baseNixpkgs = builtins.fetchTarball {
    name = "nixos-nixpkgs";
    url = "https://github.com/NixOS/nixpkgs/archive/830ef6422f643d5c639fd79bca834c726787ec51.tar.gz";
    sha256 = "0lghz9c5kl4ivp44v4ggyl5cdrd3xr8vljgh8r6541a06qynriah";
  };

  staticHaskellNixpkgs = builtins.fetchTarball
    "https://github.com/nh2/static-haskell-nix/archive/382150290ba43b6eb41981c1ab3b32aa31798140.tar.gz";
in
let
  staticHaskellPkgs = (
    import (staticHaskellNixpkgs + "/survey/default.nix") {}
  ).approachPkgs;
in
let
  overlay = self: super: {
    staticHaskell = staticHaskellPkgs.extend (selfSH: superSH: {
      ghc = (superSH.ghc.override {
        enableRelocatedStaticLibs = true;
        enableShared = false;
      }).overrideAttrs (oldAttrs: {
        preConfigure = ''
          ${oldAttrs.preConfigure or ""}
          echo "GhcLibHcOpts += -fPIC -fexternal-dynamic-refs" >> mk/build.mk
          echo "GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs" >> mk/build.mk
        '';
      });
    });
  };
in
  args@{ overlays ? [], ... }:
    import baseNixpkgs (args // {
      overlays = [overlay] ++ overlays;
    })

/nix/store/wycg9jvnswi4597ya6zyqgyaaa9bzy9x-ghc-8.6.5
$ ldd /nix/store/wycg9jvnswi4597ya6zyqgyaaa9bzy9x-ghc-8.6.5/lib/ghc-8.6.5/bin/ghc
linux-vdso.so.1 (0x00007fff109ed000)
libncursesw.so.6 => /nix/store/x1kcjwlc5ykhns1qvkcpj5464m1vx4cf-ncurses-6.1-20190112/lib/libncursesw.so.6 (0x00007f53a5189000)
libgmp.so.10 => /nix/store/pmail2mg8ybrygr1m3izzc0klvr1mgkz-gmp-6.1.2/lib/libgmp.so.10 (0x00007f53a50f5000)
libffi.so.7 => /nix/store/02a76sbyi6k112ha6nyvs02kpxka732b-libffi-3.3/lib/libffi.so.7 (0x00007f53a50e8000)
libc.so => /nix/store/38x422ih7aybxkw457xnf5d9mg82a5m0-musl-1.1.24/lib/libc.so (0x00007f53a5038000)
$ file /nix/store/wycg9jvnswi4597ya6zyqgyaaa9bzy9x-ghc-8.6.5/lib/ghc-8.6.5/bin/ghc
/nix/store/wycg9jvnswi4597ya6zyqgyaaa9bzy9x-ghc-8.6.5/lib/ghc-8.6.5/bin/ghc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/38x422ih7aybxkw457xnf5d9mg82a5m0-musl-1.1.24/lib/ld-musl-x86_64.so.1, with debug_info, not stripped

573 commented

Coming from NixOS/nixpkgs#124284
Via:

https://www.tweag.io/blog/2020-09-30-bazel-static-haskell/

This seems to be another valid solution that doesn't require a mixed static/shared overlay.

To achieve this [only compiling static libraries] we need to build GHC with a static RTS and to make sure that Haskell code is compiled as position independent code so that it can be loaded into a running GHC for template Haskell splices.

Originally posted by @rnhmjoj in NixOS/nixpkgs#61575 (comment)

573 commented

Nevermind just saw it's somewhere around here