Commit 35d0313f3fb1

Vincent Demeester <vincent@sbr.pm>
2026-02-26 12:59:40
feat(flake-updater): improve commit message format
Added before/after rev comparison in commit messages and deduplicated inputs sharing the same rev transition.
1 parent 01311f8
Changed files (1)
tools
nix-flake-update
tools/nix-flake-update/nix-flake-update.sh
@@ -155,6 +155,9 @@ log "Working in isolated worktree: $WORKTREE_DIR"
 log "Creating update branch: $BRANCH_NAME"
 git checkout -b "$BRANCH_NAME"
 
+# Save old flake.lock for before/after comparison
+OLD_FLAKE_LOCK=$(cat flake.lock)
+
 # Update flake.lock (work in worktree, flake is at root)
 log "Updating flake.lock"
 if [ -n "$FLAKE_INPUTS" ]; then
@@ -201,14 +204,31 @@ if ! git diff --quiet flake.lock; then
       input_desc="$FLAKE_INPUTS"
     fi
     
+    # Generate before/after changelog, deduplicated by rev transition
+    CHANGES=$(jq -n --argjson old "$OLD_FLAKE_LOCK" --argjson new "$(cat flake.lock)" -r '
+      def rev_map:
+        .nodes | to_entries
+        | map(select(.key != "root" and .value.locked != null))
+        | map({(.key): (.value.locked.rev // .value.locked.narHash // "unknown")})
+        | add // {};
+      ($old | rev_map) as $o |
+      ($new | rev_map) as $n |
+      [$n | to_entries[] | select($o[.key] != null and $o[.key] != .value)] |
+      group_by({old: $o[.key], new: .value}) |
+      map({
+        names: (map(.key) | join(", ")),
+        old: $o[.[0].key][0:12],
+        new: .[0].value[0:12]
+      }) |
+      map("- \(.names): \(.old) → \(.new)") |
+      join("\n")
+    ' 2>/dev/null || echo "Updated flake inputs")
+
     COMMIT_MSG="chore(flake): update $input_desc
 
-$(nix flake metadata . --json 2>/dev/null | \
-  jq -r '.locks.nodes | to_entries[] | select(.key != "root") | "- \(.key): \(.value.locked.rev // .value.locked.narHash // "updated")"' 2>/dev/null || echo "Updated flake inputs")
+$CHANGES
 
-🤖 Automated update
-Built systems: $BUILD_SYSTEMS
-"
+Built systems: $BUILD_SYSTEMS"
 
     git -c user.signingkey=/home/vincent/.ssh/id_ed25519 commit -m "$COMMIT_MSG"