Older kernels compilation

Hello, I need to compile a specific kernel version. The configuration I normally use is based on the documentation. I’m able to compile newer kernels without a problem.
The following case make the compilation brake.

boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.linux_5_4.override {
    argsOverride = rec {
      src = pkgs.fetchurl {
        url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz";
        sha256 = "0985fcf6cdcebceca63cb70abab66d12e75fac61014a796ce71272b33f831515";
      };
      version = "5.4.84";
      modDirVersion = "5.4.84";
    };
  });

This is the error I’m getting:
subcmd-util.h:56:23: error: pointer may be used after 'realloc' [-Werror=use-after-free]
If i was doing manually I would set the option on make.
How can I set this option in the declarative way? Or even set an older gcc version, that seems to be more stable to solve this kind of problems.

Updating the above info.
I kept trying to fix this issue and found this git GitHub - nix4noobs/nixosvm-custom-kernel: example showing how to use a custom kernel with a custom .config, which did something similar to what I want to do, but not quite. It uses the manual-config, which I assume it’s this file https://github.com/NixOS/nixpkgs/blob/de47b2e8a5e13afe8581f76bcb59ac5f17b4ac57/pkgs/os-specific/linux/kernel/manual-config.nix.
I modified my kernel configuration to this:

boot.kernelPackages = let
    my-kernel-pkg = { stdenv, lib, linuxKernel , ...} @ args:
      (linuxKernel.manualConfig rec {
        inherit stdenv lib;

        allowImportFromDerivation = true;
        configfile = ./kernel_config;

        extraMakeFlags = [ "KCFLAGS=-Wno-error=use-after-free -Wno-error=deprecated-declarations" ];

        version = "5.4.84";
        modDirVersion = "5.4.84";
        src = pkgs.fetchurl {
          url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz";
          sha256 = "0985fcf6cdcebceca63cb70abab66d12e75fac61014a796ce71272b33f831515";
        };
        kernelPatches = [ ];
      });
    my-kernel = pkgs.callPackage my-kernel-pkg {};
  in
    pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor my-kernel);

I still got the same error, which I found it weird.
Then, I tried to set the stdenv to use a custom gcc version.

boot.kernelPackages = let
    my-kernel-pkg = { stdenv, lib, linuxKernel , ...} @ args:
      (linuxKernel.manualConfig rec {
        inherit lib;
        stdenv = pkgs.gcc10Stdenv;

        allowImportFromDerivation = true;
        configfile = ./kernel_config;
        
        version = "5.4.84";
        modDirVersion = "5.4.84";
        src = pkgs.fetchurl {
          url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz";
          sha256 = "0985fcf6cdcebceca63cb70abab66d12e75fac61014a796ce71272b33f831515";
        };
        kernelPatches = [ ];
      });
    my-kernel = pkgs.callPackage my-kernel-pkg {};
  in
    pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor my-kernel);

This doesn’t fix either.
I’m somewhat new to nix, so I can’t understand how can I fix this.

Note: in both of these configurations I don’t use the kernel patches as before, the configurations were set in the config file.