with import <nixpkgs> { };
stdenv.mkDerivation {
  name = "car-navigation";
  version = "0";
  src = ./.;

  buildInputs = with qt6Packages; [
    qtbase
    qtdeclarative
    qtpositioning
    qtsvg
    qtimageformats
    (maplibre-native-qt.overrideAttrs (oa: {
      src = fetchFromGitHub {
        inherit (oa.src) owner repo;
        rev = "4b2a1500e0f140bb40e8bf60c5a52669a3ca0649";
        hash = "sha256-DvHadT4intZdn4jSuaYKfTzGJj4Fg6DIEVVO5D5PQCQ=";
        fetchSubmodules = true;
      };
      patches = [
        ./patches/0001-maplibre-setstyle-fix.patch
        ./patches/0002-maplibre-qml-layer-api.patch
        ./patches/0003-maplibre-qml-margins.patch
        ./patches/0004-maplibre-qml-first-symbol-layer.patch
        ./patches/0005-maplibre-qml-tile-cache.patch
        ./patches/0006-maplibre-qml-fix-style-loaded-signal-lost.patch
        ./patches/0007-maplibre-qml-fix-segfault-on-exit.patch
        ./patches/0008-maplibre-core-qml-query-rendered-features.patch
      ];
      cmakeFlags = [
        "-DMLN_WITH_OPENGL=ON"
      ];
      nativeBuildInputs = oa.nativeBuildInputs or [] ++ [ pkg-config ];
    }))
    duckdb
    duckdb.dev
    duckdb.lib
    alsa-utils
    kdePackages.kimageformats
  ];

  nativeBuildInputs = [
    cmake
    qt6Packages.wrapQtAppsHook
  ];
}
