From 552efeba59d5e7b75046161a91679d273eda1e8a Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Sat, 20 May 2023 14:46:37 +0200 Subject: [PATCH 1/3] nut: actually update to 2.8.0 The previous attempt at updating nut forgot to change the fod hash for the source code. Actually updating to 2.8.0 required some changes to dependencies and the patch for nut-scanner. We no longer need --without-hal because HAL support was removed as far back as verison 2.7.2. --- pkgs/applications/misc/nut/default.nix | 49 ++++++++++++++----- .../misc/nut/hardcode-paths.patch | 17 ++++--- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/pkgs/applications/misc/nut/default.nix b/pkgs/applications/misc/nut/default.nix index 45db4d479775..0afe4bf18c1e 100644 --- a/pkgs/applications/misc/nut/default.nix +++ b/pkgs/applications/misc/nut/default.nix @@ -1,5 +1,21 @@ -{ lib, stdenv, fetchurl, substituteAll, pkg-config, neon, libusb-compat-0_1, openssl, udev, avahi, freeipmi -, libtool, makeWrapper, autoreconfHook, fetchpatch +{ lib +, stdenv +, autoreconfHook +, avahi +, coreutils +, fetchurl +, freeipmi +, i2c-tools +, libmodbus +, libtool +, libusb-compat-0_1 +, makeWrapper +, neon +, openssl +, pkg-config +, substituteAll +, systemd +, udev }: stdenv.mkDerivation rec { @@ -8,25 +24,21 @@ stdenv.mkDerivation rec { src = fetchurl { url = "https://networkupstools.org/source/${lib.versions.majorMinor version}/${pname}-${version}.tar.gz"; - sha256 = "19r5dm07sfz495ckcgbfy0pasx0zy3faa0q7bih69lsjij8q43lq"; + sha256 = "sha256-w+WnCNp5e3xwtlPTexIGoAD8tQO4VRn+TN9jU/eSv+U="; }; patches = [ - (fetchpatch { - # Fix build with openssl >= 1.1.0 - url = "https://github.com/networkupstools/nut/commit/612c05efb3c3b243da603a3a050993281888b6e3.patch"; - sha256 = "0jdbii1z5sqyv24286j5px65j7b3gp8zk3ahbph83pig6g46m3hs"; - }) (substituteAll { src = ./hardcode-paths.patch; avahi = "${avahi}/lib"; freeipmi = "${freeipmi}/lib"; libusb = "${libusb-compat-0_1}/lib"; neon = "${neon}/lib"; + libmodbus = "${libmodbus}/lib"; }) ]; - buildInputs = [ neon libusb-compat-0_1 openssl udev avahi freeipmi ]; + buildInputs = [ neon libusb-compat-0_1 openssl udev avahi freeipmi libmodbus i2c-tools ]; nativeBuildInputs = [ autoreconfHook libtool pkg-config makeWrapper ]; @@ -36,14 +48,27 @@ stdenv.mkDerivation rec { "--without-snmp" # Until we have it ... "--without-powerman" # Until we have it ... "--without-cgi" - "--without-hal" - "--with-systemdsystemunitdir=$(out)/etc/systemd/system" + "--with-systemdsystemunitdir=$(out)/lib/systemd/system" + "--with-systemdshutdowndir=$(out)/lib/systemd/system-shutdown" + "--with-systemdtmpfilesdir=$(out)/lib/tmpfiles.d" "--with-udev-dir=$(out)/etc/udev" ]; enableParallelBuilding = true; - env.NIX_CFLAGS_COMPILE = toString [ "-std=c++14" ]; + postInstall = '' + substituteInPlace $out/lib/systemd/system-shutdown/nutshutdown \ + --replace /bin/sleep "${coreutils}/bin/sleep" \ + --replace /bin/systemctl "${systemd}/bin/systemctl" + + for file in system/{nut-monitor.service,nut-driver-enumerator.service,nut-server.service,nut-driver@.service} system-shutdown/nutshutdown; do + substituteInPlace $out/lib/systemd/$file \ + --replace "$out/etc/nut.conf" "/etc/nut.conf" + done + + # we don't need init.d scripts + rm -r $out/share/solaris-init + ''; meta = with lib; { description = "Network UPS Tools"; diff --git a/pkgs/applications/misc/nut/hardcode-paths.patch b/pkgs/applications/misc/nut/hardcode-paths.patch index db6d68471ce5..5116fb438e53 100644 --- a/pkgs/applications/misc/nut/hardcode-paths.patch +++ b/pkgs/applications/misc/nut/hardcode-paths.patch @@ -1,13 +1,14 @@ ---- a/tools/nut-scanner/nutscan-init.c -+++ b/tools/nut-scanner/nutscan-init.c -@@ -44,6 +44,10 @@ int nutscan_load_upsclient_library(const char *libname_path); - - /* FIXME: would be good to get more from /etc/ld.so.conf[.d] */ - char * search_paths[] = { +--- a/common/common.c ++++ b/common/common.c +@@ -991,6 +991,11 @@ ssize_t select_write(const int fd, const void *buf, const size_t buflen, const t + * communications media and/or vendor protocol. + */ + static const char * search_paths[] = { + "@avahi@", + "@freeipmi@", + "@libusb@", + "@neon@", ++ "@libmodbus@", + /* Use the library path (and bitness) provided during ./configure first */ LIBDIR, - "/usr/lib64", - "/lib64", + "/usr"LIBDIR, From eef5476659f1a4990e892122fcd9aa4e6157328f Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Sat, 20 May 2023 15:42:49 +0200 Subject: [PATCH 2/3] nut: add support for SNMP and CGI --- pkgs/applications/misc/nut/default.nix | 7 ++++--- pkgs/applications/misc/nut/hardcode-paths.patch | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/misc/nut/default.nix b/pkgs/applications/misc/nut/default.nix index 0afe4bf18c1e..4243dd50b87c 100644 --- a/pkgs/applications/misc/nut/default.nix +++ b/pkgs/applications/misc/nut/default.nix @@ -5,12 +5,14 @@ , coreutils , fetchurl , freeipmi +, gd , i2c-tools , libmodbus , libtool , libusb-compat-0_1 , makeWrapper , neon +, net-snmp , openssl , pkg-config , substituteAll @@ -35,19 +37,18 @@ stdenv.mkDerivation rec { libusb = "${libusb-compat-0_1}/lib"; neon = "${neon}/lib"; libmodbus = "${libmodbus}/lib"; + netsnmp = "${net-snmp.lib}/lib"; }) ]; - buildInputs = [ neon libusb-compat-0_1 openssl udev avahi freeipmi libmodbus i2c-tools ]; + buildInputs = [ neon libusb-compat-0_1 openssl udev avahi freeipmi libmodbus i2c-tools net-snmp gd ]; nativeBuildInputs = [ autoreconfHook libtool pkg-config makeWrapper ]; configureFlags = [ "--with-all" "--with-ssl" - "--without-snmp" # Until we have it ... "--without-powerman" # Until we have it ... - "--without-cgi" "--with-systemdsystemunitdir=$(out)/lib/systemd/system" "--with-systemdshutdowndir=$(out)/lib/systemd/system-shutdown" "--with-systemdtmpfilesdir=$(out)/lib/tmpfiles.d" diff --git a/pkgs/applications/misc/nut/hardcode-paths.patch b/pkgs/applications/misc/nut/hardcode-paths.patch index 5116fb438e53..a58d402a2058 100644 --- a/pkgs/applications/misc/nut/hardcode-paths.patch +++ b/pkgs/applications/misc/nut/hardcode-paths.patch @@ -1,6 +1,6 @@ --- a/common/common.c +++ b/common/common.c -@@ -991,6 +991,11 @@ ssize_t select_write(const int fd, const void *buf, const size_t buflen, const t +@@ -991,6 +991,12 @@ ssize_t select_write(const int fd, const void *buf, const size_t buflen, const t * communications media and/or vendor protocol. */ static const char * search_paths[] = { @@ -9,6 +9,7 @@ + "@libusb@", + "@neon@", + "@libmodbus@", ++ "@netsnmp@", /* Use the library path (and bitness) provided during ./configure first */ LIBDIR, "/usr"LIBDIR, From a99c630c27626d5a15ef11634d1999af63a3bdb4 Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Sat, 20 May 2023 15:47:37 +0200 Subject: [PATCH 3/3] nut: build with libusb 1.0 NUT 2.8.0 adds support for, and defaults to, libusb-1.0. --- pkgs/applications/misc/nut/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/misc/nut/default.nix b/pkgs/applications/misc/nut/default.nix index 4243dd50b87c..275d6bd3d84b 100644 --- a/pkgs/applications/misc/nut/default.nix +++ b/pkgs/applications/misc/nut/default.nix @@ -9,7 +9,7 @@ , i2c-tools , libmodbus , libtool -, libusb-compat-0_1 +, libusb1 , makeWrapper , neon , net-snmp @@ -34,14 +34,14 @@ stdenv.mkDerivation rec { src = ./hardcode-paths.patch; avahi = "${avahi}/lib"; freeipmi = "${freeipmi}/lib"; - libusb = "${libusb-compat-0_1}/lib"; + libusb = "${libusb1}/lib"; neon = "${neon}/lib"; libmodbus = "${libmodbus}/lib"; netsnmp = "${net-snmp.lib}/lib"; }) ]; - buildInputs = [ neon libusb-compat-0_1 openssl udev avahi freeipmi libmodbus i2c-tools net-snmp gd ]; + buildInputs = [ neon libusb1 openssl udev avahi freeipmi libmodbus i2c-tools net-snmp gd ]; nativeBuildInputs = [ autoreconfHook libtool pkg-config makeWrapper ];