Commit db78dd37cdcb

Vincent Demeester <vincent@sbr.pm>
2026-01-16 10:08:50
feat: Add nixpkgs maintainer auto-merge tooling
- Streamline maintainer workflow with automated review and merge script - Fix nixpkgs-review --systems flag syntax throughout documentation - Document system selection options for multi-arch testing Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent adf33b3
Changed files (2)
dots
.config
claude
skills
dots/.config/claude/skills/Nixpkgs/scripts/auto-merge-pr
@@ -0,0 +1,81 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+# auto-merge-pr - Automatically review and merge nixpkgs PRs where you're a maintainer
+# Usage: auto-merge-pr <PR_NUMBER>
+
+if [ $# -eq 0 ]; then
+    echo "Usage: auto-merge-pr <PR_NUMBER>"
+    echo ""
+    echo "Automatically reviews and merges nixpkgs PRs where you're a maintainer."
+    echo "This script will:"
+    echo "  1. Check if you're a maintainer of all touched packages"
+    echo "  2. Build the PR with nixpkgs-review"
+    echo "  3. Approve and trigger merge bot if successful"
+    exit 1
+fi
+
+PR_NUMBER="$1"
+
+echo "๐Ÿ” Fetching PR #${PR_NUMBER} details..."
+PR_FILES=$(gh pr view "$PR_NUMBER" --json files --jq '.files[].path')
+
+# Extract package names from pkgs/by-name structure
+PACKAGES=()
+for file in $PR_FILES; do
+    if [[ $file =~ pkgs/by-name/[^/]+/([^/]+)/package.nix ]]; then
+        PACKAGES+=("${BASH_REMATCH[1]}")
+    fi
+done
+
+if [ ${#PACKAGES[@]} -eq 0 ]; then
+    echo "โš ๏ธ  No packages found in pkgs/by-name/ - cannot auto-merge"
+    exit 1
+fi
+
+echo "๐Ÿ“ฆ Found packages: ${PACKAGES[*]}"
+
+# Check if we're a maintainer of all packages
+GITHUB_USER=$(gh api user --jq '.login')
+echo "๐Ÿ‘ค Your GitHub username: $GITHUB_USER"
+
+ALL_MAINTAINER=true
+for pkg in "${PACKAGES[@]}"; do
+    MAINTAINERS=$(nix eval --raw ".#${pkg}.meta.maintainers" 2>/dev/null | grep -o '"github":"[^"]*"' | cut -d'"' -f4 || true)
+
+    if [[ ! $MAINTAINERS =~ $GITHUB_USER ]]; then
+        echo "โŒ You are not a maintainer of $pkg"
+        ALL_MAINTAINER=false
+    else
+        echo "โœ… You are a maintainer of $pkg"
+    fi
+done
+
+if [ "$ALL_MAINTAINER" = false ]; then
+    echo ""
+    echo "โš ๏ธ  You are not a maintainer of all packages in this PR."
+    echo "   Cannot use merge-bot. Manual review required."
+    exit 1
+fi
+
+echo ""
+echo "๐Ÿ—๏ธ  Building PR #${PR_NUMBER}..."
+if nixpkgs-review pr "$PR_NUMBER" --no-shell; then
+    echo ""
+    echo "โœ… Build successful!"
+    echo ""
+    echo "๐Ÿ“ Approving PR and triggering merge bot..."
+
+    # Approve with merge bot comment in one go
+    gh pr review "$PR_NUMBER" --approve --body "Built successfully. All tests passed. LGTM.
+
+@NixOS/nixpkgs-merge-bot merge"
+
+    echo ""
+    echo "โœ… Done! PR approved and merge bot triggered."
+    echo "   Check: https://github.com/NixOS/nixpkgs/pull/${PR_NUMBER}"
+else
+    echo ""
+    echo "โŒ Build failed. Please review manually."
+    exit 1
+fi
dots/.config/claude/skills/Nixpkgs/SKILL.md
@@ -38,7 +38,7 @@ When the user's request matches specific nixpkgs operations, route to the approp
 ### Review PR
 ```bash
 # Review pull request (multi-arch recommended)
-nixpkgs-review pr 12345 --system x86_64-linux,aarch64-linux --no-shell
+nixpkgs-review pr 12345 --systems 'x86_64-linux aarch64-linux' --no-shell
 
 # Review single architecture (quick test)
 nixpkgs-review pr 12345
@@ -50,6 +50,12 @@ nixpkgs-review pr 12345 --post-result
 nixpkgs-review pr 12345 -p firefox
 ```
 
+### Auto-Merge PR (Maintainers)
+```bash
+# Automated review + approve + merge (if you're maintainer of all touched packages)
+~/.config/claude/skills/Nixpkgs/scripts/auto-merge-pr 12345
+```
+
 ### Update Package
 ```bash
 # Update package version
@@ -91,7 +97,7 @@ nix-shell -p nixpkgs-review
 ### Basic PR Review
 ```bash
 # Review PR on multiple architectures (recommended for thorough review)
-nixpkgs-review pr 12345 --system x86_64-linux,aarch64-linux --no-shell
+nixpkgs-review pr 12345 --systems 'x86_64-linux aarch64-linux' --no-shell
 
 # Review PR by number (single arch, interactive)
 nixpkgs-review pr 12345
@@ -141,7 +147,7 @@ nixpkgs-review pr 12345 -p firefox chromium
 nixpkgs-review pr 12345 --package-regex "python.*"
 
 # Review for multiple systems
-nixpkgs-review pr 12345 --system x86_64-linux,aarch64-linux
+nixpkgs-review pr 12345 --systems 'x86_64-linux aarch64-linux'
 
 # Don't enter shell (non-interactive)
 nixpkgs-review pr 12345 --no-shell
@@ -156,6 +162,24 @@ nixpkgs-review pr 12345 --print-result
 nixpkgs-review pr 12345 --sandbox
 ```
 
+### System Selection (--systems flag)
+
+The `--systems` flag allows building for multiple architectures. Use space-separated values in quotes.
+
+```bash
+# Multiple specific platforms (space-separated in quotes)
+nixpkgs-review pr 12345 --systems 'x86_64-linux aarch64-linux'
+
+# Predefined groups
+nixpkgs-review pr 12345 --systems all       # all 4 platforms
+nixpkgs-review pr 12345 --systems linux     # both Linux (x86_64, aarch64)
+nixpkgs-review pr 12345 --systems darwin    # both Darwin (x86_64, aarch64)
+nixpkgs-review pr 12345 --systems x64       # both x86_64 (linux, darwin)
+nixpkgs-review pr 12345 --systems aarch64   # both aarch64 (linux, darwin)
+```
+
+**Valid platforms:** `x86_64-linux`, `aarch64-linux`, `x86_64-darwin`, `aarch64-darwin`
+
 ### Interactive Commands
 ```bash
 # After nixpkgs-review pr drops you in shell:
@@ -198,6 +222,50 @@ gh pr comment 12345 --body "@NixOS/nixpkgs-merge-bot merge"
 
 **Note:** Sometimes GitHub gets stuck after enabling Auto Merge. Leave another approval to trigger the merge.
 
+### Automation Script: auto-merge-pr
+
+For maintainers, an automation script is provided to streamline the review and merge process.
+
+**Location:** `~/.config/claude/skills/Nixpkgs/scripts/auto-merge-pr`
+
+**Usage:**
+```bash
+# From nixpkgs repository
+~/.config/claude/skills/Nixpkgs/scripts/auto-merge-pr <PR_NUMBER>
+
+# Or add to PATH for convenience
+export PATH="$HOME/.config/claude/skills/Nixpkgs/scripts:$PATH"
+auto-merge-pr <PR_NUMBER>
+```
+
+**What it does:**
+1. Fetches PR details and identifies packages in `pkgs/by-name/`
+2. Checks if you're a maintainer of ALL touched packages
+3. Runs `nixpkgs-review pr <PR_NUMBER> --no-shell`
+4. If successful, approves PR and triggers merge bot in one comment
+5. If not maintainer or build fails, exits with error message
+
+**Example:**
+```bash
+cd ~/src/nixpkgs
+auto-merge-pr 480509
+```
+
+**Output:**
+```
+๐Ÿ” Fetching PR #480509 details...
+๐Ÿ“ฆ Found packages: kompose
+๐Ÿ‘ค Your GitHub username: vdemeester
+โœ… You are a maintainer of kompose
+
+๐Ÿ—๏ธ  Building PR #480509...
+[nixpkgs-review build output...]
+
+โœ… Build successful!
+๐Ÿ“ Approving PR and triggering merge bot...
+โœ… Done! PR approved and merge bot triggered.
+```
+
 ### Review Local Changes
 ```bash
 # Review your uncommitted changes
@@ -404,7 +472,7 @@ gh pr create
 ### Review Workflow
 ```bash
 # 1. Review PR on multiple architectures (recommended)
-nixpkgs-review pr 12345 --system x86_64-linux,aarch64-linux --no-shell
+nixpkgs-review pr 12345 --systems 'x86_64-linux aarch64-linux' --no-shell
 
 # OR: Review PR interactively (single arch)
 nixpkgs-review pr 12345
@@ -439,7 +507,7 @@ nix-shell> exit
 #### Version Update PR
 ```bash
 # Review version bump (multi-arch recommended)
-nixpkgs-review pr 12345 --system x86_64-linux,aarch64-linux --no-shell
+nixpkgs-review pr 12345 --systems 'x86_64-linux aarch64-linux' --no-shell
 
 # Check:
 # - Version number correct
@@ -630,7 +698,7 @@ nix-instantiate --parse default.nix
 ## Tips and Tricks
 
 1. **โš ๏ธ ALWAYS run `nixpkgs-review wip` before submitting**: This is the most important step - test your changes locally before pushing
-2. **Test multiple architectures when reviewing**: Use `--system x86_64-linux,aarch64-linux` to catch arch-specific issues
+2. **Test multiple architectures when reviewing**: Use `--systems 'x86_64-linux aarch64-linux'` to catch arch-specific issues
 3. **Use --post-result**: Auto-comment on PRs to help maintainers
 4. **Review regularly**: Help reduce PR backlog
 5. **Test on your system**: Real-world testing is valuable