Patch nixpkgs using cherry-picks without local clone

Nixtamal supports patches generically patching any input with a diff/patch file (local or remote reference supported) while also not requiring flakes or giving proprietary Microsoft GitHub any special privilege tool or syntax (like Someone/nixpkgs@pr-branch).

version "1.0.0"
patches {
	// Unique name for referencing in manifest inputs
	chroma-0.22.0 "https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/478519.patch" {
		// Optionally override the project default hash algorithm for the patch
		hash algorithm=SHA-512 expected="1mdsfx204bgia572fydnmjy78dkybbcnjx20qn9l4q65r29ry28c"
	}
}
// Define inputs
inputs {
	// Unique name for referencing in Nix
	nixpkgs {
		// Fetch an archive with string templating support
		archive {
			url "https://github.com/NixOS/nixpkgs/archive/{{fresh_value}}.tar.gz"
		}
		hash algorithm=SHA-256
		// Apply patches to the source now while awaiting review
		patches chroma-0.22.0
		fresh-cmd {
			$ git ls-remote --branches "https://github.com/NixOS/nixpkgs.git" --refs nixpkgs-unstable
			| cut -f1
		}
	}
}

Which generates a lockfile + shim that allows users to.

let
   inputs = import nix/tamal { };
   pkgs = import inputs.nixpkgs { };
in
pkgs.chroma

Since the patch URL points to a pull request, next time you run nixtamal refresh you can get the new patches as it goes thru review. But just as easily you could point to each commit individually if preferred. Patches are just pkgs.applyPatches under the hood.

4 Likes