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.
This commit is contained in:
Rodney Lorrimar 2019-06-15 15:18:06 +10:00 committed by Moritz Angermann
parent 097852792d
commit 2e49d28de0
5 changed files with 42 additions and 3 deletions

View File

@ -11,6 +11,14 @@ steps:
agents:
system: x86_64-linux
- label: 'Check closure size'
command:
- nix-build build.nix -A maintainer-scripts.check-closure-size -o check-closure-size.sh
- echo "+++ Closure size (MB)"
- ./check-closure-size.sh
agents:
system: x86_64-linux
- label: 'Update docs'
command:
- nix-build build.nix -A maintainer-scripts.update-docs -o update-docs.sh

View File

@ -38,5 +38,6 @@ in {
};
};
check-hydra = haskell.callPackage ./scripts/check-hydra.nix {};
check-closure-size = haskell.callPackage ./scripts/check-closure-size.nix {};
};
}

View File

@ -125,7 +125,8 @@ let
# we never want to actually cross compile nix-tools on it's own.
nix-tools = pkgs.buildPackages.callPackage ./nix-tools {
inherit fetchExternal cleanSourceHaskell;
inherit (pkgs.buildPackages.haskellPackages) hpack;
hpack = pkgs.buildPackages.haskell.lib.justStaticExecutables
(pkgs.buildPackages.haskellPackages.hpack);
inherit (self) mkCabalProjectPkgSet;
};

View File

@ -1,5 +1,5 @@
{ lib, symlinkJoin, makeWrapper
, hpack, git, nix, nix-prefetch-scripts
, hpack, git, nix, nix-prefetch-git
, fetchExternal, cleanSourceHaskell, mkCabalProjectPkgSet }:
let
@ -27,7 +27,7 @@ let
hsPkgs = pkgSet.config.hsPkgs;
tools = [ hpack git nix nix-prefetch-scripts ];
tools = [ hpack git nix nix-prefetch-git ];
in
symlinkJoin {
name = "nix-tools";

View File

@ -0,0 +1,29 @@
{ stdenv, writeScript, coreutils, gawk, nix
, nix-tools
, limitMB ? 500
}:
with stdenv.lib;
writeScript "check-closure-size.sh" ''
#!${stdenv.shell}
set -euo pipefail
export PATH="${makeBinPath [ coreutils gawk nix ]}"
get_closure_size() {
du -scm $(nix-store -qR $1) | sort -n | tail -n25
}
nt="$(get_closure_size ${nix-tools})"
echo ' ${nix-tools}'
echo "$nt"
total=$(awk '$2 == "total" { print $1; }' <<< "$nt")
if [ $total -gt ${toString limitMB} ]; then
echo "Closure size exceeds limit of ${toString limitMB}MB!"
exit 1
fi
''