Tired of waiting for PRs to land? Stop waiting!
Utility to patch nix flake inputs.
This can go away when nix supports patching flake inputs: NixOS/nix#3920.
Usage in a flake.nix:
{
inputs = {
flake-input-patcher.url = "github:jfly/flake-input-patcher";
# Feel free to use `follows`. If it points at a patched input, the right
# thing will happen!
systems.follows = "dep1/systems";
# ... More inputs here ...
};
outputs =
unpatchedInputs:
let
# Unfortunately, this utility requires hardcoding a single system. See
# "Known issues" below.
patcher = unpatchedInputs.flake-input-patcher.lib.x86_64-linux;
inputs = patcher.patch {
inherit unpatchedInputs;
flakePath = ./.;
patchSpec = {
# Patching a direct dependency:
nixpkgs.patches = [
(patcher.fetchpatch {
name = "k3s: use patched util-linuxMinimal";
url = "https://github.com/NixOS/nixpkgs/pull/407810.diff";
hash = "sha256-N8tzwSZB9d4Htvimy00+Jcw8TKRCeV8PJWp80x+VtSk=";
})
];
# Patching a transitive dependency:
clan-core.inputs.data-mesher.patches = [
# ... More patches here ...
];
};
};
in
# Define your flake as normal using `inputs`!
}nixdoes not (yet) have a patch builtin, so we use system-specific utilities in nixpkgs (fetchpatchandapplyPatches), which means you have to hardcode a system to make it work.- This depends on Input From Derivation (IFD).
- Support for input following depends on parsing your flake's
flake.lockfile. I'm not sure how brittle this approach is. See branchfollows-without-lockfile-abandonedfor an alternate approach that does not depend on the lockfile. I abandoned this approach before I got it completely working, but I think it is a viable approach, it just is much more work than leveraging the lockfile (which implicitly captures information about howinputsdirectives are resolved across multiple flakes).
- Be more patient and wait for PRs to land. You are trying to upstream your patches, aren't you?
- Tediously hand-write overlays/overrides for changes you need/want. This won't help with NixOS module changes.
- Maintain your own forks of your inputs.
nix-patcheris designed to automate this process. It looks like it only works for inputs hosted on GitHub.
- gepbird/nixpkgs-patcher implements a similar IFD helper. Also see this feature comparison table
Feel free to add a link to your repo here!