From beb7e02f1143539c14ce4385befc8cd20730143e Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Wed, 10 Jul 2024 03:42:46 +0000 Subject: [PATCH] packages/cynthion: Build bitstreams --- packages/cynthion/default.nix | 120 +++++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 39 deletions(-) diff --git a/packages/cynthion/default.nix b/packages/cynthion/default.nix index 54cf486..604bfe5 100644 --- a/packages/cynthion/default.nix +++ b/packages/cynthion/default.nix @@ -1,4 +1,12 @@ -{ fetchFromGitHub, python3 }: +{ + fetchFromGitHub, + python3, + zsh, + stdenv, + yosys, + nextpnr, + trellis, +}: let pyfwup = python3.pkgs.buildPythonPackage rec { @@ -174,42 +182,76 @@ let rev = version; hash = "sha256-eLimS2gghT52tV01ZlFs8xEwwibB4yezl3eW7zrHpW8="; }; + cynthion = 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 + ]); + }; + cynthion-bitstreams = stdenv.mkDerivation rec { + pname = "cynthion-bistreams"; + inherit version src; + + sourceRoot = "${src.name}/cynthion/python"; + postPatch = '' + substituteInPlace Makefile --replace-fail '/bin/zsh' '${zsh}/bin/zsh' + rm -r assets + mkdir assets + ''; + + nativeBuildInputs = [ + python3 + cynthion + yosys + nextpnr + trellis + ]; + + buildPhase = '' + make bitstreams + ''; + + installPhase = '' + mv assets $out + ''; + }; 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 - ]); -} +cynthion.overrideAttrs (attrs: { + postPatch = + attrs.postPatch + + '' + ln -s ${cynthion-bitstreams}/* assets + ''; +})