How to patch a more recent kernel

I’ve never build my own kernel.
I need to get command output from a patched kernel.
That’s why trying to build a recent kernel and apply the patch all using nix.

Do you have an idea what I should be doing instead?

The build fails with:

       > checking kernel source version... 6.15.0
       > configure: error:
       >      *** Cannot build against kernel version 6.15.0.
       >         *** The maximum supported kernel version is 6.14.
       >

When I change 15 with 14 I get another error:

error: builder for '/nix/store/ihz5iy08n12n4adj80fn88jyiq0j60aq-linux-config-6.14.0.drv' failed with exit code 255;
       last 25 log lines:
       > GOT: y
       > QUESTION: Microsoft Hyper-V driver testing, NAME: HYPERV_TESTING, ALTS: N/y/?, ANSWER:
       > GOT:
       > GOT: *
       > GOT: * Rust hacking
       > GOT: *
       > QUESTION: Debug assertions, NAME: RUST_DEBUG_ASSERTIONS, ALTS: N/y/?, ANSWER:
       > GOT:
       > QUESTION: Overflow checks, NAME: RUST_OVERFLOW_CHECKS, ALTS: Y/n/?, ANSWER:
       > GOT:
       > QUESTION: Allow unoptimized build-time assertions, NAME: RUST_BUILD_ASSERT_ALLOW, ALTS: N/y/?, ANSWER:
       > GOT:
       > GOT: #
       > GOT: # configuration written to .config
       > GOT: #
       > GOT: make[1]: Leaving directory '/build/source/build'
       > GOT: make: Leaving directory '/build/source'
       > warning: unused option: CRC32_SELFTEST
       > warning: unused option: CRYPTO_TEST
       > warning: unused option: POWER_RESET_GPIO
       > warning: unused option: POWER_RESET_GPIO_RESTART
       > warning: unused option: REISERFS_FS_POSIX_ACL
       > warning: unused option: REISERFS_FS_SECURITY
       > warning: unused option: REISERFS_FS_XATTR
       > error: unused option: SCHED_DEBUG
       For full logs, run:
         nix log /nix/store/ihz5iy08n12n4adj80fn88jyiq0j60aq-linux-config-6.14.0.drv
error: 1 dependencies of derivation '/nix/store/6pldwfq8xihkihz2wixaryvflci736yi-linux-6.14.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/1jflnm0khqsk9rzy2mfmpdl10545qmcy-nixos-minimal-25.11.20250619.08f2208-x86_64-linux.iso.drv' failed to build
      ## nix build .#isopatchedkernel
      packages.x86_64-linux.isopatchedkernel = inputs.nixos-generators.nixosGenerate {
        system = "x86_64-linux";
        format = "install-iso";
        specialArgs = {
          inherit inputs;
        };
        modules = [
          "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
          (
            { pkgs, modulesPath, ... }:
            {
              boot.kernelPackages = pkgs.linuxPackagesFor (
                pkgs.linux_6_15.override {
                  argsOverride = rec {
                    src = pkgs.fetchFromGitHub {
                      owner = "torvalds";
                      repo = "linux";
                      rev = "ada1b0436b5a290923b072b2eb0368a7869bf680";
                      sha256 = "sha256-dssKqIvWe3pSIdooOibnU1laE0/egJhdiFXuMcwzaHs=";
                    };
                    dontStrip = true;
                    version = "6.15.0";
                    modDirVersion = "6.15.0";
                  };
                }
              );
              nixpkgs.config.allowBroken = true;
              boot.kernelPatches = [
                {
                  name = "somepatch";
                  patch = ./somepatch.patch;
                }
              ];

              system.stateVersion = "25.11";
            }
          )
        ];
      };

The root of your issue is that the Linux kernel configuration option CONFIG_SCHED_DEBUG is unused. If you know the impact of not setting it then you can add the line ignoreConfigErrors = true; under the dontStrip = true; line.