Conversation
|
This pull request has been mentioned on Nix community. There might be relevant details there: |
|
Some design decisions I took:
*
|
|
@basvandijk Nice to see you standardizing this patching idea you presented at NixCon a while back. I've been happily using that method on my job's nixops nixpkgs repo. I think it is great for encouraging upstreaming of contributions, because the patch is in the same format as whatever should eventually be applied to nixpkgs. One issue we ran into is that the default Our workaround is to use |
@ryantm thanks for pointing me to #32084. Fortunately, this implementation lets the user decide how to fetch patches. So users deciding to use |
applyPatches applies a list of patches to a source directory.
3bd4df1 to
2b1bd50
Compare
|
I liked @volth idea of having a separate I also decided to move the patching code to |
2b1bd50 to
20b8e9e
Compare
Sometimes you want to track a specific branch of nixpkgs (like
nixpkgs-unstable or some release branch) but you would like to apply some
unmerged pull requests or some other patches to that revision.
Note that overlays are not always sufficient in this case because they don't
work for NixOS modules and you're forced to duplicate code which already
exists in some commit.
In this case you could fork nixpkgs, create a branch based on your desired
upstream branch and cherry-pick the commits you need on top of that
branch. Then everytime you need to upgrade nixpkgs you rebase your branch on
the latest upstream branch that you're tracking. This process works but is a
bit involved and somewhat untransparent.
nixpkgs also supports a simpler and more transparent mechanism to apply some
patches to an existing revision. First you fetch your desired revision of
nixpkgs like for example:
let
nixpkgs =
builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/86d58407a6bb8ef2e1a58ab50318b149ffd4feda.tar.gz";
sha256 = "0a2lkvacn78nza9hlmdx9znp1my3c3jf3xyhk9ydw6lxa348b7sl";
};
Then you import that revision and apply it to a list of patches, for example:
patchedPkgs = import nixpkgs {
patches = pkgs : [
# NixOS#59950
(pkgs.fetchpatch {
url = https://github.com/NixOS/nixpkgs/commit/1f770d20550a413e508e081ddc08464e9d08ba3d.patch;
sha256 = "1nlzx171y3r3jbk0qhvnl711kmdk57jlq4na8f8bs8wz2pbffymr";
})
];
};
in patchedPkgs...
Note that `patches` should be a function from a nixpkgs set `pkgs` to a list
of patch files that can be applied to a nixpkgs directory tree. The `pkgs` set
should mainly be used to get the `fetchpatch` function from. Note that `pkgs`
is a nixpkgs set for the specified `localSystem` but without `overlays` and
`crossOverlays` defined.
Overlays are applied after patching which means you can have overlays which
can depend on the patched content.
20b8e9e to
ea21757
Compare
| xml:id="chap-patching-nixpkgs"> | ||
| <title>Patching nixpkgs</title> | ||
| <para> | ||
| Sometimes you want to track a specific branch of nixpkgs (like |
There was a problem hiding this comment.
Please avoid the use of you when writing documentation
There was a problem hiding this comment.
Hi Frederik, can I ask why? Do you have a link to more info on this? Is it a nix convention?
I ask because I personally prefer reading this style of documentation, and all style guides I find on Google encourage using the second person.
There was a problem hiding this comment.
Actually I don't think we had a style guide at the time, but it was the common style at the time of writing and the way of writing I was used to from academia.
|
|
||
| unpatchedPkgs = impure unpatchedArgs; | ||
| bootstrapPkgs = impure bootstrapArgs; | ||
| patchedPkgs = import patchedNixpkgsDir unpatchedArgs; |
There was a problem hiding this comment.
This is using IFD, which seems especially dangerous for the entire Nixpkgs. Not necessarily disqualifying, but we should probably have some idea of what that means.
|
I'm 👎 on this. It seems very ad hoc and hacky to make Nixpkgs rewrite its own source tree. That's the job of the version management tool (e.g. Git), which can do a much better job of managing sources and patches. Maybe flakes could provide this functionality (e.g. by having a flake reference like |
|
I would like to be able to declare a base version of nixpkgs and a list of patches. Maybe we need to make a separate community tool that makes it easy to do that. Reasons I like using something like @basvandijk's proposal:
|
|
@ryantm I feel that that tool already exists, namely Git. I typically have a branch like |
|
@edolstra maintaining the I use this at work to keep the nixpkgs we use for NixOps consistent among all my co-workers. You may be right that Git is the tool we need to do this! I'll try to look into it some. |
|
The problem with maintaining such a list of patches is that you have to resolve any conflicts manually, e.g. if you try to update the base Nixpkgs version. Whereas with |
|
I do see the usefulness of that, but I think relying on IFD is a bad idea. It would be better to extend since this does not rely on IFD. |
|
That's not IFD because |
danbst
left a comment
There was a problem hiding this comment.
I find this a temporary solution, but still a useful change. I wish there was also a notion of "reverted" patch.
I agree with @edolstra that nixpkgs source trees should be managed by outer program. Eventually, in future, whenever someone comes to do that...
|
While I understand the need for this feature, as I my-self tried to solved it in the past.
@P-E-Meunier could this be a case where Pijul could help? As a way to add/substract a set of changes on top of a frequently updated repository. |
|
That is indeed the main use case for Pijul. Don't use it for Nixpkgs before the next version, the repository will be huge and slow. However, if all goes as planned, the next version will be competitive with Git on these two things. |
|
I want to do ad hoc patching a lot so I really like the idea here regardless of if it should be used in nixpkgs. I should have found this PR earlier. :) I find it useful to just vary nix expressions during a development/prototyping process instead of futzing imperatively with git. |
|
The solution (tbd): NixOS/nix#4433. |
|
I marked this as stale due to inactivity. → More info |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This is possible now, see this comment for a example #142273 (comment) |
Motivation for this change
Sometimes you want to track a specific branch of nixpkgs (like nixpkgs-unstable or some release branch) but you would like to apply some unmerged pull requests or some other patches to that revision.
Note that overlays are not always sufficient in this case because they don't work for NixOS modules and you're forced to duplicate code which already exists in some commit.
In this case you could fork nixpkgs, create a branch based on your desired upstream branch and cherry-pick the commits you need on top of that branch. Then everytime you need to upgrade nixpkgs you rebase your branch on the latest upstream branch that you're tracking. This process works but is a
bit involved and somewhat untransparent.
This PR implements support in nixpkgs for a simpler and more transparent mechanism to apply some patches to an existing revision. First you fetch your desired revision of nixpkgs like for example:
Then you import that revision and apply it to a list of patches, for example:
Note that
patchesshould be a function from a nixpkgs setpkgsto a list of patch files that can be applied to a nixpkgs directory tree. Thepkgsset should mainly be used to get thefetchpatchfunction from. Note thatpkgsis a nixpkgs set for the specifiedlocalSystembut withoutoverlaysandcrossOverlaysdefined.Overlays are applied after patching which means you can have overlays which can depend on the patched content.
Things done
sandboxinnix.confon non-NixOS)nix-shell -p nix-review --run "nix-review wip"./result/bin/)nix path-info -Sbefore and after)