lol
1{ stdenv, fetchurl, pkgconfig, systemd, utillinux, coreutils, nettools, man
2, enableCgiScripts ? true, gd
3}:
4
5assert enableCgiScripts -> gd != null;
6
7stdenv.mkDerivation rec {
8 pname = "apcupsd";
9 name = "${pname}-3.14.14";
10
11 src = fetchurl {
12 url = "mirror://sourceforge/${pname}/${name}.tar.gz";
13 sha256 = "0rwqiyzlg9p0szf3x6q1ppvrw6f6dbpn2rc5z623fk3bkdalhxyv";
14 };
15
16 nativeBuildInputs = [ pkgconfig ];
17 buildInputs = [ utillinux man ] ++ stdenv.lib.optional enableCgiScripts gd;
18
19 prePatch = ''
20 sed -e "s,\$(INSTALL_PROGRAM) \$(STRIP),\$(INSTALL_PROGRAM)," \
21 -i ./src/apcagent/Makefile ./autoconf/targets.mak
22 '';
23
24 # ./configure ignores --prefix, so we must specify some paths manually
25 # There is no real reason for a bin/sbin split, so just use bin.
26 preConfigure = ''
27 export ac_cv_path_SHUTDOWN=${systemd}/sbin/shutdown
28 export ac_cv_path_WALL=${utillinux}/bin/wall
29 sed -i 's|/bin/cat|${coreutils}/bin/cat|' configure
30 export configureFlags="\
31 --bindir=$out/bin \
32 --sbindir=$out/bin \
33 --sysconfdir=$out/etc/apcupsd \
34 --mandir=$out/share/man \
35 --with-halpolicydir=$out/share/halpolicy \
36 --localstatedir=/var/ \
37 --with-nologin=/run \
38 --with-log-dir=/var/log/apcupsd \
39 --with-pwrfail-dir=/run/apcupsd \
40 --with-lock-dir=/run/lock \
41 --with-pid-dir=/run \
42 --enable-usb \
43 ${stdenv.lib.optionalString enableCgiScripts "--enable-cgi --with-cgi-bin=$out/libexec/cgi-bin"}
44 "
45 '';
46
47 postInstall = ''
48 for file in "$out"/etc/apcupsd/*; do
49 sed -i -e 's|^WALL=.*|WALL="${utillinux}/bin/wall"|g' \
50 -e 's|^HOSTNAME=.*|HOSTNAME=`${nettools}/bin/hostname`|g' \
51 "$file"
52 done
53 '';
54
55 meta = with stdenv.lib; {
56 description = "Daemon for controlling APC UPSes";
57 homepage = http://www.apcupsd.com/;
58 license = licenses.gpl2;
59 platforms = platforms.linux;
60 maintainers = [ maintainers.bjornfor ];
61 };
62}