Produce fully static executables
CC @nh2 as discussed last week
My first thought was to first package snack itself as a static executable and then potentially provide a way for snack to package other executables as static. It occurred to me that this doesn't make sense since snack packages itself.
My first attempt was to simply provide those GHC options:
"--ghc-option=-optl=-static"
"--ghc-option=-optl=-pthread"
"--ghc-option=-optl=-L${pkgs.gmp6.override { withStatic = true; }}/lib"
"--ghc-option=-optl=-L${pkgs.zlib.static}/lib"
"--ghc-option=-optl=-L${pkgs.glibc.static}/lib"
as described here but you pointed out that this was plain wrong. I don't know if it'd make sense to link statically directly in the linking step or if it should just override the package's ghc options.
See https://github.com/NixOS/nixpkgs/issues/43795 and more concretely, try to build snack statically as described here: https://github.com/nh2/static-haskell-nix/tree/7e41d26eb7403806d6be5f7046efcea3b05442ab#building-arbitrary-packages
Giving a quick shot at it:
Trying:
niklas@ares ~/src/haskell/static-haskell-nix (git)-[stack-1.8-stack2nix] % g rev-parse HEAD
fefbd5e23e3cc702c3bfaae31908dec2eb0b5d12
niklas@ares ~/src/haskell/static-haskell-nix (git)-[stack-1.8-stack2nix] % g d
diff --git a/survey/default.nix b/survey/default.nix
index 753b40d..fccffe9 100644
--- a/survey/default.nix
+++ b/survey/default.nix
@@ -25,6 +25,8 @@ let
});
};
+ snack-overlay = import /home/niklas/src/haskell/snack/nix/overlay.nix;
+
trace = message: value:
if tracing then builtins.trace message value else value;
@@ -39,7 +41,7 @@ in
# config.permittedInsecurePackages = [
# "webkitgtk-2.4.11"
# ];
- overlays = [ (cabal2nix-fix-overlay normalPkgs) ];
+ overlays = [ (cabal2nix-fix-overlay normalPkgs) snack-overlay ];
}).pkgsMusl,
normalHaskellPackages ? pkgs.haskellPackages,
First hitting https://github.com/nmattia/snack/issues/62 and working around it using the diff in there.
Then:
% NIX_PATH=nixpkgs=https://github.com/nh2/nixpkgs/archive/50677e46.tar.gz nix-build survey/default.nix -A pkgs.snack-exe
these derivations will be built:
/nix/store/1xbssx6hs36b2sq9aqfi48mlmnd09knj-Snack.drv
/nix/store/dby4d9f07s5y3x8wd1qx9d0sg7k9557g-linker.drv
building '/nix/store/1xbssx6hs36b2sq9aqfi48mlmnd09knj-Snack.drv'...
unpacking sources
unpacking source archive /nix/store/n63ba0wmfp8g84665qymji4s3fwygwv5-extra-files
source root is extra-files
/nix/store/15kgcm8hnd99p7plqzx7p4lcr2jni4df-set-source-date-epoch-to-latest.sh: line 13: [: : integer expression expected
building
Building module Snack
Local imports are:
Creating dependencies symtree for module Snack
Creating module symlink for module Snack
Compiling module Snack
Snack.hs:15:1: error:
Could not find module ‘Data.Aeson’
Perhaps you meant Data.Version (from base-4.11.1.0)
Use -v to see a list of the files searched for.
|
15 | import Data.Aeson (FromJSON, (.:), (.:?))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Snack.hs:16:1: error:
Could not find module ‘Data.FileEmbed’
Use -v to see a list of the files searched for.
|
16 | import Data.FileEmbed (embedStringFile)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Snack.hs:19:1: error:
Could not find module ‘Data.String.Interpolate’
Use -v to see a list of the files searched for.
|
19 | import Data.String.Interpolate
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Snack.hs:20:1: error:
Could not find module ‘Shelly’
Use -v to see a list of the files searched for.
|
20 | import Shelly (Sh)
| ^^^^^^^^^^^^^^^^^^
Snack.hs:23:1: error:
Could not find module ‘UnliftIO.Exception’
Use -v to see a list of the files searched for.
|
23 | import UnliftIO.Exception
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Snack.hs:24:1: error:
Could not find module ‘Data.Aeson’
Perhaps you meant Data.Version (from base-4.11.1.0)
Use -v to see a list of the files searched for.
|
24 | import qualified Data.Aeson as Aeson
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Snack.hs:25:1: error:
Could not find module ‘Data.Aeson.Types’
Use -v to see a list of the files searched for.
|
25 | import qualified Data.Aeson.Types as Aeson
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Snack.hs:29:1: error:
Could not find module ‘Options.Applicative’
Use -v to see a list of the files searched for.
|
29 | import qualified Options.Applicative as Opts
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Snack.hs:30:1: error:
Could not find module ‘Shelly’
Use -v to see a list of the files searched for.
|
30 | import qualified Shelly as S
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
builder for '/nix/store/1xbssx6hs36b2sq9aqfi48mlmnd09knj-Snack.drv' failed with exit code 1
cannot build derivation '/nix/store/dby4d9f07s5y3x8wd1qx9d0sg7k9557g-linker.drv': 1 dependencies couldn't be built
error: build of '/nix/store/dby4d9f07s5y3x8wd1qx9d0sg7k9557g-linker.drv' failed
strace shows that eventually we get this invocation:
execve("/nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3/bin/ghc", ["/nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3/bin/ghc", "-B/nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3", "-B/nix/store/h8v2kvr2f4plhi3r9srzavp983p17zvg-ghc-8.4.3-with-packages/lib/ghc-8.4.3", "-tmpdir", "tmp/", "Snack.hs", "-c", "-outputdir", "/nix/store/00zvnczvn79ss9jxy0gf0ssizr6jw5s3-Snack", "-Werror", "-Wall"], [/* 71 vars */]) = 0
% ls -lah /nix/store/h8v2kvr2f4plhi3r9srzavp983p17zvg-ghc-8.4.3-with-packages/lib/ghc-8.4.3
total 228K
dr-xr-xr-x 38 niklas niklas 4.0K Jan 1 1970 ./
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 ../
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 array-0.5.2.0/
dr-xr-xr-x 13 niklas niklas 4.0K Jan 1 1970 base-4.11.1.0/
dr-xr-xr-x 2 niklas niklas 4.0K Jan 1 1970 bin/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 binary-0.8.5.1/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 bytestring-0.10.8.2/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 Cabal-2.2.0.1/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 containers-0.5.11.0/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 deepseq-1.4.3.0/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 directory-1.3.1.5/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 filepath-1.4.2/
dr-xr-xr-x 14 niklas niklas 52K Jan 1 1970 ghc-8.4.3/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 ghc-boot-8.4.3/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 ghc-boot-th-8.4.3/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 ghc-compact-0.1.0.0/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 ghci-8.4.3/
lrwxrwxrwx 1 niklas niklas 82 Jan 1 1970 ghci-usage.txt -> /nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3/ghci-usage.txt
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 ghc-prim-0.5.2.0/
lrwxrwxrwx 1 niklas niklas 81 Jan 1 1970 ghc-usage.txt -> /nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3/ghc-usage.txt
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 haskeline-0.7.4.2/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 hpc-0.6.0.3/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 html/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 include/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 integer-gmp-1.0.2.0/
dr-xr-xr-x 2 niklas niklas 4.0K Jan 1 1970 latex/
lrwxrwxrwx 1 niklas niklas 80 Jan 1 1970 llvm-targets -> /nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3/llvm-targets
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 mtl-2.2.2/
dr-xr-xr-x 2 niklas niklas 4.0K Jan 1 1970 package.conf.d/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 parsec-3.1.13.0/
lrwxrwxrwx 1 niklas niklas 85 Jan 1 1970 platformConstants -> /nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3/platformConstants
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 pretty-1.1.3.6/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 process-1.6.3.0/
dr-xr-xr-x 2 niklas niklas 4.0K Jan 1 1970 rts/
lrwxrwxrwx 1 niklas niklas 76 Jan 1 1970 settings -> /nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3/settings
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 stm-2.4.5.0/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 template-haskell-2.13.0.0/
lrwxrwxrwx 1 niklas niklas 82 Jan 1 1970 template-hsc.h -> /nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3/template-hsc.h
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 terminfo-0.4.1.1/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 text-1.2.3.0/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 time-1.8.0.2/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 transformers-0.5.5.0/
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 unix-2.7.2.2/
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 xhtml-3000.2.2.1/
No aeson in there.
In the ghc invocation I see
"-B/nix/store/hfi080vzqqzfip6bd6x4cxc2jgj56xn3-ghc-8.4.3/lib/ghc-8.4.3"
"-B/nix/store/h8v2kvr2f4plhi3r9srzavp983p17zvg-ghc-8.4.3-with-packages/lib/ghc-8.4.3"
But the desired files are in:
ls -lah /nix/store/h8v2kvr2f4plhi3r9srzavp983p17zvg-ghc-8.4.3-with-packages/ghc-8.4.3/
total 220K
dr-xr-xr-x 55 niklas niklas 4.0K Jan 1 1970 .
dr-xr-xr-x 7 niklas niklas 4.0K Jan 1 1970 ..
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 aeson-1.3.1.1
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 ansi-terminal-0.8.0.4
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 ansi-wl-pprint-0.6.8.2
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 async-2.2.1
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 attoparsec-0.13.2.2
dr-xr-xr-x 11 niklas niklas 4.0K Jan 1 1970 base-compat-0.10.4
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 base-orphans-0.7
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 colour-2.3.4
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 constraints-0.10.1
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 cpphs-1.20.8
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 dlist-0.8.0.4
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 enclosed-exceptions-1.0.2
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 exceptions-0.10.0
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 file-embed-0.0.10.1
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 hashable-1.2.7.0
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 haskell-src-exts-1.20.2
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 haskell-src-meta-0.8.0.3
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 integer-logarithms-1.0.2.1
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 interpolate-0.2.0
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 lifted-async-0.10.0.2
dr-xr-xr-x 6 niklas niklas 4.0K Jan 1 1970 lifted-base-0.2.3.12
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 monad-control-1.0.2.3
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 old-locale-1.0.0.7
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 old-time-1.1.0.3
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 optparse-applicative-0.14.2.0
dr-xr-xr-x 2 niklas niklas 4.0K Jan 1 1970 package.conf.d
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 polyparse-1.12
dr-xr-xr-x 5 niklas niklas 4.0K Jan 1 1970 primitive-0.6.3.0
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 random-1.1
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 safe-0.3.17
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 scientific-0.3.6.2
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 semigroups-0.18.5
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 shelly-1.8.1
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 syb-0.7
dr-xr-xr-x 2 niklas niklas 4.0K Jan 1 1970 system-fileio-0.3.16.3
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 system-filepath-0.4.14
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 tagged-0.8.5
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 th-abstraction-0.2.8.0
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 th-expand-syns-0.4.4.0
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 th-lift-0.7.10
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 th-lift-instances-0.1.11
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 th-orphans-0.13.6
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 th-reify-many-0.1.8
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 time-locale-compat-0.1.1.4
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 transformers-base-0.4.5.2
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 transformers-compat-0.6.2
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 unix-compat-0.5.0.1
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 unliftio-0.2.7.0
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 unliftio-core-0.1.1.0
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 unordered-containers-0.2.9.0
dr-xr-xr-x 3 niklas niklas 4.0K Jan 1 1970 uuid-types-1.0.3
dr-xr-xr-x 4 niklas niklas 4.0K Jan 1 1970 vector-0.12.0.1
dr-xr-xr-x 2 niklas niklas 4.0K Jan 1 1970 x86_64-linux-ghc-8.4.3
somehow this dir is not passed as a package DB.