TIL: How to patch Nixpkgs
Today I woke up to a broken cloudflare-dyndns
package on nixpkgs. Fortunately, some good fellow already has a PR to fix the issue. Unfortunately, the PR has not been merged yet and I’m too impatient.
So I did what had to be done. I learned how to patch nixpkgs so that I can build a patched cloudflare-dyndns
. It was actually quiet easy.
First, I downloaded the patch from Github:
curl "https://github.com/NixOS/nixpkgs/pull/198739.patch" \
-Lo packages/nixos-nixpkgs-198739.patch
Then, I changed flake.nix
outputs from:
outputs = inputs@{ nixpkgs, home-manager, ... }:
let
system = "x86_64-darwin";
pkgs = import nixpkgs {
inherit system;
config = { allowUnfree = true; };
};
in {
homeConfigurations.abhinav =
home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [ ./home.nix ];
extraSpecialArgs = { inherit inputs; };
};
};
to:
outputs = inputs@{ nixpkgs, home-manager, ... }:
let
system = "x86_64-darwin";
nixpkgs-patched =
(import nixpkgs { inherit system; }).applyPatches {
name = "nixpkgs-patched";
src = nixpkgs;
patches = [ ./packages/nixos-nixpkgs-198739.patch ];
};
pkgs = import nixpkgs-patched {
inherit system;
config = { allowUnfree = true; };
};
in {
homeConfigurations.abhinav =
home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [ ./home.nix ];
extraSpecialArgs = { inherit inputs; };
};
};
That’s it. It built fine, and I went on to write this note.