Skip to content

Instantly share code, notes, and snippets.

@bts
Created January 3, 2018 15:46
Show Gist options
  • Save bts/0f0abdef6f69b1a165181ef1d1be0360 to your computer and use it in GitHub Desktop.
Save bts/0f0abdef6f69b1a165181ef1d1be0360 to your computer and use it in GitHub Desktop.
[1 of 1] Compiling Columnate ( src/Columnate.hs, dist/build/Columnate.o )
/nix/store/drcl6z8jqwkqkbwspilyk017biyfd969-binutils-2.28.1/bin/ld: /nix/store/v8qa2qbwrb7s8b4piygdiii7p7jpv068-gcc-6.4.0/lib/gcc/x86_64-unknown-linux-gnu/6.4.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
/nix/store/drcl6z8jqwkqkbwspilyk017biyfd969-binutils-2.28.1/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
@vaibhavsagar
Copy link

I don't think that made a difference either. For posterity:

{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc822" }:

let

  inherit (nixpkgs) pkgs;

  gcc-hack = pkgs.wrapCC (pkgs.runCommand "gcc" {
      src = pkgs.gcc-unwrapped;
      isGNU = true;
    } ''
      mkdir -p $out
      cp -r --no-preserve=mode,ownership $src/* $out
      cd $out/lib/gcc/x86*/6*
      cp crtbeginS.o crtbeginT.o
    '');

  f = { mkDerivation, base, hedgehog, optparse-generic, stdenv
      , tasty, tasty-hedgehog, text, these
      }: let
        these' = pkgs.haskell.lib.doJailbreak these;
        stdenv' = stdenv.override { allowedRequisites = null; cc = gcc-hack; };
        mkDerivation' = args: (mkDerivation args).overrideDerivation (drv: { stdenv = stdenv'; });
      in
      mkDerivation' {
        pname = "columnate";
        version = "0.1.0.0";
        src = ./.;
        isLibrary = true;
        isExecutable = true;
        libraryHaskellDepends = [ base optparse-generic text these' ];
        executableHaskellDepends = [ base ];
        testHaskellDepends = [ base hedgehog tasty tasty-hedgehog text ];
        homepage = "http://github.com/bts/columnate";
        description = "Columnate data sets while preserving color codes";
        license = pkgs.stdenv.lib.licenses.bsd3;
        enableSharedExecutables = false;
        configureFlags = [
          "--ghc-option=-optl=-static"
          "--ghc-option=-optl=-pthread"
          "--ghc-option=-optl=-L${pkgs.gmp5.static}/lib"
          "--ghc-option=-optl=-L${pkgs.glibc.static}/lib"
          "--ghc-option=-fPIC"
        ];
      };

  haskellPackages = if compiler == "default"
                       then pkgs.haskellPackages
                       else pkgs.haskell.packages.${compiler};

  drv = haskellPackages.callPackage f {};

in

  if pkgs.lib.inNixShell then drv.env else drv

And the error seems to be related to https://stackoverflow.com/questions/44429253/building-a-shared-library-created-a-static-library-instead

@vaibhavsagar
Copy link

vaibhavsagar commented Jan 17, 2018

I did it! I got a pull request vaibhavsagar/experiments#3 that clarified a few things. Here's a working derivation:

{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc822" }:

let

  inherit (nixpkgs) pkgs;

  f = { mkDerivation, base, hedgehog, optparse-generic, stdenv
      , tasty, tasty-hedgehog, text, these
      }: let
        these' = pkgs.haskell.lib.doJailbreak these;
      in
      mkDerivation {
        pname = "columnate";
        version = "0.1.0.0";
        src = ./.;
        isLibrary = true;
        isExecutable = true;
        libraryHaskellDepends = [ base optparse-generic text these' ];
        executableHaskellDepends = [ base ];
        testHaskellDepends = [ base hedgehog tasty tasty-hedgehog text ];
        homepage = "http://github.com/bts/columnate";
        description = "Columnate data sets while preserving color codes";
        license = pkgs.stdenv.lib.licenses.bsd3;
        enableSharedExecutables = false;
        enableSharedLibraries = false;
        configureFlags = [
          "--ghc-option=-optl=-static"
          "--ghc-option=-optl=-L${pkgs.gmp5.static}/lib"
          "--ghc-option=-optl=-L${pkgs.glibc.static}/lib"
          "--ghc-option=-fPIC"
        ];
      };

  haskellPackages = if compiler == "default"
                       then pkgs.haskellPackages
                       else pkgs.haskell.packages.${compiler};

  drv = haskellPackages.callPackage f {};

in

  if pkgs.lib.inNixShell then drv.env else drv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment