{ lib
, rustPlatform
, rustfmt
, stdenv
, pkg-config
, openssl
}:

let
  # Keep the build input stable and small; avoid copying `target/`, `tmp/`, etc. into the Nix store.
  src = lib.cleanSourceWith {
    src = ../../.;
    filter = path: type:
      let
        base = baseNameOf path;
      in
      # Skip typical build outputs and large scratch dirs.
      !(base == "target"
        || base == ".git"
        || base == ".direnv"
        || base == "tmp"
        || base == "node_modules"
        || base == "out"
        || base == "test-results"
        || base == "deploy"
        || base == "intake"
        || base == "cache"
        || base == ".tower-minimal");
  };
in
rustPlatform.buildRustPackage {
  pname = "ec-node";
  version = "0.0.0";
  inherit src;

  cargoLock = {
    lockFile = ../../Cargo.lock;
  };

  cargoBuildFlags = [ "-p" "ec-node" ];

  nativeBuildInputs = [
    pkg-config
    rustfmt
  ];

  buildInputs =
    [
      openssl
    ];

  doCheck = false;

  meta = with lib; {
    description = "every.channel node runner (ingest + chunk + MoQ publish)";
    mainProgram = "ec-node";
    platforms = platforms.unix;
    license = licenses.agpl3Only;
  };
}
