Commit 73a9ff2536a7

Vincent Demeester <vincent@sbr.pm>
2026-01-06 13:56:14
docs(nixpkgs): Update AddPackage workflow with 2025 best practices
- Reduce PR iteration time by documenting current reviewer expectations - Include modern patterns like finalAttrs and nix-update-script - Add tag vs rev guidance to align with upstream standards - Provide references to official nixpkgs documentation Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 038bffa
Changed files (1)
dots
.config
claude
skills
Nixpkgs
workflows
dots/.config/claude/skills/Nixpkgs/workflows/AddPackage.md
@@ -113,6 +113,7 @@ pkgs/
   lib,
   stdenv,
   fetchFromGitHub,
+  nix-update-script,
   # Add build dependencies here
 }:
 
@@ -123,7 +124,7 @@ stdenv.mkDerivation (finalAttrs: {
   src = fetchFromGitHub {
     owner = "owner";
     repo = "repo";
-    rev = "v${finalAttrs.version}";
+    tag = "v${finalAttrs.version}";
     hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
   };
 
@@ -135,9 +136,12 @@ stdenv.mkDerivation (finalAttrs: {
     # Runtime dependencies (libraries)
   ];
 
+  passthru.updateScript = nix-update-script { };
+
   meta = {
     description = "Brief description of what this package does";
     homepage = "https://github.com/owner/repo";
+    changelog = "https://github.com/owner/repo/releases/tag/v${finalAttrs.version}";
     license = lib.licenses.mit;
     maintainers = with lib.maintainers; [ your-github-username ];
     platforms = lib.platforms.linux;
@@ -170,11 +174,56 @@ stdenv.mkDerivation rec {
 
 ### Go Package (buildGoModule)
 
+**Modern pattern with finalAttrs and updateScript** (recommended):
+
 ```nix
 {
   lib,
   buildGoModule,
   fetchFromGitHub,
+  nix-update-script,
+}:
+
+buildGoModule (finalAttrs: {
+  pname = "package-name";
+  version = "1.0.0";
+
+  src = fetchFromGitHub {
+    owner = "owner";
+    repo = "repo";
+    tag = "v${finalAttrs.version}";
+    hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
+  };
+
+  vendorHash = "sha256-BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=";
+
+  ldflags = [
+    "-s"
+    "-w"
+    "-X main.version=${finalAttrs.version}"
+  ];
+
+  passthru.updateScript = nix-update-script { };
+
+  meta = {
+    description = "Description of Go package";
+    homepage = "https://github.com/owner/repo";
+    changelog = "https://github.com/owner/repo/releases/tag/v${finalAttrs.version}";
+    license = lib.licenses.mit;
+    maintainers = with lib.maintainers; [ your-github-username ];
+    mainProgram = "package-name";
+  };
+})
+```
+
+**Traditional rec pattern** (still acceptable but less preferred):
+
+```nix
+{
+  lib,
+  buildGoModule,
+  fetchFromGitHub,
+  nix-update-script,
 }:
 
 buildGoModule rec {
@@ -184,7 +233,7 @@ buildGoModule rec {
   src = fetchFromGitHub {
     owner = "owner";
     repo = "repo";
-    rev = "v${version}";
+    tag = "v${version}";
     hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
   };
 
@@ -196,11 +245,14 @@ buildGoModule rec {
     "-X main.version=${version}"
   ];
 
-  meta = with lib; {
+  passthru.updateScript = nix-update-script { };
+
+  meta = {
     description = "Description of Go package";
     homepage = "https://github.com/owner/repo";
-    license = licenses.mit;
-    maintainers = with maintainers; [ your-github-username ];
+    changelog = "https://github.com/owner/repo/releases/tag/v${version}";
+    license = lib.licenses.mit;
+    maintainers = with lib.maintainers; [ your-github-username ];
     mainProgram = "package-name";
   };
 }
@@ -487,6 +539,10 @@ Before submitting PR:
 - [ ] Ran `nixpkgs-review wip`
 - [ ] Formatted with `nixfmt`
 - [ ] Used `pkgs/by-name` structure (if top-level package)
+- [ ] Used `tag` instead of `rev` in fetchFromGitHub
+- [ ] Added `passthru.updateScript = nix-update-script { };`
+- [ ] Used `finalAttrs` pattern (recommended)
+- [ ] Added `nix-update-script` to function inputs
 - [ ] Correct package name (lowercase, hyphens)
 - [ ] Accurate description
 - [ ] Correct license
@@ -568,7 +624,44 @@ The `with lib.maintainers` is acceptable since it's a simple lookup list.
 
 Expect reviewers to ask for these improvements:
 
-### 1. "Please use pkgs/by-name structure"
+### 1. "Use tag instead of rev in fetchFromGitHub"
+```nix
+# Change from:
+src = fetchFromGitHub {
+  owner = "owner";
+  repo = "repo";
+  rev = "v${version}";
+  hash = "...";
+};
+
+# To:
+src = fetchFromGitHub {
+  owner = "owner";
+  repo = "repo";
+  tag = "v${version}";  # Preferred nowadays
+  hash = "...";
+};
+```
+
+Reference: [fetchFromGitHub docs](https://github.com/NixOS/nixpkgs/blob/master/doc/build-helpers/fetchers.chapter.md#fetchfromgithub-fetchfromgithub)
+
+### 2. "Add passthru.updateScript"
+```nix
+# Add nix-update-script to inputs
+{
+  lib,
+  buildGoModule,
+  fetchFromGitHub,
+  nix-update-script,  # Add this
+}:
+
+# Add to package definition
+passthru.updateScript = nix-update-script { };
+```
+
+Reference: [Automatic package updates](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#automatic-package-updates)
+
+### 3. "Please use pkgs/by-name structure"
 ```nix
 # Move from:
 pkgs/tools/networking/package-name/default.nix
@@ -577,21 +670,21 @@ pkgs/tools/networking/package-name/default.nix
 pkgs/by-name/pa/package-name/package.nix
 ```
 
-### 2. "Add yourself as maintainer"
+### 4. "Add yourself as maintainer"
 ```nix
 meta = {
   maintainers = with lib.maintainers; [ yourhandle ];
 };
 ```
 
-### 3. "Set mainProgram"
+### 5. "Set mainProgram"
 ```nix
 meta = {
   mainProgram = "binary-name";  # The primary executable
 };
 ```
 
-### 4. "Use finalAttrs pattern"
+### 6. "Use finalAttrs pattern"
 ```nix
 # Change from:
 stdenv.mkDerivation rec {
@@ -600,12 +693,14 @@ stdenv.mkDerivation rec {
 stdenv.mkDerivation (finalAttrs: {
 ```
 
-### 5. "Format with nixfmt"
+Reference: [Fixed-point pattern](https://github.com/NixOS/nixpkgs/blob/master/doc/build-helpers/fixed-point-arguments.chapter.md)
+
+### 7. "Format with nixfmt"
 ```bash
 nixfmt pkgs/by-name/pa/package-name/package.nix
 ```
 
-### 6. "Fix commit message format"
+### 8. "Fix commit message format"
 ```bash
 # Should be:
 package-name: init at 1.0.0
@@ -615,7 +710,7 @@ Add package-name
 Added new package package-name
 ```
 
-### 7. "Add package description"
+### 9. "Add package description"
 ```nix
 meta = {
   description = "Brief, clear description of what this does";
@@ -624,7 +719,7 @@ meta = {
 };
 ```
 
-### 8. "Specify correct license"
+### 10. "Specify correct license"
 ```nix
 # Check upstream LICENSE file
 meta = {
@@ -632,13 +727,13 @@ meta = {
 };
 ```
 
-### 9. "Remove unnecessary dependencies"
+### 11. "Remove unnecessary dependencies"
 ```nix
 # Only include dependencies actually used
 # Reviewers may ask: "Is pkg-config actually needed?"
 ```
 
-### 10. "Use nativeBuildInputs for build tools"
+### 12. "Use nativeBuildInputs for build tools"
 ```nix
 # Move build tools from buildInputs
 nativeBuildInputs = [ cmake pkg-config ];