From f87776bd7c3cc67de6155ed8c9fd32ebda4bfdb0 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 11:49:53 -0700 Subject: [PATCH 01/16] pkgs/top-level/metrics.nix: use stdenvNoCC.mkDerivation instead of runCommand --- pkgs/top-level/metrics.nix | 43 +++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index c6ff0f349313..5670dda5383c 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -1,25 +1,35 @@ { nixpkgs, pkgs }: -with pkgs; +let + inherit (pkgs) lib stdenvNoCC; +in + +stdenvNoCC.mkDerivation { + name = "nixpkgs-metrics"; + + nativeBuildInputs = map lib.getBin [ + pkgs.nix + pkgs.time + pkgs.jq + ]; + + # see https://github.com/NixOS/nixpkgs/issues/52436 + #requiredSystemFeatures = [ "benchmark" ]; # dedicated `t2a` machine, by @vcunat + + unpackPhase = '' + runHook preUnpack -runCommand "nixpkgs-metrics" - { - nativeBuildInputs = - with pkgs.lib; - map getBin [ - nix - time - jq - ]; - # see https://github.com/NixOS/nixpkgs/issues/52436 - #requiredSystemFeatures = [ "benchmark" ]; # dedicated `t2a` machine, by @vcunat - } - '' export NIX_STORE_DIR=$TMPDIR/store export NIX_STATE_DIR=$TMPDIR/state export NIX_PAGER= nix-store --init + runHook postUnpack + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/nix-support touch $out/nix-support/hydra-build-products @@ -83,4 +93,7 @@ runCommand "nixpkgs-metrics" lines=$(find ${nixpkgs} -name "*.nix" -type f | xargs cat | wc -l) echo "loc $lines" >> $out/nix-support/hydra-metrics - '' + + runHook postInstall + ''; +} From c3f0ef37ebf21bfea5c17a7ef7d53afc39f711bc Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 12:00:32 -0700 Subject: [PATCH 02/16] pkgs/top-level/metrics.nix: add meta explaining this file --- pkgs/top-level/metrics.nix | 81 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index 5670dda5383c..d2a755043aec 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -96,4 +96,85 @@ stdenvNoCC.mkDerivation { runHook postInstall ''; + + meta = { + description = "Metrics tracked by Hydra about Nixpkgs"; + homepage = "https://hydra.nixos.org/job/nixpkgs/trunk/metrics"; + longDescription = '' + View the metrics for Nixpkgs evaluation over time at these URLs. + + These are all produced from running `nix` with `NIX_SHOW_STATS=1`. + See `EvalState::printStatistics` in the Nix source code for the implementation. + None of these metrics are inherently meaningful on their own. + Exercise caution in interpreting them as "bad" or "good". + + # Total repository statistics + + - [Lines of code in Nixpkgs](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/loc) + - [Count of broken packages using `nix-env -qa`](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaCountBroken) + - [Count of packages using `nix-env -qa`](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaCount) + + # Statistics about representative commands + + These are statistics gathered by running commands against Nixpkgs. + + | Name | Command | + |------|---------| + | `nix-env.qaAggressive` | `nix-env -f ${nixpkgs} -qa` | + | `nix-env.qaDrvAggressive` | `nix-env -f ${nixpkgs} -qa --drv-path --meta --xml` | + | `nix-env.qaDrv` | `nix-env -f ${nixpkgs} -qa --drv-path --meta --xml` | + | `nix-env.qa` | `nix-env -f ${nixpkgs} -qa` | + | `nixos.kde` | `nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.kde.x86_64-linux --show-trace` | + | `nixos.lapp` | `nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.lapp.x86_64-linux --show-trace` | + | `nixos.smallContainer` | `nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.smallContainer.x86_64-linux --show-trace`| + + ## Allocations performed (in bytes) + + This counts `envs.bytes`, `list.bytes`, `values.bytes`, and `sets.bytes` from the Nix statistics. + + - [nix-env.qa.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.allocations) + - [nix-env.qaAggressive.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaAggressive.allocations) + - [nix-env.qaDrv.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrv.allocations) + - [nix-env.qaDrvAggressive.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrvAggressive.allocations) + - [nixos.kde.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.kde.allocations) + - [nixos.lapp.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.lapp.allocations) + - [nixos.smallContainer.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.smallContainer.allocations) + + ## Maximum resident size (in number of KiB) + + This counts `maxresident` KiB (`%M`) from the `time` command on Linux. + + - [nix-env.qa.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.maxresident) + - [nix-env.qaAggressive.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaAggressive.maxresident) + - [nix-env.qaDrv.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrv.maxresident) + - [nix-env.qaDrvAggressive.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrvAggressive.maxresident) + - [nixos.kde.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.kde.maxresident) + - [nixos.lapp.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.lapp.maxresident) + - [nixos.smallContainer.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.smallContainer.maxresident) + + ## Time taken (in seconds) + + This counts `cpuTime` as reported in the Nix statistics. On Linux, this resolves to [`getrusage(RUSAGE_SELF)`](https://man7.org/linux/man-pages/man2/getrusage.2.html). + + - [nix-env.qa.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.time) + - [nix-env.qaAggressive.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaAggressive.time) + - [nix-env.qaDrv.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrv.time) + - [nix-env.qaDrvAggressive.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrvAggressive.time) + - [nixos.kde.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.kde.time) + - [nixos.lapp.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.lapp.time) + - [nixos.smallContainer.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.smallContainer.time) + + ## Number of values + + This counts the total number of values allocated in Nix (see `EvalState::allocValue` in the Nix source code). + + - [nix-env.qa.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.values) + - [nix-env.qaAggressive.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaAggressive.values) + - [nix-env.qaDrv.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrv.values) + - [nix-env.qaDrvAggressive.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrvAggressive.values) + - [nixos.kde.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.kde.values) + - [nixos.lapp.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.lapp.values) + - [nixos.smallContainer.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.smallContainer.values) + ''; + }; } From a34bbb6b9cd5f511fb5d5cff7d2ceb12d927cffb Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 12:14:54 -0700 Subject: [PATCH 03/16] pkgs/top-level/metrics.nix: tidy up variables and quoting We also allow the lines to be unbroken. --- pkgs/top-level/metrics.nix | 53 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index d2a755043aec..9b80d3d300e4 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -40,49 +40,48 @@ stdenvNoCC.mkDerivation { echo "running $@" case "$name" in - # Redirect stdout to /dev/null to avoid hitting "Output Limit - # Exceeded" on Hydra. + # Redirect stdout to /dev/null to avoid hitting "Output Limit Exceeded" on Hydra. nix-env.qaDrv|nix-env.qaDrvAggressive) NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats-nix time -o stats-time "$@" >/dev/null ;; *) NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats-nix time -o stats-time "$@" ;; esac - cat stats-nix; echo; cat stats-time; echo + # Show the Nix statistics and the `time` statistics. + cat stats-nix + echo + cat stats-time + echo - x=$(jq '.cpuTime' < stats-nix) - [[ -n $x ]] || exit 1 - echo "$name.time $x s" >> $out/nix-support/hydra-metrics + cpuTime="$(jq '.cpuTime' < stats-nix)" + [[ -n $cpuTime ]] || exit 1 + echo "$name.time $cpuTime s" >> $out/nix-support/hydra-metrics - x=$(sed -e 's/.* \([0-9]\+\)maxresident.*/\1/ ; t ; d' < stats-time) - [[ -n $x ]] || exit 1 - echo "$name.maxresident $x KiB" >> $out/nix-support/hydra-metrics + maxresident="$(sed -e 's/.* \([0-9]\+\)maxresident.*/\1/ ; t ; d' < stats-time)" + [[ -n $maxresident ]] || exit 1 + echo "$name.maxresident $maxresident KiB" >> $out/nix-support/hydra-metrics - # nix-2.2 also outputs .symbols.bytes but that wasn't summed originally - # https://github.com/NixOS/nix/pull/2392/files#diff-8e6ba8c21672fc1a5f6f606e1e101c74L1762 - x=$(jq '[.envs,.list,.values,.sets] | map(.bytes) | add' < stats-nix) - [[ -n $x ]] || exit 1 - echo "$name.allocations $x B" >> $out/nix-support/hydra-metrics + # Nix also outputs `.symbols.bytes` but since that wasn't summed originally, we don't count it here. + allocations="$(jq '[.envs,.list,.values,.sets] | map(.bytes) | add' < stats-nix)" + [[ -n $allocations ]] || exit 1 + echo "$name.allocations $allocations B" >> $out/nix-support/hydra-metrics - x=$(jq '.values.number' < stats-nix) - [[ -n $x ]] || exit 1 - echo "$name.values $x" >> $out/nix-support/hydra-metrics + values="$(jq '.values.number' < stats-nix)" + [[ -n $values ]] || exit 1 + echo "$name.values $values" >> $out/nix-support/hydra-metrics } - run nixos.smallContainer nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix \ - -A closures.smallContainer.x86_64-linux --show-trace - run nixos.kde nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix \ - -A closures.kde.x86_64-linux --show-trace - run nixos.lapp nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix \ - -A closures.lapp.x86_64-linux --show-trace + run nixos.smallContainer nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.smallContainer.x86_64-linux --show-trace + run nixos.kde nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.kde.x86_64-linux --show-trace + run nixos.lapp nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.lapp.x86_64-linux --show-trace run nix-env.qa nix-env -f ${nixpkgs} -qa run nix-env.qaDrv nix-env -f ${nixpkgs} -qa --drv-path --meta --xml # It's slightly unclear which of the set to track: qaCount, qaCountDrv, qaCountBroken. - num=$(nix-env -f ${nixpkgs} -qa | wc -l) + num="$(nix-env -f ${nixpkgs} -qa | wc -l)" echo "nix-env.qaCount $num" >> $out/nix-support/hydra-metrics - qaCountDrv=$(nix-env -f ${nixpkgs} -qa --drv-path | wc -l) - num=$((num - $qaCountDrv)) + qaCountDrv="$(nix-env -f ${nixpkgs} -qa --drv-path | wc -l)" + num="$((num - $qaCountDrv))" echo "nix-env.qaCountBroken $num" >> $out/nix-support/hydra-metrics # TODO: this has been ignored for some time @@ -91,7 +90,7 @@ stdenvNoCC.mkDerivation { run nix-env.qaAggressive nix-env -f ${nixpkgs} -qa run nix-env.qaDrvAggressive nix-env -f ${nixpkgs} -qa --drv-path --meta --xml - 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 runHook postInstall From 29db1d32be1964eefd223a974f733f261f32ec55 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 12:21:52 -0700 Subject: [PATCH 04/16] pkgs/top-level/metrics.nix: use __structuredAttrs --- pkgs/top-level/metrics.nix | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index 9b80d3d300e4..f1eff8e4c9ab 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -7,6 +7,10 @@ in stdenvNoCC.mkDerivation { name = "nixpkgs-metrics"; + # Use structured attrs to pass in relevant information. + __structuredAttrs = true; + inherit nixpkgs; + nativeBuildInputs = map lib.getBin [ pkgs.nix pkgs.time @@ -30,6 +34,8 @@ stdenvNoCC.mkDerivation { installPhase = '' runHook preInstall + release="$nixpkgs/nixos/release.nix" + mkdir -p $out/nix-support touch $out/nix-support/hydra-build-products @@ -71,26 +77,26 @@ stdenvNoCC.mkDerivation { echo "$name.values $values" >> $out/nix-support/hydra-metrics } - run nixos.smallContainer nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.smallContainer.x86_64-linux --show-trace - run nixos.kde nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.kde.x86_64-linux --show-trace - run nixos.lapp nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.lapp.x86_64-linux --show-trace - run nix-env.qa nix-env -f ${nixpkgs} -qa - run nix-env.qaDrv nix-env -f ${nixpkgs} -qa --drv-path --meta --xml + run nixos.smallContainer nix-instantiate --dry-run "$release" -A closures.smallContainer.x86_64-linux --show-trace + run nixos.kde nix-instantiate --dry-run "$release" -A closures.kde.x86_64-linux --show-trace + run nixos.lapp nix-instantiate --dry-run "$release" -A closures.lapp.x86_64-linux --show-trace + run nix-env.qa nix-env -f "$nixpkgs" -qa + run nix-env.qaDrv nix-env -f "$nixpkgs" -qa --drv-path --meta --xml # It's slightly unclear which of the set to track: qaCount, qaCountDrv, qaCountBroken. - num="$(nix-env -f ${nixpkgs} -qa | wc -l)" + num="$(nix-env -f "$nixpkgs" -qa | wc -l)" echo "nix-env.qaCount $num" >> $out/nix-support/hydra-metrics - qaCountDrv="$(nix-env -f ${nixpkgs} -qa --drv-path | wc -l)" + qaCountDrv="$(nix-env -f "$nixpkgs" -qa --drv-path | wc -l)" num="$((num - $qaCountDrv))" echo "nix-env.qaCountBroken $num" >> $out/nix-support/hydra-metrics # TODO: this has been ignored for some time # GC Warning: Bad initial heap size 128k - ignoring it. #export GC_INITIAL_HEAP_SIZE=128k - run nix-env.qaAggressive nix-env -f ${nixpkgs} -qa - run nix-env.qaDrvAggressive nix-env -f ${nixpkgs} -qa --drv-path --meta --xml + run nix-env.qaAggressive nix-env -f "$nixpkgs" -qa + run nix-env.qaDrvAggressive nix-env -f "$nixpkgs" -qa --drv-path --meta --xml - 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 runHook postInstall From b2331161b3aeb84a9a0be008cb1547cb3d34cb56 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 12:28:15 -0700 Subject: [PATCH 05/16] pkgs/top-level/metrics.nix: remove the aggressive variants They've been the same as the non-aggressive variants since Jan 13, 2019 (61b8c03a78caa) --- pkgs/top-level/metrics.nix | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index f1eff8e4c9ab..702dcea29d27 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -47,7 +47,7 @@ stdenvNoCC.mkDerivation { case "$name" in # Redirect stdout to /dev/null to avoid hitting "Output Limit Exceeded" on Hydra. - nix-env.qaDrv|nix-env.qaDrvAggressive) + nix-env.qaDrv) NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats-nix time -o stats-time "$@" >/dev/null ;; *) NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats-nix time -o stats-time "$@" ;; @@ -90,12 +90,6 @@ stdenvNoCC.mkDerivation { num="$((num - $qaCountDrv))" echo "nix-env.qaCountBroken $num" >> $out/nix-support/hydra-metrics - # TODO: this has been ignored for some time - # GC Warning: Bad initial heap size 128k - ignoring it. - #export GC_INITIAL_HEAP_SIZE=128k - run nix-env.qaAggressive nix-env -f "$nixpkgs" -qa - run nix-env.qaDrvAggressive nix-env -f "$nixpkgs" -qa --drv-path --meta --xml - lines="$(find "$nixpkgs" -name "*.nix" -type f | xargs cat | wc -l)" echo "loc $lines" >> $out/nix-support/hydra-metrics @@ -125,8 +119,6 @@ stdenvNoCC.mkDerivation { | Name | Command | |------|---------| - | `nix-env.qaAggressive` | `nix-env -f ${nixpkgs} -qa` | - | `nix-env.qaDrvAggressive` | `nix-env -f ${nixpkgs} -qa --drv-path --meta --xml` | | `nix-env.qaDrv` | `nix-env -f ${nixpkgs} -qa --drv-path --meta --xml` | | `nix-env.qa` | `nix-env -f ${nixpkgs} -qa` | | `nixos.kde` | `nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.kde.x86_64-linux --show-trace` | @@ -138,9 +130,7 @@ stdenvNoCC.mkDerivation { This counts `envs.bytes`, `list.bytes`, `values.bytes`, and `sets.bytes` from the Nix statistics. - [nix-env.qa.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.allocations) - - [nix-env.qaAggressive.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaAggressive.allocations) - [nix-env.qaDrv.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrv.allocations) - - [nix-env.qaDrvAggressive.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrvAggressive.allocations) - [nixos.kde.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.kde.allocations) - [nixos.lapp.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.lapp.allocations) - [nixos.smallContainer.allocations](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.smallContainer.allocations) @@ -150,9 +140,7 @@ stdenvNoCC.mkDerivation { This counts `maxresident` KiB (`%M`) from the `time` command on Linux. - [nix-env.qa.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.maxresident) - - [nix-env.qaAggressive.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaAggressive.maxresident) - [nix-env.qaDrv.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrv.maxresident) - - [nix-env.qaDrvAggressive.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrvAggressive.maxresident) - [nixos.kde.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.kde.maxresident) - [nixos.lapp.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.lapp.maxresident) - [nixos.smallContainer.maxresident](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.smallContainer.maxresident) @@ -162,9 +150,7 @@ stdenvNoCC.mkDerivation { This counts `cpuTime` as reported in the Nix statistics. On Linux, this resolves to [`getrusage(RUSAGE_SELF)`](https://man7.org/linux/man-pages/man2/getrusage.2.html). - [nix-env.qa.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.time) - - [nix-env.qaAggressive.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaAggressive.time) - [nix-env.qaDrv.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrv.time) - - [nix-env.qaDrvAggressive.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrvAggressive.time) - [nixos.kde.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.kde.time) - [nixos.lapp.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.lapp.time) - [nixos.smallContainer.time](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.smallContainer.time) @@ -174,9 +160,7 @@ stdenvNoCC.mkDerivation { This counts the total number of values allocated in Nix (see `EvalState::allocValue` in the Nix source code). - [nix-env.qa.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.values) - - [nix-env.qaAggressive.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaAggressive.values) - [nix-env.qaDrv.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrv.values) - - [nix-env.qaDrvAggressive.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qaDrvAggressive.values) - [nixos.kde.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.kde.values) - [nixos.lapp.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.lapp.values) - [nixos.smallContainer.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.smallContainer.values) From 94f1da567e4717c81fc28195a6eb301e720303b6 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 12:49:26 -0700 Subject: [PATCH 06/16] pkgs/top-level/metrics.nix: convince the time command to output JSON Also, name the JSON files with the .json extension and the name of the run being produced. --- pkgs/top-level/metrics.nix | 43 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index 702dcea29d27..ba5de46f40ad 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -44,35 +44,37 @@ stdenvNoCC.mkDerivation { shift echo "running $@" + local nix_stats="$name-nix-stats.json" + local time_stats="$name-time-stats.json" case "$name" in # Redirect stdout to /dev/null to avoid hitting "Output Limit Exceeded" on Hydra. nix-env.qaDrv) - NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats-nix time -o stats-time "$@" >/dev/null ;; + NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH="$nix_stats" time -o "$time_stats" "$@" >/dev/null ;; *) - NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats-nix time -o stats-time "$@" ;; + NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH="$nix_stats" time -o "$time_stats" "$@" ;; esac # Show the Nix statistics and the `time` statistics. - cat stats-nix + cat "$nix_stats" echo - cat stats-time + cat "$time_stats" echo - cpuTime="$(jq '.cpuTime' < stats-nix)" + cpuTime="$(jq '.cpuTime' < "$nix_stats")" [[ -n $cpuTime ]] || exit 1 echo "$name.time $cpuTime s" >> $out/nix-support/hydra-metrics - maxresident="$(sed -e 's/.* \([0-9]\+\)maxresident.*/\1/ ; t ; d' < stats-time)" + maxresident="$(jq '.max_resident_set_kb' < "$time_stats")" [[ -n $maxresident ]] || exit 1 echo "$name.maxresident $maxresident KiB" >> $out/nix-support/hydra-metrics # Nix also outputs `.symbols.bytes` but since that wasn't summed originally, we don't count it here. - allocations="$(jq '[.envs,.list,.values,.sets] | map(.bytes) | add' < stats-nix)" + allocations="$(jq '[.envs,.list,.values,.sets] | map(.bytes) | add' < "$nix_stats")" [[ -n $allocations ]] || exit 1 echo "$name.allocations $allocations B" >> $out/nix-support/hydra-metrics - values="$(jq '.values.number' < stats-nix)" + values="$(jq '.values.number' < "$nix_stats")" [[ -n $values ]] || exit 1 echo "$name.values $values" >> $out/nix-support/hydra-metrics } @@ -166,4 +168,29 @@ stdenvNoCC.mkDerivation { - [nixos.smallContainer.values](https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nixos.smallContainer.values) ''; }; + + # Convince `time` to output in JSON + env.TIME = builtins.toJSON { + real_time = "%e"; + user_time = "%U"; + sys_time = "%S"; + cpu_percent = "%P"; + max_resident_set_kb = "%M"; + avg_resident_set_kb = "%t"; + avg_total_mem_kb = "%K"; + avg_data_kb = "%D"; + avg_stack_kb = "%p"; + avg_unshared_data_kb = "%X"; + avg_shared_text_kb = "%Z"; + page_faults_major = "%F"; + page_faults_minor = "%R"; + swaps = "%W"; + context_switches_voluntary = "%c"; + context_switches_involuntary = "%w"; + io_reads = "%I"; + io_writes = "%O"; + signals_received = "%k"; + exit_status = "%x"; + command = "%C"; + }; } From b9519e2c0af72fe953c48cfa8e941d558219cfa2 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 13:04:37 -0700 Subject: [PATCH 07/16] pkgs/top-level/metrics.nix: log out the statistics using jq with a header --- pkgs/top-level/metrics.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index ba5de46f40ad..6bd2be765950 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -56,9 +56,11 @@ stdenvNoCC.mkDerivation { esac # Show the Nix statistics and the `time` statistics. - cat "$nix_stats" + echo "Nix statistics for $@" + jq . "$nix_stats" echo - cat "$time_stats" + echo "Time statistics for $@" + jq . "$time_stats" echo cpuTime="$(jq '.cpuTime' < "$nix_stats")" From e35ab56228ac9027e54c3eae9267fab48aaccd95 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 13:13:24 -0700 Subject: [PATCH 08/16] pkgs/top-level/metrics.nix: use the eval-system parameter to target a specific system --- pkgs/top-level/metrics.nix | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index 6bd2be765950..29d66e2c5da8 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -2,6 +2,7 @@ let inherit (pkgs) lib stdenvNoCC; + evalSystem = "x86_64-linux"; in stdenvNoCC.mkDerivation { @@ -9,7 +10,7 @@ stdenvNoCC.mkDerivation { # Use structured attrs to pass in relevant information. __structuredAttrs = true; - inherit nixpkgs; + inherit evalSystem nixpkgs; nativeBuildInputs = map lib.getBin [ pkgs.nix @@ -81,16 +82,16 @@ stdenvNoCC.mkDerivation { echo "$name.values $values" >> $out/nix-support/hydra-metrics } - run nixos.smallContainer nix-instantiate --dry-run "$release" -A closures.smallContainer.x86_64-linux --show-trace - run nixos.kde nix-instantiate --dry-run "$release" -A closures.kde.x86_64-linux --show-trace - run nixos.lapp nix-instantiate --dry-run "$release" -A closures.lapp.x86_64-linux --show-trace - run nix-env.qa nix-env -f "$nixpkgs" -qa - run nix-env.qaDrv nix-env -f "$nixpkgs" -qa --drv-path --meta --xml + run nixos.smallContainer nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.smallContainer.x86_64-linux --show-trace + run nixos.kde nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.kde.x86_64-linux --show-trace + run nixos.lapp nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.lapp.x86_64-linux --show-trace + run nix-env.qa nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa + run nix-env.qaDrv nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa --drv-path --meta --xml # It's slightly unclear which of the set to track: qaCount, qaCountDrv, qaCountBroken. - num="$(nix-env -f "$nixpkgs" -qa | wc -l)" + num="$(nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa | wc -l)" echo "nix-env.qaCount $num" >> $out/nix-support/hydra-metrics - qaCountDrv="$(nix-env -f "$nixpkgs" -qa --drv-path | wc -l)" + qaCountDrv="$(nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa --drv-path | wc -l)" num="$((num - $qaCountDrv))" echo "nix-env.qaCountBroken $num" >> $out/nix-support/hydra-metrics From 146c6b9aadc712723370be6ecee8d28fc8f60331 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 15:48:37 -0700 Subject: [PATCH 09/16] pkgs/top-level/metrics.nix: use json, not XML It's testing the same thing, and it's useful to have the JSON output. --- pkgs/top-level/metrics.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index 29d66e2c5da8..14ed1092e9ee 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -86,7 +86,7 @@ stdenvNoCC.mkDerivation { run nixos.kde nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.kde.x86_64-linux --show-trace run nixos.lapp nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.lapp.x86_64-linux --show-trace run nix-env.qa nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa - run nix-env.qaDrv nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa --drv-path --meta --xml + 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. num="$(nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa | wc -l)" @@ -124,7 +124,7 @@ stdenvNoCC.mkDerivation { | Name | Command | |------|---------| - | `nix-env.qaDrv` | `nix-env -f ${nixpkgs} -qa --drv-path --meta --xml` | + | `nix-env.qaDrv` | `nix-env -f ${nixpkgs} -qa --drv-path --meta --json` | | `nix-env.qa` | `nix-env -f ${nixpkgs} -qa` | | `nixos.kde` | `nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.kde.x86_64-linux --show-trace` | | `nixos.lapp` | `nix-instantiate --dry-run ${nixpkgs}/nixos/release.nix -A closures.lapp.x86_64-linux --show-trace` | From dfd90bf4c07b6eb3d101190c2ad2369c92ea52d5 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 13:15:47 -0700 Subject: [PATCH 10/16] 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`. --- pkgs/top-level/metrics.nix | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index 14ed1092e9ee..fe1ddb0304cb 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -45,16 +45,11 @@ stdenvNoCC.mkDerivation { shift echo "running $@" + local output="$name.out" local nix_stats="$name-nix-stats.json" local time_stats="$name-time-stats.json" - case "$name" in - # 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 + NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH="$nix_stats" time -o "$time_stats" "$@" > "$output" # Show the Nix statistics and the `time` statistics. 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 # 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 - qaCountDrv="$(nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa --drv-path | wc -l)" - num="$((num - $qaCountDrv))" - echo "nix-env.qaCountBroken $num" >> $out/nix-support/hydra-metrics + qaCountDrv="$(jq -r 'reduce .[].drvPath as $d (0; .+1)' < nix-env.qaDrv.out)" + numBroken="$((num - $qaCountDrv))" + echo "nix-env.qaCountBroken $numBroken" >> $out/nix-support/hydra-metrics lines="$(find "$nixpkgs" -name "*.nix" -type f | xargs cat | wc -l)" echo "loc $lines" >> $out/nix-support/hydra-metrics From 251dff3a3e2a057cb7c3f8e46e15e1d95211c012 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 12 Sep 2025 15:25:06 -0700 Subject: [PATCH 11/16] pkgs/top-level/metrics.nix: save the raw files, compressing the output --- pkgs/top-level/metrics.nix | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index fe1ddb0304cb..e8ace0e84806 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -12,6 +12,11 @@ stdenvNoCC.mkDerivation { __structuredAttrs = true; inherit evalSystem nixpkgs; + outputs = [ + "out" + "raw" + ]; + nativeBuildInputs = map lib.getBin [ pkgs.nix pkgs.time @@ -45,11 +50,13 @@ stdenvNoCC.mkDerivation { shift echo "running $@" - local output="$name.out" - local nix_stats="$name-nix-stats.json" - local time_stats="$name-time-stats.json" - NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH="$nix_stats" time -o "$time_stats" "$@" > "$output" + mkdir -p "$raw/$name" + local output="$raw/$name/output" + local nix_stats="$raw/$name/nix-stats.json" + local time_stats="$raw/$name/time-stats.json" + + NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH="$nix_stats" command time -o "$time_stats" -- "$@" > "$output" # Show the Nix statistics and the `time` statistics. echo "Nix statistics for $@" @@ -84,15 +91,18 @@ stdenvNoCC.mkDerivation { 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. - num="$(wc -l < nix-env.qa.out)" + num="$(wc -l < $raw/nix-env.qa/output)" echo "nix-env.qaCount $num" >> $out/nix-support/hydra-metrics - qaCountDrv="$(jq -r 'reduce .[].drvPath as $d (0; .+1)' < nix-env.qaDrv.out)" + qaCountDrv="$(jq -r 'reduce .[].drvPath as $d (0; .+1)' $raw/nix-env.qaDrv/output)" numBroken="$((num - $qaCountDrv))" echo "nix-env.qaCountBroken $numBroken" >> $out/nix-support/hydra-metrics lines="$(find "$nixpkgs" -name "*.nix" -type f | xargs cat | wc -l)" echo "loc $lines" >> $out/nix-support/hydra-metrics + # Compress the raw output + xz -v $raw/*/output + runHook postInstall ''; From 4973d53405faece1e5394cc9616fca610641d117 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Sat, 13 Sep 2025 05:29:34 -0700 Subject: [PATCH 12/16] pkgs/top-level/metrics.nix: use the latest Nix version, just like CI --- pkgs/top-level/metrics.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index e8ace0e84806..26ef31c4a1d8 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -18,7 +18,7 @@ stdenvNoCC.mkDerivation { ]; nativeBuildInputs = map lib.getBin [ - pkgs.nix + pkgs.nixVersions.latest pkgs.time pkgs.jq ]; From 8ac12754cecbfffadeb97178a32584f9342df04b Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Sat, 13 Sep 2025 05:47:22 -0700 Subject: [PATCH 13/16] pkgs/top-level/metrics.nix: turn off aliases in the evaluation This mirrors `ci/eval` and also prevents many warnings from being logged. --- pkgs/top-level/metrics.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index 26ef31c4a1d8..fe9437572e93 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -201,4 +201,11 @@ stdenvNoCC.mkDerivation { exit_status = "%x"; command = "%C"; }; + + # Don't allow aliases anywhere in Nixpkgs for the metrics. + env.NIXPKGS_CONFIG = builtins.toFile "nixpkgs-config.nix" '' + { + allowAliases = false; + } + ''; } From fda7cefcdbd5e50052dfd3bf9b97ae5cc32d8cf9 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Sat, 13 Sep 2025 05:56:26 -0700 Subject: [PATCH 14/16] pkgs/top-level/metrics.nix: pass --no-gc-warning so that no spew about --add-root shows up --- pkgs/top-level/metrics.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index fe9437572e93..8073666f7bd9 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -84,9 +84,9 @@ stdenvNoCC.mkDerivation { echo "$name.values $values" >> $out/nix-support/hydra-metrics } - run nixos.smallContainer nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.smallContainer.x86_64-linux --show-trace - run nixos.kde nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.kde.x86_64-linux --show-trace - run nixos.lapp nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.lapp.x86_64-linux --show-trace + run nixos.smallContainer nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.smallContainer.x86_64-linux --show-trace --no-gc-warning + run nixos.kde nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.kde.x86_64-linux --show-trace --no-gc-warning + run nixos.lapp nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.lapp.x86_64-linux --show-trace --no-gc-warning run nix-env.qa nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa run nix-env.qaDrv nix-env --option eval-system "$evalSystem" -f "$nixpkgs" -qa --drv-path --meta --json From 32c68bb46e8d51f5833830750af8bbb078299949 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 16 Sep 2025 05:43:25 -0700 Subject: [PATCH 15/16] pkgs/top-level/metrics.nix: use the configure, build, and install phases Per CR feedback, this is better than unpack and install with build jammed into install. --- pkgs/top-level/metrics.nix | 55 +++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index 8073666f7bd9..ee36532d5c41 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -26,35 +26,35 @@ stdenvNoCC.mkDerivation { # see https://github.com/NixOS/nixpkgs/issues/52436 #requiredSystemFeatures = [ "benchmark" ]; # dedicated `t2a` machine, by @vcunat - unpackPhase = '' - runHook preUnpack + # Required because this derivation doesn't have a `src`. + dontUnpack = true; + + configurePhase = '' + runHook preConfigure export NIX_STORE_DIR=$TMPDIR/store export NIX_STATE_DIR=$TMPDIR/state export NIX_PAGER= nix-store --init - runHook postUnpack + runHook postConfigure ''; - installPhase = '' - runHook preInstall + buildPhase = '' + runHook preBuild release="$nixpkgs/nixos/release.nix" - mkdir -p $out/nix-support - touch $out/nix-support/hydra-build-products - run() { local name="$1" shift echo "running $@" - mkdir -p "$raw/$name" - local output="$raw/$name/output" - local nix_stats="$raw/$name/nix-stats.json" - local time_stats="$raw/$name/time-stats.json" + mkdir -p "metrics/$name" + local output="metrics/$name/output" + local nix_stats="metrics/$name/nix-stats.json" + local time_stats="metrics/$name/time-stats.json" NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH="$nix_stats" command time -o "$time_stats" -- "$@" > "$output" @@ -68,20 +68,20 @@ stdenvNoCC.mkDerivation { cpuTime="$(jq '.cpuTime' < "$nix_stats")" [[ -n $cpuTime ]] || exit 1 - echo "$name.time $cpuTime s" >> $out/nix-support/hydra-metrics + echo "$name.time $cpuTime s" >> hydra-metrics maxresident="$(jq '.max_resident_set_kb' < "$time_stats")" [[ -n $maxresident ]] || exit 1 - echo "$name.maxresident $maxresident KiB" >> $out/nix-support/hydra-metrics + echo "$name.maxresident $maxresident KiB" >> hydra-metrics # Nix also outputs `.symbols.bytes` but since that wasn't summed originally, we don't count it here. allocations="$(jq '[.envs,.list,.values,.sets] | map(.bytes) | add' < "$nix_stats")" [[ -n $allocations ]] || exit 1 - echo "$name.allocations $allocations B" >> $out/nix-support/hydra-metrics + echo "$name.allocations $allocations B" >> hydra-metrics values="$(jq '.values.number' < "$nix_stats")" [[ -n $values ]] || exit 1 - echo "$name.values $values" >> $out/nix-support/hydra-metrics + echo "$name.values $values" >> hydra-metrics } run nixos.smallContainer nix-instantiate --option eval-system "$evalSystem" --dry-run "$release" -A closures.smallContainer.x86_64-linux --show-trace --no-gc-warning @@ -91,16 +91,27 @@ stdenvNoCC.mkDerivation { 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. - num="$(wc -l < $raw/nix-env.qa/output)" - echo "nix-env.qaCount $num" >> $out/nix-support/hydra-metrics - qaCountDrv="$(jq -r 'reduce .[].drvPath as $d (0; .+1)' $raw/nix-env.qaDrv/output)" + num="$(wc -l < metrics/nix-env.qa/output)" + echo "nix-env.qaCount $num" >> hydra-metrics + qaCountDrv="$(jq -r 'reduce .[].drvPath as $d (0; .+1)' metrics/nix-env.qaDrv/output)" numBroken="$((num - $qaCountDrv))" - echo "nix-env.qaCountBroken $numBroken" >> $out/nix-support/hydra-metrics + echo "nix-env.qaCountBroken $numBroken" >> hydra-metrics lines="$(find "$nixpkgs" -name "*.nix" -type f | xargs cat | wc -l)" - echo "loc $lines" >> $out/nix-support/hydra-metrics + echo "loc $lines" >> hydra-metrics - # Compress the raw output + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/nix-support + touch $out/nix-support/hydra-build-products + mv hydra-metrics $out/nix-support/hydra-metrics + + # Save and compress the raw output + mv metrics $raw xz -v $raw/*/output runHook postInstall From 79feab6cff53917a2fd40be55547faf68ea0eee5 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 16 Sep 2025 05:48:31 -0700 Subject: [PATCH 16/16] pkgs/top-level/metrics.nix: use -print0 to insulate us from spaces in find --- pkgs/top-level/metrics.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/metrics.nix b/pkgs/top-level/metrics.nix index ee36532d5c41..c6380b74a667 100644 --- a/pkgs/top-level/metrics.nix +++ b/pkgs/top-level/metrics.nix @@ -97,7 +97,7 @@ stdenvNoCC.mkDerivation { numBroken="$((num - $qaCountDrv))" echo "nix-env.qaCountBroken $numBroken" >> hydra-metrics - lines="$(find "$nixpkgs" -name "*.nix" -type f | xargs cat | wc -l)" + lines="$(find "$nixpkgs" -name "*.nix" -type f -print0 | xargs -0 cat | wc -l)" echo "loc $lines" >> hydra-metrics runHook postBuild