{
  lib,
  rustPlatform,
  fetchFromGitHub,
  pkg-config,
  makeWrapper,
  dbus,
  libpulseaudio,
  gtk4,
  libadwaita,
  glib,
  bluez,
  wayland,
  libxkbcommon,
  libGL,
  vulkan-loader,
  xorg,
  gsettings-desktop-schemas,
}:

rustPlatform.buildRustPackage rec {
  pname = "librepods";
  version = "0.1.0";

  src = fetchFromGitHub {
    owner = "kavishdevar";
    repo = "librepods";
    rev = "4737cbfc2c1a4e227e42d095c49ab43bd8d7b64a";
    hash = "sha256-5vPCtjUiFSI/Ix5dbGmR3TGQsYIwWAUHMwx8yH6HXac=";
  };

  sourceRoot = "${src.name}/linux-rust";

  cargoHash = "sha256-Ebqx+UU2tdygvqvDGjBSxbkmPnkR47/yL3sCVWo54CU=";

  nativeBuildInputs = [
    pkg-config
    makeWrapper
  ];

  buildInputs = [
    dbus
    libpulseaudio
    gtk4
    libadwaita
    glib
    bluez
    wayland
    libxkbcommon
    libGL
    vulkan-loader
    xorg.libX11
    xorg.libXcursor
    xorg.libXrandr
    xorg.libXi
    gsettings-desktop-schemas
  ];

  # Create wrapper script instead of wrapping in-place
  postInstall = ''
    mv $out/bin/librepods $out/bin/.librepods-unwrapped

    makeWrapper $out/bin/.librepods-unwrapped $out/bin/librepods \
      --prefix LD_LIBRARY_PATH : "${
        lib.makeLibraryPath [
          wayland
          libxkbcommon
          libGL
          vulkan-loader
          xorg.libX11
          xorg.libXcursor
          xorg.libXrandr
          xorg.libXi
        ]
      }" \
      --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH" \
      --set GDK_BACKEND "wayland,x11"
  '';

  meta = with lib; {
    description = "Open source alternative for AirPods";
    homepage = "https://github.com/kavishdevar/librepods";
    license = licenses.gpl3;
    maintainers = [ ];
    mainProgram = "librepods";
    platforms = platforms.linux;
  };
}
