nix-flake-outputs-size/create-report.sh
Jalil David Salamé Messina c3362d4650
fix(action): small typos and weird stuff
Why is it not downloading the previous report?
2024-12-18 16:20:41 +01:00

59 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
set -eu
util_path="${GITHUB_ACTION_PATH-.}/utils.sh"
# shellcheck source=utils.sh
. "${util_path}"
log 'Retrieving Flake information'
flake_info=$(nix flake show --json 2>/dev/null)
packages=$(
jq --raw-output '.packages."x86_64-linux" | select(. != null) | keys[]' <<-EOF
$flake_info
EOF
)
group 'Show Packages'
log "$packages"
endgroup
configurations=$(
jq --raw-output '.nixosConfigurations | select(. != null) | keys[]' <<-EOF
$flake_info
EOF
)
group 'Show NixOS Configurations'
log "$configurations"
endgroup
pkgs_json() {
group 'Building packages'
for package in $packages; do
log "Building $package"
path=$(nix build --print-out-paths ".#$package" 2>/dev/null)
log "Calculating size of $package"
nix path-info --closure-size --json "$path" 2>/dev/null |
jq --compact-output --arg pkg "$package" '.[] | {"name": $pkg, "size": .closureSize, "narSize": .narSize}'
done
endgroup
}
configs_json() {
group 'Building NixOS configurations'
for config in $configurations; do
log "Building $config"
path=$(nix build --print-out-paths ".#nixosConfigurations.$config.config.system.build.toplevel" 2>/dev/null)
log "Calculating size of $config"
nix path-info --closure-size --json "$path" 2>/dev/null |
jq --compact-output --arg pkg "$config" '.[] | {"name": $pkg, "size": .closureSize, "narSize": .narSize}'
done
endgroup
}
pkgs=$(pkgs_json | jq --slurp '.')
configs=$(configs_json | jq --slurp '.')
echo "{}" | jq \
--argjson pkgs "$pkgs" \
--argjson configs "$configs" \
'{"packages": $pkgs, "nixosConfigurations": $configs}'