pkgs/README.md: minor refactor to patch section to improve readability (#361688)

This commit is contained in:
Aleksana 2024-12-04 16:58:19 +08:00 committed by GitHub
parent 0d5a61037c
commit c3c2032ecb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -492,7 +492,9 @@ Examples going from bad to best practices:
Sometimes, changes are needed to the source to allow building a derivation in nixpkgs, or to get earlier access to an upstream fix or improvement.
When using the `patches` parameter to `mkDerivation`, make sure the patch name clearly describes the reason for the patch, or add a comment.
Patches already merged upstream or published elsewhere should be retrieved using `fetchpatch`.
### Fetching patches
In the interest of keeping our maintenance burden and the size of Nixpkgs to a minimum, patches already merged upstream or published elsewhere _should_ be retrieved using `fetchpatch`:
```nix
{
@ -506,15 +508,22 @@ Patches already merged upstream or published elsewhere should be retrieved using
}
```
Otherwise, you can add a `.patch` file to the `nixpkgs` repository.
In the interest of keeping our maintenance burden and the size of nixpkgs to a minimum, only do this for patches that are unique to `nixpkgs` or that have been proposed upstream but are not merged yet, cannot be easily fetched or have a high chance to disappear in the future due to unstable or unreliable URLs.
The latter avoids link rot when the upstream abandons, squashes or rebases their change, in which case the commit may get garbage-collected.
If a patch is available online but does not cleanly apply, it can be modified in some fixed ways by using additional optional arguments for `fetchpatch`. Check [the `fetchpatch` reference](https://nixos.org/manual/nixpkgs/unstable/#fetchpatch) for details.
### Vendoring patches
In the following cases, a `.patch` file _should_ be added to Nixpkgs repository, instead of retrieved:
- solves problems unique to packaging in Nixpkgs
- is already proposed upstream but not merged yet
- cannot be fetched easily
- has a high chance to disappear in the future due to unstable or unreliable URLs
The latter avoids link rot when the upstream abandons, squashes or rebases their change, in which case the commit may get garbage-collected.
```nix
{
patches = [ ./0001-changes.patch ];
patches = [ ./0001-add-missing-include.patch ];
}
```