pkgs/top-level/metrics.nix: just run nix-env -qa once

If we save the output, we can use it later with a little `jq`.
This commit is contained in:
Philip Taron
2025-09-12 13:15:47 -07:00
parent 146c6b9aad
commit dfd90bf4c0

View File

@@ -45,16 +45,11 @@ stdenvNoCC.mkDerivation {
shift shift
echo "running $@" echo "running $@"
local output="$name.out"
local nix_stats="$name-nix-stats.json" local nix_stats="$name-nix-stats.json"
local time_stats="$name-time-stats.json" local time_stats="$name-time-stats.json"
case "$name" in NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH="$nix_stats" time -o "$time_stats" "$@" > "$output"
# Redirect stdout to /dev/null to avoid hitting "Output Limit Exceeded" on Hydra.
nix-env.qaDrv)
NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH="$nix_stats" time -o "$time_stats" "$@" >/dev/null ;;
*)
NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH="$nix_stats" time -o "$time_stats" "$@" ;;
esac
# Show the Nix statistics and the `time` statistics. # Show the Nix statistics and the `time` statistics.
echo "Nix statistics for $@" echo "Nix statistics for $@"
@@ -89,11 +84,11 @@ stdenvNoCC.mkDerivation {
run nix-env.qaDrv nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa --drv-path --meta --json run nix-env.qaDrv nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa --drv-path --meta --json
# It's slightly unclear which of the set to track: qaCount, qaCountDrv, qaCountBroken. # It's slightly unclear which of the set to track: qaCount, qaCountDrv, qaCountBroken.
num="$(nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa | wc -l)" num="$(wc -l < nix-env.qa.out)"
echo "nix-env.qaCount $num" >> $out/nix-support/hydra-metrics echo "nix-env.qaCount $num" >> $out/nix-support/hydra-metrics
qaCountDrv="$(nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa --drv-path | wc -l)" qaCountDrv="$(jq -r 'reduce .[].drvPath as $d (0; .+1)' < nix-env.qaDrv.out)"
num="$((num - $qaCountDrv))" numBroken="$((num - $qaCountDrv))"
echo "nix-env.qaCountBroken $num" >> $out/nix-support/hydra-metrics echo "nix-env.qaCountBroken $numBroken" >> $out/nix-support/hydra-metrics
lines="$(find "$nixpkgs" -name "*.nix" -type f | xargs cat | wc -l)" lines="$(find "$nixpkgs" -name "*.nix" -type f | xargs cat | wc -l)"
echo "loc $lines" >> $out/nix-support/hydra-metrics echo "loc $lines" >> $out/nix-support/hydra-metrics