on iko/ghcjs-patch-master help sign in
Reduce closure size of nix-tools (#178)

* Buildkite: Add a test for nix-tools closure size The limit is a rather generous 500MB. * nix-tools: Reduce closure size 1. Run justStackExecutables on hpack to remove dependency on ghc and libraries. Ideally we would be using the component builder on hpack. 2. Replace nix-prefetch-scripts with nix-prefetch-git. stack.yaml supports mercurial repositories but I've never seen it used.

commit2e49d28de0a1f406d2e7abe0e5e8284d3c349d4a authorRodney Lorrimar <rodney.lorrimar@iohk.io> dateSat 15 Jun 2019, 15:18 (7 years ago) parent0978527
5 files changed+42−3
.buildkite/pipeline.yml+8 build.nix+1 default.nix+2−1 nix-tools/default.nix+2−2 scripts/check-closure-size.nix+29
.buildkite/pipeline.yml+8
@@ -11,6 +11,14 @@ steps:
1111 agents:
1212 system: x86_64-linux
1313
14+ - label: 'Check closure size'
15+ command:
16+ - nix-build build.nix -A maintainer-scripts.check-closure-size -o check-closure-size.sh
17+ - echo "+++ Closure size (MB)"
18+ - ./check-closure-size.sh
19+ agents:
20+ system: x86_64-linux
21+
1422 - label: 'Update docs'
1523 command:
1624 - nix-build build.nix -A maintainer-scripts.update-docs -o update-docs.sh
build.nix+1
@@ -38,5 +38,6 @@ in {
3838 };
3939 };
4040 check-hydra = haskell.callPackage ./scripts/check-hydra.nix {};
41+ check-closure-size = haskell.callPackage ./scripts/check-closure-size.nix {};
4142 };
4243}
default.nix+2−1
@@ -125,7 +125,8 @@ let
125125 # we never want to actually cross compile nix-tools on it's own.
126126 nix-tools = pkgs.buildPackages.callPackage ./nix-tools {
127127 inherit fetchExternal cleanSourceHaskell;
128− inherit (pkgs.buildPackages.haskellPackages) hpack;
128+ hpack = pkgs.buildPackages.haskell.lib.justStaticExecutables
129+ (pkgs.buildPackages.haskellPackages.hpack);
129130 inherit (self) mkCabalProjectPkgSet;
130131 };
131132
nix-tools/default.nix+2−2
@@ -1,5 +1,5 @@
11{ lib, symlinkJoin, makeWrapper
2−, hpack, git, nix, nix-prefetch-scripts
2+, hpack, git, nix, nix-prefetch-git
33, fetchExternal, cleanSourceHaskell, mkCabalProjectPkgSet }:
44
55let
@@ -27,7 +27,7 @@ let
2727
2828 hsPkgs = pkgSet.config.hsPkgs;
2929
30− tools = [ hpack git nix nix-prefetch-scripts ];
30+ tools = [ hpack git nix nix-prefetch-git ];
3131in
3232 symlinkJoin {
3333 name = "nix-tools";
scripts/check-closure-size.nixnew file+29
@@ -0,0 +1,29 @@
1+{ stdenv, writeScript, coreutils, gawk, nix
2+, nix-tools
3+, limitMB ? 500
4+}:
5+
6+with stdenv.lib;
7+
8+writeScript "check-closure-size.sh" ''
9+ #!${stdenv.shell}
10+
11+ set -euo pipefail
12+
13+ export PATH="${makeBinPath [ coreutils gawk nix ]}"
14+
15+ get_closure_size() {
16+ du -scm $(nix-store -qR $1) | sort -n | tail -n25
17+ }
18+
19+ nt="$(get_closure_size ${nix-tools})"
20+ echo ' ${nix-tools}'
21+ echo "$nt"
22+
23+ total=$(awk '$2 == "total" { print $1; }' <<< "$nt")
24+
25+ if [ $total -gt ${toString limitMB} ]; then
26+ echo "Closure size exceeds limit of ${toString limitMB}MB!"
27+ exit 1
28+ fi
29+''