Skip to content

Instantly share code, notes, and snippets.

@573
Last active February 20, 2023 22:19
Show Gist options
  • Save 573/a35ed9fcfdf8e6d2ccc52443ff18fafb to your computer and use it in GitHub Desktop.
Save 573/a35ed9fcfdf8e6d2ccc52443ff18fafb to your computer and use it in GitHub Desktop.
Problem with fetchpatch #nix #patch #nixpkgs

Patches are only applied if the have the right format. In other words a simple git diff to generate them does not work. Using git commit -a (temporary commit i. e. named "changes"), then git format-patch (for that to work you need to have username and email set in git config), followed by git reset --[hard|mixed] <SHA of last not temporary commit> should work. Test using git am < 0001-changes.patch before uploading 0001-changes.patch elsewhere. Now the more probelmatic issue: If you set to patch i. e. nixpkgs using the approach here NixOS/nixpkgs#111651 (comment) you first need to give it a (wrong) sha to provoke getting the right one, i. e. use nix-hash --flat --type sha256 0001-changes.patch and put the output in fetchpatches sha256 field. The build will then output an error saying "got: sha256:". That one you can finally put in the sha256 field and then the build should output i. e. "applying patch /nix/store/8q1lhja5kbmnmynsqxzwf4pqfkpjsssm-nixpkgs-0001-changes.patch (...) patching file".

NOPE

It's just the derivation was built and in nix-store already. So to have the patches (re-)applied you need to delete the according nix-store entries or change the derivation name.

Mic92/nixos-shell#26

let
nixpkgsPatches = [
{
name = "nixpkgs-qemu-5.2.0-desktop.patch";
sha256 = "sha256:0255mav4sc556dzmapmyfz2x3a92ch6hhmyp60vycj47fvs6gf91";
url = "https://gist.githubusercontent.com/573/29b1ad750bd88102177e8dcdfcaf540e/raw/6b65e4a9102f5490388a7f096903b1129d85c6a9/qemu-5.2.0-111651.patch";
}
];
localNixpkgsPatches = [
];
patches = map hostPkgs.fetchpatch nixpkgsPatches ++ localNixpkgsPatches;
hostPkgs = import <nixpkgs> {};
patchedPkgs = hostPkgs.runCommand "nixpkgs-patched-11" { inherit patches; pkgs = hostPkgs.path; } ''
cp -r $pkgs $out
chmod -R +w $out
for p in $patches; do
echo "Applying patch $p";
patch -d $out -N -p1 < "$p";
done
'';
pkgs = import patchedPkgs {};
in
# https://archive.vn/wip/XEeuK (hostPkgs)
with import patchedPkgs {};
stdenv.mkDerivation {
name = "nixos-shell";
src = ./.;
buildInputs = [ bash ];
preConfigure = ''
export PREFIX=$out
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment