#!/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 'Packages:' log "$packages" endgroup configurations=$( jq --raw-output '.nixosConfigurations | select(. != null) | keys[]' <<-EOF $flake_info EOF ) group '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}'