From 0ccb80a68d58182a19a73dbd5bc633d916440313 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 11 Apr 2024 10:59:07 -0700 Subject: [PATCH 1/8] avrdude: use libusb1 as upstream is compatible now --- pkgs/development/embedded/avrdude/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix index 924c50235821..3360ad2b89e0 100644 --- a/pkgs/development/embedded/avrdude/default.nix +++ b/pkgs/development/embedded/avrdude/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, cmake, bison, flex, libusb-compat-0_1, libelf +{ lib, stdenv, fetchFromGitHub, cmake, bison, flex, libusb1, libelf , libftdi1, readline, libserialport # documentation building is broken on darwin , docSupport ? (!stdenv.isDarwin), texliveMedium, texinfo, texi2html, unixtools }: @@ -21,7 +21,7 @@ stdenv.mkDerivation rec { texi2html ]; - buildInputs = [ libusb-compat-0_1 libelf libftdi1 libserialport readline ]; + buildInputs = [ libusb1 libelf libftdi1 libserialport readline ]; cmakeFlags = lib.optionals docSupport [ "-DBUILD_DOC=ON" From 0665935e754fdd119db5f8578b397bf1c6d25eb7 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 11 Apr 2024 11:02:40 -0700 Subject: [PATCH 2/8] avrdude: enable hidapi support, as it builds on both linux and darwin --- pkgs/development/embedded/avrdude/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix index 3360ad2b89e0..0e957f837c60 100644 --- a/pkgs/development/embedded/avrdude/default.nix +++ b/pkgs/development/embedded/avrdude/default.nix @@ -1,5 +1,5 @@ { lib, stdenv, fetchFromGitHub, cmake, bison, flex, libusb1, libelf -, libftdi1, readline, libserialport +, libftdi1, readline, libserialport, hidapi # documentation building is broken on darwin , docSupport ? (!stdenv.isDarwin), texliveMedium, texinfo, texi2html, unixtools }: @@ -21,7 +21,7 @@ stdenv.mkDerivation rec { texi2html ]; - buildInputs = [ libusb1 libelf libftdi1 libserialport readline ]; + buildInputs = [ hidapi libusb1 libelf libftdi1 libserialport readline ]; cmakeFlags = lib.optionals docSupport [ "-DBUILD_DOC=ON" From 837069946a05dc39943fc8500623774c9b4c7d04 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 11 Apr 2024 11:35:36 -0700 Subject: [PATCH 3/8] avrdude: document more about why documentation building doesn't work on darwin --- pkgs/development/embedded/avrdude/default.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix index 0e957f837c60..68b819e38c6b 100644 --- a/pkgs/development/embedded/avrdude/default.nix +++ b/pkgs/development/embedded/avrdude/default.nix @@ -1,7 +1,10 @@ { lib, stdenv, fetchFromGitHub, cmake, bison, flex, libusb1, libelf -, libftdi1, readline, libserialport, hidapi -# documentation building is broken on darwin -, docSupport ? (!stdenv.isDarwin), texliveMedium, texinfo, texi2html, unixtools }: +, libftdi1, readline, hidapi, libserialport +# Documentation building doesn't work on Darwin. It fails with: +# Undefined subroutine &Locale::Messages::dgettext called in ... texi2html +# +# https://github.com/NixOS/nixpkgs/issues/224761 +, docSupport ? (!stdenv.hostPlatform.isDarwin), texliveMedium, texinfo, texi2html, unixtools }: stdenv.mkDerivation rec { pname = "avrdude"; From 84604bb80de8e6909df4eba2bd00ebb0ac303296 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 11 Apr 2024 11:42:16 -0700 Subject: [PATCH 4/8] avrdude: turn on SPI support on Linux --- pkgs/development/embedded/avrdude/default.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix index 68b819e38c6b..31f6f26496e2 100644 --- a/pkgs/development/embedded/avrdude/default.nix +++ b/pkgs/development/embedded/avrdude/default.nix @@ -26,9 +26,8 @@ stdenv.mkDerivation rec { buildInputs = [ hidapi libusb1 libelf libftdi1 libserialport readline ]; - cmakeFlags = lib.optionals docSupport [ - "-DBUILD_DOC=ON" - ]; + cmakeFlags = lib.optionals stdenv.hostPlatform.isLinux [ "-DHAVE_LINUXSPI=ON" ] + ++ lib.optionals docSupport [ "-DBUILD_DOC=ON" ]; # dvips output references texlive in comments, resulting in a huge closure postInstall = lib.optionalString docSupport '' From 472fb7ce50ffb750e4d4b6d1bb86501133018db2 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 11 Apr 2024 12:23:18 -0700 Subject: [PATCH 5/8] avrdude: explain why we don't turn HAVE_LINUXGPIO on --- pkgs/development/embedded/avrdude/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix index 31f6f26496e2..423ca7934a94 100644 --- a/pkgs/development/embedded/avrdude/default.nix +++ b/pkgs/development/embedded/avrdude/default.nix @@ -26,6 +26,10 @@ stdenv.mkDerivation rec { buildInputs = [ hidapi libusb1 libelf libftdi1 libserialport readline ]; + # Not used: + # + # -DHAVE_LINUXGPIO=ON because it's incompatible with libgpiod 2.x + # cmakeFlags = lib.optionals stdenv.hostPlatform.isLinux [ "-DHAVE_LINUXSPI=ON" ] ++ lib.optionals docSupport [ "-DBUILD_DOC=ON" ]; From 98e8fbee79016d30d2268a99473cbe88598184d2 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 11 Apr 2024 12:45:44 -0700 Subject: [PATCH 6/8] avrdude: enable parallel port support on Linux (it doesn't work on macOS) --- pkgs/development/embedded/avrdude/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix index 423ca7934a94..f03efa1dc820 100644 --- a/pkgs/development/embedded/avrdude/default.nix +++ b/pkgs/development/embedded/avrdude/default.nix @@ -30,7 +30,8 @@ stdenv.mkDerivation rec { # # -DHAVE_LINUXGPIO=ON because it's incompatible with libgpiod 2.x # - cmakeFlags = lib.optionals stdenv.hostPlatform.isLinux [ "-DHAVE_LINUXSPI=ON" ] + cmakeFlags = [ ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ "-DHAVE_LINUXSPI=ON" "-DHAVE_PARPORT=ON" ] ++ lib.optionals docSupport [ "-DBUILD_DOC=ON" ]; # dvips output references texlive in comments, resulting in a huge closure From 55ddcaf70d70bf287a916624db2bbb5bb41c011a Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 11 Apr 2024 12:57:48 -0700 Subject: [PATCH 7/8] avrdude: use either vendored libelf or elfutils instead of abandoned upstream --- pkgs/development/embedded/avrdude/default.nix | 26 ++++++++++++-- pkgs/development/embedded/avrdude/libelf.nix | 36 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/embedded/avrdude/libelf.nix diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix index f03efa1dc820..b3d6d25f4502 100644 --- a/pkgs/development/embedded/avrdude/default.nix +++ b/pkgs/development/embedded/avrdude/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, cmake, bison, flex, libusb1, libelf +{ lib, callPackage, stdenv, fetchFromGitHub, cmake, bison, flex, libusb1, elfutils , libftdi1, readline, hidapi, libserialport # Documentation building doesn't work on Darwin. It fails with: # Undefined subroutine &Locale::Messages::dgettext called in ... texi2html @@ -6,6 +6,10 @@ # https://github.com/NixOS/nixpkgs/issues/224761 , docSupport ? (!stdenv.hostPlatform.isDarwin), texliveMedium, texinfo, texi2html, unixtools }: +let + useElfutils = lib.meta.availableOn stdenv.hostPlatform elfutils; +in + stdenv.mkDerivation rec { pname = "avrdude"; version = "7.3"; @@ -24,7 +28,19 @@ stdenv.mkDerivation rec { texi2html ]; - buildInputs = [ hidapi libusb1 libelf libftdi1 libserialport readline ]; + buildInputs = [ + (if useElfutils then elfutils else finalAttrs.finalPackage.passthru.libelf) + hidapi + libusb1 + libftdi1 + libserialport + readline + ]; + + postPatch = lib.optionalString (!useElfutils) '' + # vendored libelf is a static library + sed -i "s/PREFERRED_LIBELF elf/PREFERRED_LIBELF libelf.a elf/" CMakeLists.txt + ''; # Not used: # @@ -39,6 +55,12 @@ stdenv.mkDerivation rec { rm $out/share/doc/${pname}/*.ps ''; + passthru = { + # Vendored and mutated copy of libelf for avrdudes use. + # Produces a static library only. + libelf = callPackage ./libelf.nix { }; + }; + meta = with lib; { description = "Command-line tool for programming Atmel AVR microcontrollers"; mainProgram = "avrdude"; diff --git a/pkgs/development/embedded/avrdude/libelf.nix b/pkgs/development/embedded/avrdude/libelf.nix new file mode 100644 index 000000000000..bd7b7be7066a --- /dev/null +++ b/pkgs/development/embedded/avrdude/libelf.nix @@ -0,0 +1,36 @@ +{ + lib, + stdenv, + cmake, + fetchFromGitHub, +}: + +stdenv.mkDerivation { + pname = "libelf"; + version = "0.8.13-unstable-2023-01-14"; + + src = fetchFromGitHub { + owner = "avrdudes"; + repo = "libelf"; + rev = "0c55bfe1d3020a20bddf6ce57c0d9d98ccb12586"; + hash = "sha256-jz7Ef0Eg673IJVZvVNklY40s13LCuMVAc7FGrRI7scQ="; + }; + + nativeBuildInputs = [ cmake ]; + + installPhase = '' + runHook preInstall + mkdir -p $out/lib + cp liblibelf.a $out/lib/libelf.a + cp -r $src/include $out/include + runHook postInstall + ''; + + meta = { + description = "ELF object file access library (vendored by avrdudes)"; + homepage = "https://github.com/avrdudes/libelf"; + license = lib.licenses.lgpl2Plus; + platforms = lib.platforms.all; + maintainers = [ lib.maintainers.bjornfor ]; + }; +} From 07b7ca8345611c1e46fde38ae40397737e4695d7 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 11 Apr 2024 12:59:01 -0700 Subject: [PATCH 8/8] avrdude: use finalAttrs instead of rec --- pkgs/development/embedded/avrdude/default.nix | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix index b3d6d25f4502..41b6c5ffc940 100644 --- a/pkgs/development/embedded/avrdude/default.nix +++ b/pkgs/development/embedded/avrdude/default.nix @@ -10,14 +10,14 @@ let useElfutils = lib.meta.availableOn stdenv.hostPlatform elfutils; in -stdenv.mkDerivation rec { +stdenv.mkDerivation (finalAttrs: { pname = "avrdude"; version = "7.3"; src = fetchFromGitHub { owner = "avrdudes"; - repo = pname; - rev = "v${version}"; + repo = "avdude"; + rev = "v${finalAttrs.version}"; sha256 = "sha256-JqW3AOMmAfcy+PQRcqviWlxA6GoMSEfzIFt1pRYY7Dw="; }; @@ -43,16 +43,13 @@ stdenv.mkDerivation rec { ''; # Not used: - # # -DHAVE_LINUXGPIO=ON because it's incompatible with libgpiod 2.x - # - cmakeFlags = [ ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ "-DHAVE_LINUXSPI=ON" "-DHAVE_PARPORT=ON" ] - ++ lib.optionals docSupport [ "-DBUILD_DOC=ON" ]; + cmakeFlags = lib.optionals docSupport [ "-DBUILD_DOC=ON" ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ "-DHAVE_LINUXSPI=ON" "-DHAVE_PARPORT=ON" ]; # dvips output references texlive in comments, resulting in a huge closure postInstall = lib.optionalString docSupport '' - rm $out/share/doc/${pname}/*.ps + rm $out/share/doc/avrdude/*.ps ''; passthru = { @@ -74,4 +71,4 @@ stdenv.mkDerivation rec { platforms = with platforms; linux ++ darwin; maintainers = [ maintainers.bjornfor ]; }; -} +})