Trouble patching Linux

Hello all,

I’m trying to apply a patch [1] to linux that fixes screen corruption on my XPS 13. After pasting the entire patch email into fix-display.patch, I updated my config to the following:

  boot.kernelPackages = pkgs.linuxPackages_5_3;
  boot.kernelPatches = [
    { name = "fix-display.patch";
      patch = ./fix-display.patch; }

I downloaded a 5.3.18 tarball myself and verified that the patch can be applied with git apply, and yet NixOS outputs the following error:

applying patch /nix/store/ps043r96vap431zdb4nh2daz052xcf85-fix-display.patch
patching file drivers/gpu/drm/i915/display/intel_dp.c
Hunk #1 FAILED at 495.
Hunk #2 succeeded at 1995 with fuzz 1.
Hunk #3 FAILED at 2178.
Hunk #4 FAILED at 2198.
3 out of 4 hunks FAILED -- saving rejects to file drivers/gpu/drm/i915/display/intel_dp.c.rej
patching file drivers/gpu/drm/i915/intel_drv.h
Hunk #1 FAILED at 1115.
1 out of 1 hunk FAILED -- saving rejects to file drivers/gpu/drm/i915/intel_drv.h.rej
builder for '/nix/store/d4ayrfkwrswrf95zs8y29r4dzkgwdgmz-linux-config-5.3.18.drv' failed with exit code 1
cannot build derivation '/nix/store/hpxzy09m7fjay6izfvzhyzk9xz6gnql8-linux-5.3.18.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/7i5hwbla4j0w961jsk1d4m4rqf10yng6-nixos-system-nixos-xps-20.03.git.091ddf2.drv': 1 dependencies couldn't be built
error: build of '/nix/store/7i5hwbla4j0w961jsk1d4m4rqf10yng6-nixos-system-nixos-xps-20.03.git.091ddf2.drv' failed

What did I do wrong?

EDIT: I’ve also tried directly building the kernel from source with the same tarball I tested against, but I got the same error.


Can you try this instead?

  boot.kernelPackages = pkgs.linuxPackages_5_3;
  boot.kernelPatches = [
    (fetchpatch { url = ""; sha256 = "sha256-Fc6V5UwZsU6K3ZhToQdbQdyxCFWd6kOxU6ACZKyaVZo="; })

fetchpatch does some normalization for you that should help.


Just a heads up, fetchpatch needed to be wrapped with {name="abc"; patch = (pkgs.fetchpatch ...);}, but other than that, it worked great!