{
  stdenv,
  fetchurl,
  autoPatchelfHook,
  makeWrapper,
  zstd,
  dotnetCorePackages,
  postgresql,
  version,
}:
stdenv.mkDerivation {
  pname = "iceshrimp";
  version = version.version;

  src = fetchurl {
    url = "https://iceshrimp.dev/iceshrimp/Iceshrimp.NET/releases/download/v2025.1-beta5.patch2.security1/Iceshrimp.NET-v${version.version}-linux-amd64-glibc.tar.zst";
    hash = version.hash;
  };

  nativeBuildInputs = [
    stdenv.cc.cc.lib
    zstd
    autoPatchelfHook
    makeWrapper
  ];

  buildInputs = [
    dotnetCorePackages.sdk_9_0
    postgresql
  ];

  unpackPhase = ''
    runHook preUnpack

    mkdir -p $out $out/lib $out/etc

    tar xf $src

    cp -r Iceshrimp.NET-${version.version}-linux-amd64-glibc/* $out/lib
    mv $out/lib/configuration.ini $out/etc

    runHook postUnpack
  '';

  postFixup = ''
    makeWrapper $out/lib/Iceshrimp.Backend $out/bin/iceshrimp \
      --set DOTNET_ROOT ${dotnetCorePackages.sdk_9_0}/share/dotnet/ \
      --set ICESHRIMP_CONFIG $out/etc/configuration.ini \
      --set ICESHRIMP_CONFIG_OVERRIDES $out/etc/configuration.overrides.ini
  '';
}
