From 838f2050208b41c339803a1111608d7182bbda3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Mon, 2 Jun 2025 18:30:23 +0200 Subject: [PATCH] feat: add support for homeConfigurations This enables support for `homeConfigurations` (the Home Manager standalone configurations). --- comment_on_pr.sh | 22 +++++++++++++++++++++- create-report.sh | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/comment_on_pr.sh b/comment_on_pr.sh index 3a6d7a0..9122a22 100755 --- a/comment_on_pr.sh +++ b/comment_on_pr.sh @@ -64,7 +64,7 @@ markdown_from_report() {
Tips on reading this data -- For NixOS configurations you generally care only about the `Size` (closure size/size on disk). +- For NixOS/Home-Manager configurations you generally care only about the `Size` (closure size/size on disk). - Reduce the `Size` by disabling unneeded services/default packages. - For Packages you care about both the `Size` and the `NAR Size`. - Reduce the `NAR Size` by reducing the size of the build outputs, e.g. don't copy unnecessary data to the $out dir, optimize binaries for size, etc. @@ -87,6 +87,16 @@ markdown_from_report() { echo "$compare" | json_to_md_rows_and_change "nixosConfigurations" echo fi + if echo "$compare" | has_elements 'homeConfigurations'; then + cat <<-"EOF" + ## Home Manager Configurations + + | Name | Size | Size Change | NAR Size | NAR Size Change | + |------|-----:|------------:|---------:|----------------:| + EOF + echo "$compare" | json_to_md_rows_and_change "homeConfigurations" + echo + fi if echo "$compare" | has_elements 'packages'; then cat <<-"EOF" ## Packages @@ -108,6 +118,16 @@ markdown_from_report() { json_to_md_rows "nixosConfigurations" "$1" echo fi + if has_elements 'homeConfigurations' "$1"; then + cat <<-"EOF" + ## Home Manger Configurations + + | Name | Size | NAR Size | + |------|-----:|---------:| + EOF + json_to_md_rows "homeConfigurations" "$1" + echo + fi if has_elements 'packages' "$1"; then cat <<-"EOF" ## Packages diff --git a/create-report.sh b/create-report.sh index bd478aa..a463eb7 100755 --- a/create-report.sh +++ b/create-report.sh @@ -20,13 +20,22 @@ packages=$( log "$packages" endgroup +group 'Show Home Manager Configurations' +hmConfigs=$( + jq --raw-output '.homeConfigurations | select(. != null) | keys[]' <<-EOF + $flake_info + EOF +) +log "$hmConfigs" +endgroup + group 'Show NixOS Configurations' -configurations=$( +nixosConfigs=$( jq --raw-output '.nixosConfigurations | select(. != null) | keys[]' <<-EOF $flake_info EOF ) -log "$configurations" +log "$nixosConfigs" endgroup pkgs_json() { @@ -42,10 +51,22 @@ pkgs_json() { endgroup } -configs_json() { +hm_configs_json() { + group 'Building Home Manager configurations' + trap endgroup RETURN + for config in $hmConfigs; do + log "Building $config" + path=$(nix build --print-out-paths ".#homeConfigurations.$config.activationPackages") + log "Calculating size of $config" + nix path-info --closure-size --json "$path" | + jq --compact-output --arg pkg "$config" '.[] | {"name": $pkg, "size": .closureSize, "narSize": .narSize}' + done +} + +nixos_configs_json() { group 'Building NixOS configurations' trap endgroup RETURN - for config in $configurations; do + for config in $nixosConfigs; do log "Building $config" path=$(nix build --print-out-paths ".#nixosConfigurations.$config.config.system.build.toplevel") log "Calculating size of $config" @@ -55,9 +76,11 @@ configs_json() { } pkgs=$(pkgs_json | jq --slurp '.') -configs=$(configs_json | jq --slurp '.') +hmConfigs=$(hm_configs_json | jq --slurp '.') +nixosConfigs=$(nixos_configs_json | jq --slurp '.') echo "{}" | jq \ --argjson pkgs "$pkgs" \ - --argjson configs "$configs" \ - '{"packages": $pkgs, "nixosConfigurations": $configs}' + --argjson nixosConfigs "$nixosConfigs" \ + --argjson hmConfigs "$hmConfigs" \ + '{"packages": $pkgs, "nixosConfigurations": $nixosConfigs, "homeConfigurations": $hmConfigs}' -- 2.49.0