{
  lib,
  pkgs,
  src ? ../.,
}:
let
  daemonToml = builtins.fromTOML (builtins.readFile (src + "/daemon/Cargo.toml"));
in
pkgs.rustPlatform.buildRustPackage rec {
  pname = "gsf-tools";
  version = daemonToml.package.version;

  inherit src;
  cargoLock.lockFile = src + "/Cargo.lock";

  cargoBuildFlags = ["-p" "gsf-cli" "-p" "gsf-daemon"];

  doCheck = false;

  installPhase = ''
    runHook preInstall
    mkdir -p $out/bin

    gsf_bin="$(find target -type f -path '*/release/gsf' | head -n1)"
    gsfd_bin="$(find target -type f -path '*/release/gsfd' | head -n1)"

    if [ -z "$gsf_bin" ] || [ -z "$gsfd_bin" ]; then
      echo "failed to locate built binaries under target/*/release" >&2
      find target -maxdepth 4 -type f | sed -n '1,200p' >&2
      exit 1
    fi

    install -m755 "$gsf_bin" $out/bin/gsf
    install -m755 "$gsfd_bin" $out/bin/gsfd

    runHook postInstall
  '';

  meta = with lib; {
    description = "gotta-scroll-fast tools (gsf + gsfd)";
    license = licenses.gpl2Plus;
    platforms = platforms.linux;
  };
}
