diff --git a/create-report.sh b/create-report.sh index abee680..0452793 100755 --- a/create-report.sh +++ b/create-report.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash set -eu @@ -7,32 +7,36 @@ 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) +group 'Retrieving Flake information' +flake_info=$(nix flake show --json) +endgroup + +group 'Show Packages' packages=$( jq --raw-output '.packages."x86_64-linux" | select(. != null) | keys[]' <<-EOF $flake_info EOF ) -group 'Show Packages' log "$packages" endgroup + +group 'Show NixOS Configurations' configurations=$( jq --raw-output '.nixosConfigurations | select(. != null) | keys[]' <<-EOF $flake_info EOF ) -group 'Show NixOS Configurations' log "$configurations" endgroup pkgs_json() { group 'Building packages' + trap endgroup RETURN for package in $packages; do log "Building $package" - path=$(nix build --print-out-paths ".#$package" 2>/dev/null) + path=$(nix build --print-out-paths ".#$package") log "Calculating size of $package" - nix path-info --closure-size --json "$path" 2>/dev/null | + nix path-info --closure-size --json "$path" | jq --compact-output --arg pkg "$package" '.[] | {"name": $pkg, "size": .closureSize, "narSize": .narSize}' done endgroup @@ -40,14 +44,14 @@ pkgs_json() { configs_json() { group 'Building NixOS configurations' + trap endgroup RETURN for config in $configurations; do log "Building $config" - path=$(nix build --print-out-paths ".#nixosConfigurations.$config.config.system.build.toplevel" 2>/dev/null) + path=$(nix build --print-out-paths ".#nixosConfigurations.$config.config.system.build.toplevel") log "Calculating size of $config" - nix path-info --closure-size --json "$path" 2>/dev/null | + nix path-info --closure-size --json "$path" | jq --compact-output --arg pkg "$config" '.[] | {"name": $pkg, "size": .closureSize, "narSize": .narSize}' done - endgroup } pkgs=$(pkgs_json | jq --slurp '.')