{ pkgs, lib, ... }:

with pkgs;

python312Packages.buildPythonApplication rec {
  pname = "flux-local";
  version = "6.0.1";

  src = python312Packages.fetchPypi {
    pname = "flux_local";
    inherit version;
    sha256 = "sha256-rACAgO52U8u6R1Ufr7BGhQCrDEDfGshC9hIxwzEUYMI=";
  };

  # Use the PEP 517 build system
  format = "pyproject";

  # Do not run tests during the build
  doCheck = false;

  # Runtime dependencies
  propagatedBuildInputs = with python312Packages; [
    setuptools
    pyyaml
    aiofiles
    gitpython
    nest-asyncio
    python-slugify
    mashumaro
    pytest
    pytest-asyncio
  ] ++ [
    pkgs.kustomize
    pkgs.kubernetes-helm
    pkgs.fluxcd
    pkgs.git
  ];

  # Include makeWrapper to wrap the executable
  nativeBuildInputs = [ pkgs.makeWrapper ];

  # Wrap the flux-local executable to include necessary tools in PATH
  postInstall = ''
    wrapProgram $out/bin/flux-local \
      --prefix PATH : ${lib.makeBinPath [ pkgs.kustomize pkgs.kubernetes-helm pkgs.flux pkgs.git ]}
  '';

  meta = with lib; {
    homepage = "https://github.com/allenporter/flux-local";
    description = "Perform Flux diffs locally";
    license = licenses.mit;
    maintainers = with maintainers; [ "tommy-skaug" ];
  };
}
