#
# Argos standalone MPD client.
#
# vim: et:ts=2:sw=2:
{
  lib,
  pkgs,
  meson,
  fetchFromGitHub,
  pkg-config,
  glib,
  gobject-introspection,
  python3,
  ninja,
  wrapGAppsHook,
  kdePackages,
  ...
}:
let
  pythonWithPackages = python3.withPackages (
    pkgs: with pkgs; [
      pyxdg
      aiohttp
      pygobject3
    ]
  );
in
pkgs.stdenv.mkDerivation rec {
  pname = "argos";
  version = "1.13.0";

  nativeBuildInputs = [
    meson
    ninja
    pkg-config
    wrapGAppsHook
  ];

  buildInputs = [
    glib
    gobject-introspection
    pythonWithPackages
    kdePackages.breeze-icons
  ];

  # The post-install script assumes that package managers are here to
  # package up their e.g. gschemas; and thus won't do it if DESTDIR
  # is set. We just patch out the post-install script and do it ourselves.
  postPatch = ''
    substituteInPlace meson.build \
      --replace-fail \
        "meson.add_install_script('build-aux/meson/postinstall.py')" \
        ""
  '';

  preFixup = ''
    # Compile our gschema...
    ${glib.dev}/bin/glib-compile-schemas $out/share/gsettings-schemas/argos-1.13.0/glib-2.0/schemas

    # ... and add known-good icons, since this will fail if there's any icons missing.
    gappsWrapperArgs+=(
      --prefix XDG_DATA_DIRS : "${kdePackages.breeze-icons}/share"
    )
  '';

  src = fetchFromGitHub {
    owner = "orontee";
    repo = "argos";
    rev = "v${version}";
    hash = "sha256-LzSGTqsqe07FO+gH2aWgFSicubfNopPy+Os3bPWIR2c=";
  };

  meta = {
    description = "Standalone Mopidy client.";
    homepage = "https://github.com/Yepkit/ykush";
    license = lib.licenses.gpl3;
  };
}
