feat: add support for homeConfigurations
All checks were successful
/ check (treefmt) (push) Successful in 3s
/ report-size (push) Successful in 2s
/ report-download-check (push) Successful in 1s

This enables support for `homeConfigurations` (the Home Manager
standalone configurations).
This commit is contained in:
Jalil David Salamé Messina 2025-06-02 18:30:23 +02:00
parent b7e76df813
commit 838f205020
Signed by: jalil
GPG key ID: F016B9E770737A0B
2 changed files with 51 additions and 8 deletions

View file

@ -64,7 +64,7 @@ markdown_from_report() {
<details><summary><b>Tips on reading this data</b></summary>
- 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

View file

@ -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}'