2019-06-15 08:18:06 +03:00
|
|
|
{ stdenv, writeScript, coreutils, gawk, nix
|
|
|
|
, nix-tools
|
2020-01-15 00:34:14 +03:00
|
|
|
, limitMB ? 525
|
2019-06-15 08:18:06 +03:00
|
|
|
}:
|
|
|
|
|
|
|
|
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")
|
2020-08-31 02:08:25 +03:00
|
|
|
|
2019-06-15 08:18:06 +03:00
|
|
|
if [ $total -gt ${toString limitMB} ]; then
|
|
|
|
echo "Closure size exceeds limit of ${toString limitMB}MB!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
''
|