# SPDX-FileCopyrightText: 2024 Maurice Debray <maurice.debray@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2

{
  lib,
  python3,
  fetchgit,
  ethtool,
  dmidecode,
  ipmitool,
  lldpd,
  lshw,
}:

python3.pkgs.buildPythonApplication {
  pname = "netbox-agent";
  version = "unstable-2023-03-19";
  pyproject = true;

  src = fetchgit {
    url = "https://git.dgnum.eu/DGNum/netbox-agent";
    rev = "424283239658516feb34c0f68496775350b1bf22";
    hash = "sha256-sp1QVy8AIezR2LRDDYS9G0g0GQRwGKGmEE7ykITPxtY=";
  };

  nativeBuildInputs = with python3.pkgs; [
    setuptools
    wheel
    pythonRelaxDepsHook
  ];

  pythonRelaxDeps = true;

  propagatedBuildInputs = with python3.pkgs; [
    distro
    jsonargparse
    netaddr
    (callPackage ./netifaces2.nix { })
    packaging
    pynetbox
    python-slugify
    pyyaml
  ];

  postInstall = ''
    wrapProgram $out/bin/netbox_agent \
      --prefix PATH ":" ${
        lib.makeBinPath [
          ethtool
          dmidecode
          ipmitool
          lldpd
          lshw
        ]
      }
  '';

  pythonImportsCheck = [ "netbox_agent" ];

  meta = with lib; {
    description = "Netbox agent to run on your infrastructure's servers";
    homepage = "https://git.dgnum.eu/DGNum/netbox-agent";
    license = licenses.asl20;
    maintainers = [ ];
    mainProgram = "netbox_agent";
  };
}