A lot of software has to be patched for Nix since it breaks some fundamental assumptions about how software should be deployed.
To do that, people use patches
which are usually the text format of diff files
from git commits.
To generate the patch we can manually clone the repo and create some changes,
commit it into git and generate the patch using git format-patch -1 HEAD
.
This generates a file which we can move into our Nix repo.
We can use it by adding a reference to the file in the patches
attribute of mkDerivation
.
Note the important part :
$src
references the source from GitHub UNPATCHED
. The patch is applied after
and the source is copied to $PWD
when you build. Hence the cp -rf * $out
instead of $src/*
.
{ pkgs, ...}:
pkgs.stdenv.mkDerivation {
name = "papermod";
src = pkgs.fetchFromGitHub {
owner = "adityatelange";
repo = "hugo-PaperMod";
# Current master
rev = "3f50861";
hash = "sha256-NpO7VEXApOpOXznvhbSWWdxBrzn+xn81OGyUGe4/Hzc=";
};
patches = [ ./0001-Fix-span-somehow-broken.patch ];
buildPhase = ''
mkdir $out
cp -rf * $out
'';
}
Cheers!