Skip to content

Reduce closure size by removing GCC run-time dependency

The third-largest Nix package on our storage servers currently is a full GCC installation:

[vagrant@storage1:~]$ sudo du -ms /nix/store/* | sort -rn | head -23

194     /nix/store/k9m7557ph3fy9h97px390zwdg8sgpc2j-grafana-loki-2.4.1
190     /nix/store/8zzh0r7fgc7vah6kfxpfv33mv0sgdyc3-nixos-20.09.3218.6bebc91e288
177     /nix/store/cfkfpca5ymx2rf66k6f16sa3lb6ndgc2-gcc-10.3.0
95      /nix/store/v0vm93xrv2hf5wi175wskcgzbicfvbss-python3-3.9.13
93      /nix/store/xhzxyk74z0bwl2w6ywjvwnfdy267m6vx-linux-5.10.126
[...]

Why do we have a compiler on our servers?

[vagrant@storage1:~]$ nix why-depends /run/current-system /nix/store/cfkfpca5ymx2rf66k6f16sa3lb6ndgc2-gcc-10.3.0

[vagrant@storage1:~]$ nix why-depends /run/current-system /nix/store/cfkfpca5ymx2rf66k6f16sa3lb6ndgc2-gcc-10.3.0
/nix/store/5c1p1as3740zlhp36nsaib4yjawmdxjk-nixos-system-storage1-21.11.337975.eabc3821918
╚═══sw -> /nix/store/h9axia0fsa0326mlm6zqwwrzajf682a8-system-path
    => /nix/store/h9axia0fsa0326mlm6zqwwrzajf682a8-system-path
    ╚═══bin/LeaseReport -> /nix/store/xpbgbzmax35ginsdi27przd3brlxmwiy-LeaseReport-exe-LeaseReport-0.1.0.0/bin/LeaseReport
        => /nix/store/xpbgbzmax35ginsdi27przd3brlxmwiy-LeaseReport-exe-LeaseReport-0.1.0.0
        ╚═══bin/LeaseReport: …ncludes/stg.includes./nix/store/cfkfpca5ymx2rf66k6f16sa3lb6ndgc2-gcc-10.3.0/lib/gcc/x86_64-unkno…
            => /nix/store/cfkfpca5ymx2rf66k6f16sa3lb6ndgc2-gcc-10.3.0

Turns out Haskell builds can include GCC as a run-time dependency when one uses the default option of disabling stripping. Seems stripping can, in some cases, lead to trouble, which is why it's disabled by default.

Setting packages.my-package.components.exes.my-exe.dontStrip = false; should rid us of run-time GCC according to these issues I found:

Edited by Florian Sesser