Manually rebuild ncurses6 package from source

I need to manually rebuild ncurses6 library from sources, as I have some issues with the package, present in Nixpkgs repository.

I’m wondering, how to install this library into a system, but instead of regular installation(that is invoked when you put pkgs.ncurses6 into environment.systemPackages), build from source?

Is there a way to do this declaratively?

Got the solution. To rebuild a package with specific compile flags, you can:

environment.systemPackages = with pkgs; {
  (ncurses override { abiVersion = "5"; })

Available compile flags can be found in the Nixpkgs repository, inside pkgs folder