Overriding patchFlags in buildLinux

I am building a custom kernel derivation using Linux kernel - NixOS Wiki example, but as I have a patch which does not apply without passing -N flag, then I need to find a way how to pass it.

Other derivations usually support patchFlags attribute, I think I had a luck with overriding it in the past at least once, but today seems like I’m not lucky and after digging in nixpkgs repository, seems like patchFlags doesn’t even get passed on/inherited by final package derivation.

Based on the example, I’ve tried following things:

{ pkgs, ... }:

  boot.kernelPackages = let
      linux_sgx_pkg = { fetchurl, buildLinux, ... } @ args:

        buildLinux (args // rec {
          version = "5.4.0-rc3";
          modDirVersion = version;

          src = fetchurl {
            url = "https://github.com/jsakkine-intel/linux-sgx/archive/v23.tar.gz";
            sha256 = "11rwlwv7s071ia889dk1dgrxprxiwgi7djhg47vi56dj81jgib20";
          kernelPatches = [
            { name = "mypatch"
            , patch = (fetchurl "https://domain.tld/patch.xz")}
          patchFlags = ["-N"]; # Does not work

          extraConfig = ''
            INTEL_SGX y

          extraMeta.branch = "5.4";
        } // (args.argsOverride or {}));
      linux_sgx = (pkgs.callPackage linux_sgx_pkg {
        patchFlags = ["-N"]; # Does not work here either
      }).overrideAttrs (old: rec {
        patchFlags = ["-N"]; # Nor here, also causes other attributes to vanish?
      pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux_sgx);

Am I missing something?

Hi! While this is not a direct answer to your question, I believe that for SGX, you should be able to use either my patch or the one that has been recently merged upstream.

You are right, this question was not about SGX in particular, but about the patch phase instead.

This question has been open for a good amount of time, I’ve forgot about it completely and unsurprisingly don’t even need answer for this directly anymore.

However, answer is that this is not possible in a comfortable way, and it would break other patches (pkgs/os-specific/linux/kernel/manual-config.nix includes few patches etc.)