btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / nu / nut / package.nix
blobcded819dbb5bed3b70124c3559da9edf5e74ed36
1 { lib
2 , stdenv
3 , autoreconfHook
4 , avahi
5 , coreutils
6 , fetchurl
7 , freeipmi
8 , gd
9 , i2c-tools
10 , libgpiod_1
11 , libmodbus
12 , libtool
13 , libusb1
14 , makeWrapper
15 , neon
16 , net-snmp
17 , openssl
18 , pkg-config
19 , substituteAll
20 , systemd
21 , udev
22 , gnused
25 stdenv.mkDerivation rec {
26   pname = "nut";
27   version = "2.8.2";
29   src = fetchurl {
30     url = "https://networkupstools.org/source/${lib.versions.majorMinor version}/${pname}-${version}.tar.gz";
31     sha256 = "sha256-5LSwy+fdObqQl75/fXh7sv/74132Tf9Ttf45PWWcWX0=";
32   };
34   patches = [
35     # This patch injects a default value for NUT_CONFPATH into the nutshutdown script
36     # since the way we build the package results in the binaries being hardcoded to check
37     # $out/etc/ups.conf instead of /etc/nut/ups.conf (where the module places the file).
38     # We also cannot use `--sysconfdir=/etc/nut` since that results in the install phase
39     # trying to install directly into /etc/nut which predictably fails
40     ./nutshutdown-conf-default.patch
42     (substituteAll {
43       src = ./hardcode-paths.patch;
44       avahi = "${avahi}/lib";
45       freeipmi = "${freeipmi}/lib";
46       libgpiod = "${libgpiod_1}/lib";
47       libusb = "${libusb1}/lib";
48       neon = "${neon}/lib";
49       libmodbus = "${libmodbus}/lib";
50       netsnmp = "${net-snmp.lib}/lib";
51     })
52   ];
54   buildInputs = [ neon libusb1 openssl udev avahi freeipmi libgpiod_1 libmodbus libtool i2c-tools net-snmp gd ];
56   nativeBuildInputs = [ autoreconfHook pkg-config makeWrapper ];
58   configureFlags =
59     [ "--with-all"
60       "--with-ssl"
61       "--without-powerman" # Until we have it ...
62       "--with-systemdsystemunitdir=$(out)/lib/systemd/system"
63       "--with-systemdshutdowndir=$(out)/lib/systemd/system-shutdown"
64       "--with-systemdtmpfilesdir=$(out)/lib/tmpfiles.d"
65       "--with-udev-dir=$(out)/etc/udev"
66     ];
68   enableParallelBuilding = true;
70   # Add `cgi-bin` to the default list to avoid pulling in whole
71   # of `gcc` into build closure.
72   stripDebugList = [ "cgi-bin" "lib" "lib32" "lib64" "libexec" "bin" "sbin" ];
74   postInstall = ''
75     substituteInPlace $out/lib/systemd/system-shutdown/nutshutdown \
76       --replace /bin/sed "${gnused}/bin/sed" \
77       --replace /bin/sleep "${coreutils}/bin/sleep" \
78       --replace /bin/systemctl "${systemd}/bin/systemctl"
80     for file in system/{nut-monitor.service,nut-driver-enumerator.service,nut-server.service,nut-driver@.service} system-shutdown/nutshutdown; do
81       substituteInPlace $out/lib/systemd/$file \
82         --replace "$out/etc/nut.conf" "/etc/nut/nut.conf"
83     done
85     substituteInPlace $out/lib/systemd/system/nut-driver-enumerator.path \
86       --replace "$out/etc/ups.conf" "/etc/nut/ups.conf"
88     # Suspicious/overly broad rule, remove it until we know better
89     rm $out/etc/udev/rules.d/52-nut-ipmipsu.rules
90   '';
92   meta = with lib; {
93     description = "Network UPS Tools";
94     longDescription = ''
95       Network UPS Tools is a collection of programs which provide a common
96       interface for monitoring and administering UPS, PDU and SCD hardware.
97       It uses a layered approach to connect all of the parts.
98     '';
99     homepage = "https://networkupstools.org/";
100     platforms = platforms.linux;
101     maintainers = [ maintainers.pierron ];
102     license = with licenses; [ gpl1Plus gpl2Plus gpl3Plus ];
103     priority = 10;
104   };