Skip to content

Commit

Permalink
Trying to create static Haskell binaries using Nix
Browse files Browse the repository at this point in the history
Unfortunately, the build fails with

/nix/store/cdbsfljc8m900axs37fab7gnp2y1dksn-binutils-2.31.1/bin/ld: /nix/store/x0ybqvkk6h6x8mhsy5gghplsfvammq6q-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-musl/9.3.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
/nix/store/cdbsfljc8m900axs37fab7gnp2y1dksn-binutils-2.31.1/bin/ld: /nix/store/x0ybqvkk6h6x8mhsy5gghplsfvammq6q-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-musl/9.3.0/crtend.o: relocation R_X86_64_32 against `.ctors' can not be used when making a shared object; recompile with -fPIC

This may be related to

- nh2/static-haskell-nix#99
- input-output-hk/haskell.nix#914
  • Loading branch information
timjb committed Dec 13, 2020
1 parent de2c832 commit 419ee1e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
12 changes: 12 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,17 @@
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/65c9cc79f1d179713c227bf447fb0dac384cdcda.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"static-haskell-nix": {
"branch": "master",
"description": "easily build most Haskell programs into fully static Linux executables",
"homepage": "",
"owner": "nh2",
"repo": "static-haskell-nix",
"rev": "382150290ba43b6eb41981c1ab3b32aa31798140",
"sha256": "0zsyplzf1k235rl26irm27y5ljd8ciayw80q575msxa69a9y2nvd",
"type": "tarball",
"url": "https://github.com/nh2/static-haskell-nix/archive/382150290ba43b6eb41981c1ab3b32aa31798140.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
47 changes: 26 additions & 21 deletions project.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
{ compiler ? "ghc865", sources ? import ./nix/sources.nix }:

let
config = {
packageOverrides = pkgs: rec {
haskell = pkgs.haskell // {
packages = pkgs.haskell.packages // {
"${compiler}" = pkgs.haskell.packages."${compiler}".override {
overrides = haskellPackagesNew: haskellPackagesOld: rec {
envy = haskellPackagesNew.callPackage ./nix/envy.nix {}; # old version (< 2) depended on by envy
hal = pkgs.haskell.lib.markUnbroken haskellPackagesOld.hal;
telegram-api = haskellPackagesNew.callPackage ./nix/haskell-telegram-api.nix {}; # patched version from git repo
halma = haskellPackagesNew.callPackage ./halma/halma.nix {};
halma-telegram-bot = haskellPackagesNew.callPackage ./halma-telegram-bot/halma-telegram-bot.nix {};
servant-server = pkgs.haskell.lib.dontCheck haskellPackagesOld.servant-server; # tests fail to compile
};
};
nonStaticPkgs =
with
{ overlay = _: pkgs: { niv = import sources.niv {}; }; };
import sources.nixpkgs { overlays = [ overlay ]; };

staticPkgs = (import "${sources.static-haskell-nix}/survey/default.nix" { compiler = compiler; normalPkgs = nonStaticPkgs; }).pkgs;
haskellLib = staticPkgs.haskell.lib;

staticHaskellPkgs = staticPkgs.haskell.packages.${compiler}.override {
overrides = haskellPackagesNew: haskellPackagesOld: rec {
envy = haskellPackagesNew.callPackage ./nix/envy.nix {}; # old version (< 2) depended on by envy
hal = haskellLib.markUnbroken haskellPackagesOld.hal;
telegram-api = haskellPackagesNew.callPackage ./nix/haskell-telegram-api.nix {}; # patched version from git repo
halma = haskellPackagesNew.callPackage ./halma/halma.nix {};
halma-telegram-bot = haskellLib.overrideCabal
(haskellLib.justStaticExecutables (haskellPackagesNew.callPackage ./halma-telegram-bot/halma-telegram-bot.nix {}))
{
configureFlags = [
"--ghc-option=-optl=-static"
"--extra-lib-dirs=${staticPkgs.gmp6.override { withStatic = true; }}/lib"
"--extra-lib-dirs=${staticPkgs.zlib.static}/lib"
"--extra-lib-dirs=${staticPkgs.libffi.overrideAttrs (old: { dontDisableStatic = true; })}/lib"
#"--disable-executable-stripping"
];
};
};
servant-server = haskellLib.dontCheck haskellPackagesOld.servant-server; # tests fail to compile
};
};

pkgs =
with
{ overlay = _: pkgs: { niv = import sources.niv {}; }; };
import sources.nixpkgs { overlays = [ overlay ]; inherit config; };

in
{ halma-telegram-bot = pkgs.haskell.packages.${compiler}.halma-telegram-bot;
{ halma-telegram-bot = staticHaskellPkgs.halma-telegram-bot;
}

0 comments on commit 419ee1e

Please sign in to comment.