From 68d8d204b5f64fdbe1521dbb3604369fa965d88d Mon Sep 17 00:00:00 2001
From: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Date: Tue, 30 Jul 2024 12:03:50 +0200
Subject: [PATCH] python312Packages.greatfet: add missing dependencies

---
 .../python-modules/greatfet/default.nix       | 51 ++++++++++++++-----
 1 file changed, 37 insertions(+), 14 deletions(-)

diff --git a/pkgs/development/python-modules/greatfet/default.nix b/pkgs/development/python-modules/greatfet/default.nix
index 147cd19164e2..9383ec903700 100644
--- a/pkgs/development/python-modules/greatfet/default.nix
+++ b/pkgs/development/python-modules/greatfet/default.nix
@@ -1,46 +1,69 @@
 {
-  lib,
-  fetchFromGitHub,
   buildPythonPackage,
-  isPy3k,
+  cmsis-svd,
+  fetchFromGitHub,
   future,
-  pyusb,
   ipython,
+  lib,
+  prompt-toolkit,
+  pyfwup,
   pygreat,
+  pythonOlder,
+  pyusb,
+  setuptools,
+  tabulate,
+  tqdm,
 }:
 
 buildPythonPackage rec {
   pname = "greatfet";
   version = "2024.0.1";
+  pyproject = true;
+
+  disabled = pythonOlder "3.8";
 
   src = fetchFromGitHub {
     owner = "greatscottgadgets";
     repo = "greatfet";
     rev = "refs/tags/v${version}";
-    sha256 = "sha256-AKpaJZJTzMY3IQXLvVnLWh3IHeGp759z6tvaBl28BHQ=";
+    hash = "sha256-AKpaJZJTzMY3IQXLvVnLWh3IHeGp759z6tvaBl28BHQ=";
   };
 
-  disabled = !isPy3k;
+  sourceRoot = "${src.name}/host";
 
-  propagatedBuildInputs = [
+  postPatch = ''
+    substituteInPlace pyproject.toml \
+      --replace-fail ', "setuptools-git-versioning<2"' "" \
+      --replace-fail 'dynamic = ["version"]' 'version = "${version}"'
+  '';
+
+  build-system = [ setuptools ];
+
+  dependencies = [
+    cmsis-svd
     future
-    pyusb
     ipython
+    prompt-toolkit
+    pyfwup
     pygreat
+    pyusb
+    tabulate
+    tqdm
   ];
 
+  # Tests seem to require devices (or simulators) which are
+  # not available in the build sandbox.
   doCheck = false;
 
-  preBuild = ''
-    cd host
-    echo "$version" > ../VERSION
-  '';
-
   meta = {
     description = "Hardware hacking with the greatfet";
     homepage = "https://greatscottgadgets.com/greatfet";
     license = lib.licenses.bsd3;
     platforms = lib.platforms.all;
-    maintainers = with lib.maintainers; [ mog ];
+    mainProgram = "gf";
+    maintainers = with lib.maintainers; [
+      mog
+      msanft
+    ];
   };
 }