{ stdenv
, lib
, fetchFromGitHub
, cmake
, ninja
, pkg-config
, fftwFloat
, lksctp-tools
, yaml-cpp
, mbedtls
, gtest
, elfutils
, libbfd
, libdwarf
, boost
, uhd
}:

stdenv.mkDerivation {
  pname = "srsran5g";
  version = "24.04";

  src = fetchFromGitHub {
    owner = "srsran";
    repo = "srsRAN_Project";
    rev = "release_24_04";
    hash = "sha256-ZgOeWpmcqQE7BYgiaVysnRkcJxD4fTCfKSQC5hIGTfk=";
  };

  env.CFLAGS = "-D_SCTP_H";
  env.CXXFLAGS = lib.concatStringsSep " " [
    #"-D_SCTP_H"  # lksctp and glibc do not agree

    # /build/source/tests/unittests/phy/lower/processors/downlink/lower_phy_downlink_processor_test.cpp:796:75: error: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Werror=sign-compare]
    #   796 |               ASSERT_TRUE(md.tx_start.has_value() && (md.tx_start.value() == std::abs(t_offset)));
    #       |                                                       ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
    "-Wno-error=sign-compare"
  ];

  nativeBuildInputs = [
    cmake
    ninja
    pkg-config
  ];

  buildInputs = [
    fftwFloat
    lksctp-tools
    yaml-cpp
    mbedtls
    gtest
    elfutils  # libdw
    libbfd
    libdwarf

    boost  # required by uhd; should really be a propagatedBuildInput...
    uhd
  ];
}