Repository navigation
Description
Describe the bug
There is a patch in nixpkgs NixOS/nixpkgs#59990 "Support patching nixpkgs" which is meant to support users who 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. This is really common flow for linux users in general. What people currently do is 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. IMHO a kinda consuming process if you just want a few patches.
Overall, this patch was a 👎 from @edolstra who commented the following as the most early retort:
I'm -1 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 github:NixOS/nixpkgs?patch=./foo.patch) but I'm convinced it's a good idea.
This idea with flakes piqued my interest as possible, though.
@edolstra did eventually see the usefulness of such a functionality after the following comments NixOS/nixpkgs#59990 (comment) NixOS/nixpkgs#59990 (comment)
I've opened this issue, as I'm not entirely sure how this should look like with flakes, but it is certainly something I'd like to have and would be an instant user of (and judging from the thumbs up on the PR in nixpkgs it would be welcome to many others).
Pinging people from NixOS/nixpkgs#59990
@basvandijk @volth @edolstra
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
worldofpeace commentedon Aug 11, 2020
I seemed to have used the wrong template for a feature request 😬
Ma27 commentedon Aug 12, 2020
@edolstra already suggested to add a
patches-argument tofetchTarball[1]. As this is basically part of the newfetchTree-API, it could look like this with flakes:Not sure (yet) how this can use
fetchpatchthen as this is part ofnixpkgs.[1] NixOS/nixpkgs#59990 (comment)
bqv commentedon Aug 12, 2020
I'm not sure I'm a fan of this idea. It's simple enough to do that patching outside the context of flake setup, not to mention nixpkgs itself supports disabledModules etc. anyway. I think this would overcomplicate the mechanics of flakes
Ma27 commentedon Aug 12, 2020
I'm currently doing this for my personal machines and my infra and I don't really think it is.
Also, when people ask me how I deal with my patches (that aren't on NixOS master/stable) I explain my approach (with those tracking branches) to them and we usually agree pretty fast that this is not really suitable for someone who's new to NixOS or not a poweruser (which I think I am). So we should either add a feature as suggested above or document those approaches pretty well.
Additionally, I'd like to quote @worldofpeace's original comment here:
I don't like this kind of monkey-patching approach (and I think I've heard similar opinions from a few more NixOS users) for the following reasons:
nixpkgs/nixos.master-version of a module, it's IMHO way easier to use the patch rather thandisabledModules. This will eventually lead to even more patching of the module-system since modules can affect each other and you'll probably have to "replace" even more modules.This is not necessarily related to flakes. I suggested to simply pass this argument to the underlying code which uses the
libfetchers-API that is also used forbuiltins.fetchTree/builtins.fetchTarball/etc and it was already suggested to add apatches-functionality to those primops, so this is something that can be implemented on thelibfetchers-level (in Nix's source) and thus also used for flake-inputs.ju1m commentedon Aug 27, 2020
If that may help, here's the workaround I'm currently using to cherry-pick patches against Nixpkgs (not sure at all that everything is correct wrt. using flakes, but at least it's not breaking obviously to me):
If possible, I would prefer to have a more builtin way, like the proposed
patches=attribute toinputs: it would feel less hacky and could maybe avoid to slow down builds by having to loadoriginPkgsto get a NixOS configuration orpkgsindevShell.bqv commentedon Sep 27, 2020
After several frustrating experiences with nixpkgs PRs, I've come around to this idea. I remove my apprehension
worldofpeace commentedon Sep 27, 2020
That's great to hear 👍
bqv commentedon Oct 15, 2020
It seems sensible to me that the patches themselves would also be flake references, to support being urls that can be updated like any other input, rather than having to manually download and keep the files up to date
Edit: nevermind, it seems flake references can't be files... (?)
Allow a "file" libfetcher type for plain files
blaggacao commentedon Jan 7, 2021
While this proposal is not immediately clear to me, I strongly endorse the following:
(for sake of conciseness I opened another issue with my user story)
nixos-discourse commentedon Jan 7, 2021
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/flake-patch-inputs/10854/4
38 remaining items
LiGoldragon commentedon Sep 15, 2023
In the real world, when someone doesnt do his job right, others have to do it for him.
Dessix commentedon Dec 1, 2023
Is there any recommended pattern for doing this with multiple unmerged PRs, until this fix exists? Comparing making a single "everything merged" fork-of-forks versus overlaying multiple nixpkgs repos and overriding, both have significant manual overhead.
ibizaman commentedon Dec 1, 2023
I came across this comment a while ago NixOS/nixpkgs#142273 (comment); if you refine it to just include stuff related to patches, you get the following which I've used in my
flake.nixalready:It's not as nice as it being available at the flake inputs level but the syntax is not too bad. Also, I'm not sure of all the implications of doing this, maybe there are some use cases not supported. But I thought it might be worth mentioning here.
yajo commentedon Dec 11, 2023
That's an IFD AFAIK. Not nice indeed.
nixos-discourse commentedon Apr 6, 2024
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/best-pattern-to-include-multiples-patches-prs-to-nixpgs-in-flake-nix/40917/2
musjj commentedon Nov 11, 2024
Any progress here? I wanted to patch arbitrary inputs, so the
applyPatcheshack isn't an option for me.nazarewk commentedon Nov 12, 2024
I made a workaround for keeping my "fork" up to date using https://github.com/katrinafyi/nix-patcher , added notes on it at my README.md
nixos-discourse commentedon Jan 13, 2025
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/using-overlay-to-bump-android-studio-version/58717/6
jfly commentedon May 23, 2025
I've been using a version of the hardcoded system + IFD approach described in various posts above. I took the time to extract this into a helper library: https://github.com/jfly/flake-input-patcher. Posting it here in case others find this useful!
nixos-discourse commentedon Jun 11, 2025
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/glf-os-cant-figure-out-how-to-remove-some-of-the-included-programs/65426/6
nixos-discourse commentedon Jun 16, 2025
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/including-nixpkgs-prs-for-your-system-has-never-been-easier/65724/1
mightyiam commentedon Jul 2, 2025
I hope this can help some as much as it has been helping me:
https://github.com/mightyiam/input-branches
flake: lock base16-fish input to custom patch
flake: lock base16-fish input to custom patch
PerchunPak commentedon Apr 8, 2026
I have created another solution, a better version of nix-patcher (it also doesn't require IFD). It cherry-picks commits (using GitHub API, no local clone required) instead of using raw patch files that need constant rebasing.
Read more here