Build stackage2nix-static
Currently build fails with:
$ nix-build nixpkgs.nix -A stackage2nix-static
...
[ 7 of 15] Compiling Stack.Config.TH ( src/Stack/Config/TH.hs, dist/build/Stack/Config/TH.o )
[ 8 of 15] Compiling Stack.Config.Yaml ( src/Stack/Config/Yaml.hs, dist/build/Stack/Config/Yaml.o )
/nix/store/4576wq2aj36yhdqck4rfyxg16c1s0r1y-icu4c-58.2-static/lib/libicuuc.a(putil.ao): In function `uprv_dl_open_58':
(.text+0x1ba2): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/nix/store/zi17ydzr9x1kqjcpfjr93iwg1frpmv8s-binutils-2.28.1/bin/ld: /nix/store/pymp4cq49z4whxzjzys4by7dij0axdb0-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/zi17ydzr9x1kqjcpfjr93iwg1frpmv8s-binutils-2.28.1/bin/ld: /nix/store/1h1v44a7qj8pskcw75dcs84gsj4gy3x5-glibc-2.25-49-static/lib/libpthread.a(elision-lock.o): .preinit_array section is not allowed in DSO
/nix/store/zi17ydzr9x1kqjcpfjr93iwg1frpmv8s-binutils-2.28.1/bin/ld: failed to set dynamic section sizes: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
<no location info>: error:
`cc' failed in phase `Linker'. (Exit code: 1)
[ 9 of 15] Compiling Stack.Types ( src/Stack/Types.hs, dist/build/Stack/Types.o )
builder for ‘/nix/store/x7c9rkivww8ypn4bmxsnnngv0fmbs860-stackage2nix-0.5.0.drv’ failed with exit code 1
I had the same issue until I updated my expression with enableSharedLibraries = false; which fixed this. See here for a working derivation that was previously running into the same issue.
Yes, I saw the discussion, but unfortunately, it didn't work out in this case. Maybe I did something wrong though.
I've been trying this and I think the issue is with overrideAttrs which doesn't seem to be doing what I expect. When I try to build these are the contents of configureFlags:
configureFlags: --verbose --prefix=/nix/store/71x8s09dsh0lbv1a48jxpphfmg23hwli-stackage2nix-0.5.0 --libdir=$prefix/lib/$compiler --libsubdir=$pkgid --docdir=/nix/store/1qprzcjlagshv3k8ypj2h75lrh1c7yg4-stackage2nix-0.5.0-doc/share/doc --with-gcc=gcc --package-db=/tmp/nix-build-stackage2nix-0.5.0.drv-0/package.conf.d --ghc-option=-optl=-Wl,-rpath=/nix/store/71x8s09dsh0lbv1a48jxpphfmg23hwli-stackage2nix-0.5.0/lib/ghc-8.2.2/stackage2nix-0.5.0 --ghc-option=-j2 --disable-split-objs --disable-library-profiling --disable-profiling --enable-shared --disable-coverage --enable-library-vanilla --enable-executable-dynamic --enable-tests --ghc-option=-split-sections --ghc-option=-optl=-static --ghc-option=-optl=-L/nix/store/m9ww2brp2wq4yv8zrxmk1x7zmqiz57bp-gmp-6.1.2/lib --ghc-option=-optl=-L/nix/store/4576wq2aj36yhdqck4rfyxg16c1s0r1y-icu4c-58.2-static/lib --ghc-option=-optl=-L/nix/store/87216hp20gpqfjx7gnnc39c53xfbvavs-openssl-1.0.2n-static/lib --ghc-option=-optl=-L/nix/store/hc64qimrlainiqhf61996x2q1c6iziir-zlib-1.2.11-static/lib --ghc-option=-optl=-L/nix/store/1h1v44a7qj8pskcw75dcs84gsj4gy3x5-glibc-2.25-49-static/lib
and the interesting thing is the presence of --enable-shared and --enable-executable-dynamic which seems to indicate that these are not being properly overridden. Can you have a look at your build output and see if you are seeing a similar thing?
I tried with overrideDerivation but that didn't seem to help either.
Thanks again for the fixed overrides. Now it becomes interesting because I can build static columnate, but stackage2nix fails, both built the same configure flags and compilers:
configureFlags: --verbose --prefix=/nix/store/viv1wpa24v2c7dcrjhk889kv24vbbj6w-columnate-0.1.0 --libdir=$prefix/lib/$compiler --libsubdir=$pkgid --docdir=/nix/store/f9ryry7r8zpfy9qf4dcgg1f0fca60iy1-columnate-0.1.0-doc/share/doc --with-gcc=gcc --package-db=/tmp/nix-build-columnate-0.1.0.drv-0/package.conf.d --ghc-option=-j4 --disable-split-objs --disable-library-profiling --disable-profiling --disable-shared --disable-coverage --enable-library-vanilla --disable-executable-dynamic --disable-tests --ghc-option=-split-sections --ghc-option=-optl=-static --ghc-option=-optl=-L/nix/store/j381swc0ikqm7g5anfwfmkh4c8a9l5rd-gmp-6.1.2/lib --ghc-option=-optl=-L/nix/store/742vgi0cn35l13gzq63z5sgzl3aicaad-glibc-2.25-123-static/lib
...
Using gcc version 6.4.0 given by user at:
/nix/store/5l6b97jscljkvsq9y9amg71v5jfzddm4-gcc-wrapper-6.4.0/bin/gcc
Using ghc version 8.2.2 found on system at:
/nix/store/xjgn21ai9mg1ghfb1sb34wgarnpbcrzm-ghc-8.2.2/bin/ghc
configureFlags: --verbose --prefix=/nix/store/mvzy4rypw0bmy5acrxnj4lqxjazhkz01-stackage2nix-0.5.0 --libdir=$prefix/lib/$compiler --libsubdir=$pkgid --docdir=/nix/store/wis2i4wmnv1x6mr1fqv95vagmcw0kj8g-stackage2nix-0.5.0-doc/share/doc --with-gcc=gcc --package-db=/tmp/nix-build-stackage2nix-0.5.0.drv-0/package.conf.d --ghc-option=-j4 --disable-split-objs --disable-library-profiling --disable-profiling --disable-shared --disable-coverage --enable-library-vanilla --disable-executable-dynamic --enable-tests --ghc-option=-split-sections --ghc-option=-optl=-static --ghc-option=-optl=-L/nix/store/742vgi0cn35l13gzq63z5sgzl3aicaad-glibc-2.25-123-static/lib --ghc-option=-optl=-L/nix/store/j381swc0ikqm7g5anfwfmkh4c8a9l5rd-gmp-6.1.2/lib --ghc-option=-optl=-L/nix/store/5k935gchsn77jx9dkphz7j9a6zq6513s-icu4c-58.2-static/lib --ghc-option=-optl=-L/nix/store/0rbjnskrml3schagh8dvmr94x6dyif1a-openssl-1.0.2n-static/lib --ghc-option=-optl=-L/nix/store/dh04g6w6g3jgm5yh4gsbl0pv9h4b55im-zlib-1.2.11-static/lib
...
Using gcc version 6.4.0 given by user at:
/nix/store/5l6b97jscljkvsq9y9amg71v5jfzddm4-gcc-wrapper-6.4.0/bin/gcc
Using ghc version 8.2.2 found on system at:
/nix/store/xjgn21ai9mg1ghfb1sb34wgarnpbcrzm-ghc-8.2.2/bin/ghc
Interestingly, if I comment out configureFlags and set doCheck = false, then the resulting executable seems to be statically linked:
[vaibhavsagar@nixos:~/repos/nixpkgs-stackage]$ git diff
diff --git a/default.nix b/default.nix
index ad558ff..cf39069 100644
--- a/default.nix
+++ b/default.nix
@@ -30,13 +30,14 @@ in {
in self.haskell.lib.overrideCabal stackagePackages.stackage2nix (drv: {
enableSharedExecutables = false;
enableSharedLibraries = false;
+ doCheck = false;
configureFlags = [
- "--ghc-option=-optl=-static"
- "--ghc-option=-optl=-L${self.glibc.static}/lib"
- "--ghc-option=-optl=-L${self.gmp.override { withStatic = true; }}/lib"
- "--ghc-option=-optl=-L${self.icu-static.static}/lib"
- "--ghc-option=-optl=-L${self.openssl-static.static}/lib"
- "--ghc-option=-optl=-L${self.zlib.static}/lib"
+ # "--ghc-option=-optl=-static"
+ # "--ghc-option=-optl=-L${self.glibc.static}/lib"
+ # "--ghc-option=-optl=-L${self.gmp.override { withStatic = true; }}/lib"
+ # "--ghc-option=-optl=-L${self.icu-static.static}/lib"
+ # "--ghc-option=-optl=-L${self.openssl-static.static}/lib"
+ # "--ghc-option=-optl=-L${self.zlib.static}/lib"
];
});
cacheVersion = builtins.readFile ./cache-version.txt;
[vaibhavsagar@nixos:~/repos/nixpkgs-stackage]$ ldd result/bin/stackage2nix
not a dynamic executable
nix-build nixpkgs.nix -A stackage2nix-static produces shell wrapper:
cat result/bin/stackage2nix
#! /nix/store/jgw8hxx7wzkyhb2dr9hwsd9h2caaasdc-bash-4.4-p12/bin/bash -e
export PATH=/nix/store/c7axbcb4f21n7m6kjdkrfzs2z2p28k14-nix-1.11.16/bin${PATH:+:}$PATH
export PATH=/nix/store/bnk2g0kb0qlgwgwpv3w27q8z56066mhk-nix-prefetch-scripts/bin${PATH:+:}$PATH
exec "/nix/store/hks82qha44a85ajyzmpnk29vmq2fvypf-stackage2nix-0.5.0/bin/stackage2nix" --all-cabal-hashes /nix/store/ypvs0w4fbvnmz4ihh2drx3gfs2j9kap8-all-cabal-hashes --lts-haskell /nix/store/ssb36cjzm8yp8fzfwjaydipkkfb0wkvi-stackage-lts --hackage-db /nix/store/ahk3g1f0xabkb1d1wvv49vjmshpzm8yj-hackage-db/01-index.tar "${extraFlagsArray[@]}" "$@"
Compiled binary is still dynamic.
I also thought that it might be the issue with linked libraries (it prints some warnings during linking), but it still fails with libraries commented out:
diff --git a/default.nix b/default.nix
index ad558ff..b662ead 100644
--- a/default.nix
+++ b/default.nix
@@ -30,13 +30,15 @@ in {
in self.haskell.lib.overrideCabal stackagePackages.stackage2nix (drv: {
enableSharedExecutables = false;
enableSharedLibraries = false;
+ doCheck = false;
+ doHaddock = false;
configureFlags = [
"--ghc-option=-optl=-static"
- "--ghc-option=-optl=-L${self.glibc.static}/lib"
- "--ghc-option=-optl=-L${self.gmp.override { withStatic = true; }}/lib"
- "--ghc-option=-optl=-L${self.icu-static.static}/lib"
- "--ghc-option=-optl=-L${self.openssl-static.static}/lib"
- "--ghc-option=-optl=-L${self.zlib.static}/lib"
+ #"--ghc-option=-optl=-L${self.glibc.static}/lib"
+ #"--ghc-option=-optl=-L${self.gmp.override { withStatic = true; }}/lib"
+ #"--ghc-option=-optl=-L${self.icu-static.static}/lib"
+ #"--ghc-option=-optl=-L${self.openssl-static.static}/lib"
+ #"--ghc-option=-optl=-L${self.zlib.static}/lib"
];
});
cacheVersion = builtins.readFile ./cache-version.txt;