nh2 / static-haskell-nix

easily build most Haskell programs into fully static Linux executables
388 stars 36 forks source link

Has runtime deps #2

Closed danbst closed 5 years ago

danbst commented 6 years ago

While it should be a static binary, it still contains links to /nix/store derivations:

$ strings /nix/store/0dsc67qhb1s5sa3f0rkmvan5ngqmazs8-blank-me-up-0.1.0.0-x86_64-unknown-linux-musl/bin/blank-me-up | grep /nix/store
/nix/store/n3akrix0bc6lyvvsy183ygzhr72j75xx-warp-3.2.18.1-x86_64-unknown-linux-musl/bin
/nix/store/n3akrix0bc6lyvvsy183ygzhr72j75xx-warp-3.2.18.1-x86_64-unknown-linux-musl/lib/ghc-8.4.1/warp-3.2.18.1
/nix/store/n3akrix0bc6lyvvsy183ygzhr72j75xx-warp-3.2.18.1-x86_64-unknown-linux-musl/lib/ghc-8.4.1/x86_64-linux-ghc-8.4.1
/nix/store/n3akrix0bc6lyvvsy183ygzhr72j75xx-warp-3.2.18.1-x86_64-unknown-linux-musl/share/x86_64-linux-ghc-8.4.1/warp-3.2.18.1
/nix/store/n3akrix0bc6lyvvsy183ygzhr72j75xx-warp-3.2.18.1-x86_64-unknown-linux-musl/libexec/x86_64-linux-ghc-8.4.1/warp-3.2.18.1
/nix/store/n3akrix0bc6lyvvsy183ygzhr72j75xx-warp-3.2.18.1-x86_64-unknown-linux-musl/etc
/nix/store/4rcafzmp5w40mpcabwmrin1nqn207vmf-libiconv-1.15-x86_64-unknown-linux-musl/lib

The resulting closure is quite large and includes gcc and all Haskell libs. Total runtime closure size is 1.9 Gb!

nmattia commented 6 years ago

I've seen something like this before, which was due to a module using cabal's Paths_ (which contains links to the library). You should be able to check this with nix why-depends <your derivation> <path-of-warp>, for instance.

EDIT: Forgot to mention the fix: run remove-references-to -t ${the-warp-you-are-using} <your-exe> from makeWrapper. But first make sure those references really are spurious.

nh2 commented 5 years ago

This is solved for most packages now.

E.g. on commit 3ae445d7fd1f84e61617fc16e83d7fbd005cc438:

% nix-store -qR $(NIX_PATH=nixpkgs=nixpkgs nix-build default.nix)
/nix/store/702n4ffyszdm7vh154w5nk9h8axm1cl4-example-scotty-app-0.1.0.0

Some packages like pandoc still have that problem (2 GB closure), likely because they actually use Paths_ and data files and so on as @nmattia said.

But for the original problem of this happening for all packages, that should be solved.

Thus I'll close this general issue; let's file individual issues for packages where we want to fix this.

nh2 commented 5 years ago

Found here: https://github.com/jgm/pandoc/blob/c3236560c234aaefe9239ba2e391f540f1d6408a/INSTALL.md#linux

This provides both pandoc and pandoc-citeproc. The executables are statically linked and have no dynamic dependencies or dependencies on external data files. Note: because of the static linking, the pandoc binary from this package cannot use lua filters that require external lua modules written in C.

That seems to give some hints.