From 3d794b1dfe66ec8a555361687d0c15afb4581374 Mon Sep 17 00:00:00 2001 From: Fernando Rodrigues Date: Thu, 31 Oct 2024 14:52:18 +0000 Subject: [PATCH 1/5] gnuk: convert into a saner derivation This absolutely does not need a generic builder. Signed-off-by: Fernando Rodrigues --- pkgs/misc/gnuk/default.nix | 49 ++++++++++++++++++++++++++++++++--- pkgs/misc/gnuk/generic.nix | 52 -------------------------------------- 2 files changed, 46 insertions(+), 55 deletions(-) delete mode 100644 pkgs/misc/gnuk/generic.nix diff --git a/pkgs/misc/gnuk/default.nix b/pkgs/misc/gnuk/default.nix index afef861c0dc4f..29198c196ad58 100644 --- a/pkgs/misc/gnuk/default.nix +++ b/pkgs/misc/gnuk/default.nix @@ -1,6 +1,13 @@ -{ callPackage, fetchgit, ... } @ args: +{ lib, stdenv, gcc-arm-embedded, binutils-arm-embedded, makeWrapper +, python3Packages, fetchgit + +# Extra options +, vid ? "234b", pid ? "0000" +}: + +stdenv.mkDerivation { + pname = "gnuk"; -callPackage ./generic.nix (args // { version = "1.2.14"; src = fetchgit { @@ -8,4 +15,40 @@ callPackage ./generic.nix (args // { rev = "177ef67edfa2306c2a369a037362385c354083e1"; sha256 = "16wa3xsaq4r8caw6c24hnv4j78bklacix4in2y66j35h68ggr3j1"; }; -}) + + nativeBuildInputs = [ gcc-arm-embedded binutils-arm-embedded makeWrapper ]; + buildInputs = with python3Packages; [ python pyusb colorama ]; + + configurePhase = '' + cd src + patchShebangs configure + ./configure --vidpid=${vid}:${pid} + ''; + + installPhase = '' + mkdir -p $out/bin + + find . -name gnuk.bin -exec cp {} $out \; + + #sed -i 's,Exception as e,IOError as e,' ../tool/stlinkv2.py + sed -i ../tool/stlinkv2.py \ + -e "1a import array" \ + -e "s,\(data_received =\) (),\1 array.array('B'),g" \ + -e "s,\(data_received\) = data_received + \(.*\),\1.extend(\2),g" + cp ../tool/stlinkv2.py $out/bin/stlinkv2 + wrapProgram $out/bin/stlinkv2 --prefix PYTHONPATH : "$PYTHONPATH" + + # Some useful helpers + echo "#! ${stdenv.shell} -e" | tee $out/bin/{unlock,flash} + echo "$out/bin/stlinkv2 -u \$@" >> $out/bin/unlock + echo "$out/bin/stlinkv2 -b \$@ $out/gnuk.bin" >> $out/bin/flash + chmod +x $out/bin/{unlock,flash} + ''; + + meta = with lib; { + homepage = "https://www.fsij.org/doc-gnuk/"; + description = "Implementation of USB cryptographic token for gpg"; + license = licenses.gpl3; + platforms = with platforms; linux; + }; +} diff --git a/pkgs/misc/gnuk/generic.nix b/pkgs/misc/gnuk/generic.nix deleted file mode 100644 index e9cc3aff2cf6f..0000000000000 --- a/pkgs/misc/gnuk/generic.nix +++ /dev/null @@ -1,52 +0,0 @@ -{ lib, stdenv, gcc-arm-embedded, binutils-arm-embedded, makeWrapper -, python3Packages - -# Extra options -, device ? "fsij", vid ? "234b", pid ? "0000" - -# Version specific options -, version, src -, ... -}: - -stdenv.mkDerivation { - pname = "gnuk-${device}"; - - inherit version src; - - nativeBuildInputs = [ gcc-arm-embedded binutils-arm-embedded makeWrapper ]; - buildInputs = with python3Packages; [ python pyusb colorama ]; - - configurePhase = '' - cd src - patchShebangs configure - ./configure --vidpid=${vid}:${pid} - ''; - - installPhase = '' - mkdir -p $out/bin - - find . -name gnuk.bin -exec cp {} $out \; - - #sed -i 's,Exception as e,IOError as e,' ../tool/stlinkv2.py - sed -i ../tool/stlinkv2.py \ - -e "1a import array" \ - -e "s,\(data_received =\) (),\1 array.array('B'),g" \ - -e "s,\(data_received\) = data_received + \(.*\),\1.extend(\2),g" - cp ../tool/stlinkv2.py $out/bin/stlinkv2 - wrapProgram $out/bin/stlinkv2 --prefix PYTHONPATH : "$PYTHONPATH" - - # Some useful helpers - echo "#! ${stdenv.shell} -e" | tee $out/bin/{unlock,flash} - echo "$out/bin/stlinkv2 -u \$@" >> $out/bin/unlock - echo "$out/bin/stlinkv2 -b \$@ $out/gnuk.bin" >> $out/bin/flash - chmod +x $out/bin/{unlock,flash} - ''; - - meta = with lib; { - homepage = "https://www.fsij.org/doc-gnuk/"; - description = "Implementation of USB cryptographic token for gpg"; - license = licenses.gpl3; - platforms = with platforms; linux; - }; -} From 4e63264c5427e2e09db6f4252dd2f8d7aa5792d0 Mon Sep 17 00:00:00 2001 From: Fernando Rodrigues Date: Thu, 31 Oct 2024 15:40:02 +0000 Subject: [PATCH 2/5] gnuk: format with nixfmt-rfc-style Signed-off-by: Fernando Rodrigues --- pkgs/misc/gnuk/default.nix | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/pkgs/misc/gnuk/default.nix b/pkgs/misc/gnuk/default.nix index 29198c196ad58..9da9e1d69af3e 100644 --- a/pkgs/misc/gnuk/default.nix +++ b/pkgs/misc/gnuk/default.nix @@ -1,8 +1,15 @@ -{ lib, stdenv, gcc-arm-embedded, binutils-arm-embedded, makeWrapper -, python3Packages, fetchgit +{ + lib, + stdenv, + gcc-arm-embedded, + binutils-arm-embedded, + makeWrapper, + python3Packages, + fetchgit, -# Extra options -, vid ? "234b", pid ? "0000" + # Extra options + vid ? "234b", + pid ? "0000", }: stdenv.mkDerivation { @@ -16,8 +23,16 @@ stdenv.mkDerivation { sha256 = "16wa3xsaq4r8caw6c24hnv4j78bklacix4in2y66j35h68ggr3j1"; }; - nativeBuildInputs = [ gcc-arm-embedded binutils-arm-embedded makeWrapper ]; - buildInputs = with python3Packages; [ python pyusb colorama ]; + nativeBuildInputs = [ + gcc-arm-embedded + binutils-arm-embedded + makeWrapper + ]; + buildInputs = with python3Packages; [ + python + pyusb + colorama + ]; configurePhase = '' cd src From ac2bd873a34bad238808ff94f0a8592ff4780ea3 Mon Sep 17 00:00:00 2001 From: Fernando Rodrigues Date: Thu, 31 Oct 2024 15:42:19 +0000 Subject: [PATCH 3/5] gnuk: replace configurePhase with configureFlags and sourceRoot Signed-off-by: Fernando Rodrigues --- pkgs/misc/gnuk/default.nix | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkgs/misc/gnuk/default.nix b/pkgs/misc/gnuk/default.nix index 9da9e1d69af3e..46a98ed198669 100644 --- a/pkgs/misc/gnuk/default.nix +++ b/pkgs/misc/gnuk/default.nix @@ -34,12 +34,11 @@ stdenv.mkDerivation { colorama ]; - configurePhase = '' - cd src - patchShebangs configure - ./configure --vidpid=${vid}:${pid} - ''; + sourceRoot = "${finalAttrs.src.name}/src"; + + configureFlags = [ "--vidpid=${vid}:${pid}" ]; + # TODO: Check how many of these patches are actually needed. installPhase = '' mkdir -p $out/bin From cab0d917f430d0608e39e1f097f5f00c36232b5d Mon Sep 17 00:00:00 2001 From: Fernando Rodrigues Date: Thu, 31 Oct 2024 15:41:26 +0000 Subject: [PATCH 4/5] gnuk: 1.2.14 -> 2.2 Still broken, as they switched from newlib to picolib. Signed-off-by: Fernando Rodrigues --- pkgs/misc/gnuk/default.nix | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pkgs/misc/gnuk/default.nix b/pkgs/misc/gnuk/default.nix index 46a98ed198669..af4e7d371f1e1 100644 --- a/pkgs/misc/gnuk/default.nix +++ b/pkgs/misc/gnuk/default.nix @@ -1,26 +1,28 @@ { lib, stdenv, + fetchFromGitLab, gcc-arm-embedded, binutils-arm-embedded, makeWrapper, python3Packages, - fetchgit, # Extra options vid ? "234b", pid ? "0000", }: -stdenv.mkDerivation { +stdenv.mkDerivation (finalAttrs: { pname = "gnuk"; + version = "2.2"; - version = "1.2.14"; - - src = fetchgit { - url = "git://git.gniibe.org/gnuk/gnuk.git"; - rev = "177ef67edfa2306c2a369a037362385c354083e1"; - sha256 = "16wa3xsaq4r8caw6c24hnv4j78bklacix4in2y66j35h68ggr3j1"; + src = fetchFromGitLab { + domain = "salsa.debian.org"; + owner = "gnuk-team"; + repo = "gnuk/gnuk"; + rev = "release/${finalAttrs.version}"; + hash = "sha256-qY/dwkcPJiPx/+inSxH7w7a0v3cWUQDX+NYJwUjnkMY="; + fetchSubmodules = true; }; nativeBuildInputs = [ @@ -65,4 +67,4 @@ stdenv.mkDerivation { license = licenses.gpl3; platforms = with platforms; linux; }; -} +}) From ec8cc3e7175aa57d0edd2fb5a6e6e8cd319da183 Mon Sep 17 00:00:00 2001 From: Fernando Rodrigues Date: Thu, 31 Oct 2024 15:42:01 +0000 Subject: [PATCH 5/5] gnuk: set as broken, use correct homepage in meta and remove nested with expression Signed-off-by: Fernando Rodrigues --- pkgs/misc/gnuk/default.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkgs/misc/gnuk/default.nix b/pkgs/misc/gnuk/default.nix index af4e7d371f1e1..98eb9c12aef08 100644 --- a/pkgs/misc/gnuk/default.nix +++ b/pkgs/misc/gnuk/default.nix @@ -7,7 +7,7 @@ makeWrapper, python3Packages, - # Extra options + # Default FSIJ IDs vid ? "234b", pid ? "0000", }: @@ -30,6 +30,7 @@ stdenv.mkDerivation (finalAttrs: { binutils-arm-embedded makeWrapper ]; + buildInputs = with python3Packages; [ python pyusb @@ -61,10 +62,12 @@ stdenv.mkDerivation (finalAttrs: { chmod +x $out/bin/{unlock,flash} ''; - meta = with lib; { - homepage = "https://www.fsij.org/doc-gnuk/"; + meta = { + homepage = "https://www.fsij.org/category/gnuk.html"; description = "Implementation of USB cryptographic token for gpg"; - license = licenses.gpl3; - platforms = with platforms; linux; + license = lib.licenses.gpl3; + platforms = lib.platforms.linux; + maintainers = [ ]; + broken = true; # Needs Picolib, which is not packaged in Nixpkgs. }; })