From 2a1528fdab11ef5d421d962ecfc617488cedb5c8 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Wed, 10 Jul 2024 01:46:37 +0000 Subject: [PATCH] packages/cynthion: init --- flake.nix | 1 + packages/cynthion/default.nix | 215 ++++++++++++++++++++++++++++++++++ 2 files changed, 216 insertions(+) create mode 100644 packages/cynthion/default.nix diff --git a/flake.nix b/flake.nix index 2c3e627..6b6def7 100644 --- a/flake.nix +++ b/flake.nix @@ -58,6 +58,7 @@ attic = final.callPackage ./packages/attic { }; attic-client = final.attic.override { clientOnly = true; }; cups-dymo-patched = final.callPackage ./packages/cups-dymo { }; + cynthion = final.callPackage ./packages/cynthion { }; hactoolnet = final.callPackage ./packages/hactoolnet { }; ipsw = final.callPackage ./packages/ipsw { }; jlink = final.callPackage ./packages/jlink { }; diff --git a/packages/cynthion/default.nix b/packages/cynthion/default.nix new file mode 100644 index 0000000..54cf486 --- /dev/null +++ b/packages/cynthion/default.nix @@ -0,0 +1,215 @@ +{ fetchFromGitHub, python3 }: + +let + pyfwup = python3.pkgs.buildPythonPackage rec { + pname = "pyfwup"; + version = "0.4.0"; + + src = fetchFromGitHub { + owner = "greatscottgadgets"; + repo = pname; + rev = version; + hash = "sha256-JSaAEGobdLqpSj9yvKrAsXfdkHpXSCcuGYRxz2QJqck="; + }; + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail '"setuptools-git-versioning<2"' "" \ + --replace-fail 'dynamic = ["version"]' 'version = "${version}"' + ''; + + pyproject = true; + + nativeBuildInputs = with python3.pkgs; [ setuptools ]; + + propagatedBuildInputs = with python3.pkgs; [ + pyusb + tqdm + ]; + }; + + pygreat = python3.pkgs.buildPythonPackage rec { + pname = "pygreat"; + version = "2024.0.1"; + + src = fetchFromGitHub { + owner = "greatscottgadgets"; + repo = "libgreat"; + rev = "v${version}"; + hash = "sha256-k+0dGBohKglQEFN13mGsw0C6pCeQDRp+CwPW2GuKfuY="; + }; + + sourceRoot = "${src.name}/host"; + + postPatch = '' + substituteInPlace pyproject.toml --replace '"backports.functools_lru_cache",' "" + substituteInPlace pygreat/comms.py --replace "from backports.functools_lru_cache import lru_cache as memoize_with_lru_cache" "from functools import lru_cache as memoize_with_lru_cache" + substituteInPlace pyproject.toml \ + --replace-fail '"setuptools-git-versioning<2"' "" \ + --replace-fail 'dynamic = ["version"]' 'version = "${version}"' + ''; + + pyproject = true; + nativeBuildInputs = with python3.pkgs; [ setuptools ]; + propagatedBuildInputs = with python3.pkgs; [ + pyusb + future + ]; + }; + + amaranth = python3.pkgs.amaranth.overrideAttrs (attrs: rec { + version = "0.4.1"; + src = fetchFromGitHub { + owner = "amaranth-lang"; + repo = "amaranth"; + rev = "refs/tags/v${version}"; + hash = "sha256-VMgycvxkphdpWIib7aZwh588En145RgYlG2Zfi6nnDo="; + }; + }); + + apollo-fpga = python3.pkgs.buildPythonPackage rec { + pname = "apollo"; + version = "1.0.7"; + + src = fetchFromGitHub { + owner = "greatscottgadgets"; + repo = pname; + rev = "v${version}"; + hash = "sha256-+a6C1JiSxnIZTjnmkEHKZyjFyDQ0HhGQjBGpxkFIgkY="; + }; + + pyproject = true; + nativeBuildInputs = with python3.pkgs; [ setuptools ]; + propagatedBuildInputs = with python3.pkgs; [ + importlib-resources + pyusb + pyvcd + prompt-toolkit + pyxdg + ]; + + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail '"setuptools-git-versioning<2"' "" \ + --replace-fail 'dynamic = ["version"]' 'version = "${version}"' + ''; + }; + usb-protocol = python3.pkgs.buildPythonPackage rec { + pname = "usb-protocol"; + version = "0.9.1"; + + src = fetchFromGitHub { + owner = "greatscottgadgets"; + repo = "python-usb-protocol"; + rev = version; + hash = "sha256-CYbXs/SRC1FAVEzfw0gwf6U0qQ9Q34nyuj5yfjHfDn8="; + }; + + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail '"setuptools-git-versioning<2"' "" \ + --replace-fail 'dynamic = ["version"]' 'version = "${version}"' + ''; + + pyproject = true; + nativeBuildInputs = with python3.pkgs; [ setuptools ]; + propagatedBuildInputs = with python3.pkgs; [ construct ]; + }; + luna-usb = python3.pkgs.buildPythonPackage rec { + pname = "luna-usb"; + version = "0.1.1"; + + src = fetchFromGitHub { + owner = "greatscottgadgets"; + repo = "luna"; + rev = version; + hash = "sha256-81GJF3QLERCmvZXYlQvb1vzJFeGMSMNMwuGoaBJE8Zg="; + }; + + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail '"setuptools-git-versioning<2"' "" \ + --replace-fail 'dynamic = ["version"]' 'version = "${version}"' + ''; + + pyproject = true; + nativeBuildInputs = with python3.pkgs; [ setuptools ]; + propagatedBuildInputs = + [ + amaranth + usb-protocol + ] + ++ (with python3.pkgs; [ + libusb1 + pyserial + pyusb + pyvcd + ]); + }; + luna-soc = python3.pkgs.buildPythonPackage rec { + pname = "luna-soc"; + version = "0.2.0"; + + src = fetchFromGitHub { + owner = "greatscottgadgets"; + repo = pname; + rev = version; + hash = "sha256-P8P32hM1cVXENcDpCrmPe8BvkMCWdeEgHwbIU94uLe8="; + }; + + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail '"setuptools-git-versioning<2"' "" \ + --replace-fail 'dynamic = ["version"]' 'version = "${version}"' + ''; + + pyproject = true; + nativeBuildInputs = with python3.pkgs; [ setuptools ]; + propagatedBuildInputs = [ luna-usb ]; + }; + + version = "0.1.2"; + src = fetchFromGitHub { + owner = "greatscottgadgets"; + repo = "cynthion"; + rev = version; + hash = "sha256-eLimS2gghT52tV01ZlFs8xEwwibB4yezl3eW7zrHpW8="; + }; +in +python3.pkgs.buildPythonApplication { + pname = "cynthion"; + inherit version src; + + sourceRoot = "${src.name}/cynthion/python"; + + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail '"setuptools-git-versioning<2"' "" \ + --replace-fail 'dynamic = ["version"]' 'version = "${version}"' + ''; + + postInstall = '' + install -D assets/54-cynthion.rules $out/lib/udev/rules.d/54-cynthion.rules + ''; + + pyproject = true; + nativeBuildInputs = with python3.pkgs; [ setuptools ]; + propagatedBuildInputs = + [ + amaranth + apollo-fpga + pyfwup + pygreat + luna-usb + luna-soc + ] + ++ (with python3.pkgs; [ + future + libusb1 + prompt-toolkit + pyserial + pyusb + tabulate + tomli + tqdm + ]); +}