How can I used the compiled kernel in NixOS?

I installed NixOS in my old i5 7th gen laptop. I always like to use the latest kernel by:

kernelPackages = pkgs.linuxPackagesFor (pkgs.linux_latest.override {
      argsOverride = rec {
        src = pkgs.fetchurl {
              url = "mirror://kernel/linux/kernel/v6.x/linux-${version}.tar.xz";
              sha256 = "c34de41baa29c475c0834e88a3171e255ff86cd32d83c6bffc2b797e60bfa671";
        version = "6.7.2";
        modDirVersion = "6.7.2";

This compiles the latest kernel for my laptop, however it takes a long time (about 2 hours). I want to use my powerful windows 11 pc (with wsl2 ubuntu installed) to compile the kernel for my NixOS laptop. How can I modify the configuration.nix in order to use the compiled kernel??

You’d need to do a remote Nix build. I’m wondering as to why you’re overriding the src though? We have the latest kernel packaged in linuxPackages_latest.

I didn’t get 6.7 Kernel from linuxPackages_latest…

How can I setup the remote build? For my wsl2 machine, does it have to install Nix/NixOS as well?

It is 6.7 since linux_6_7: init at 6.7 · NixOS/nixpkgs@549529d · GitHub.

Which revision of Nixpkgs are you on?

You need nix+ssh in there.