1 { stdenv, lib, fetchFromGitHub, fetchurl, cmake, makeWrapper, pkg-config
2 , curl, ffmpeg, glib, libjpeg, libselinux, libsepol, mp4v2, libmysqlclient, mariadb, pcre, perl, perlPackages
3 , polkit, util-linuxMinimal, x264, zlib
4 , coreutils, procps, psmisc, nixosTests }:
8 # 1. ZM_CONFIG_DIR is set to $out/etc/zoneminder as the .conf file distributed
9 # by upstream contains defaults and is not supposed to be edited so it is fine
10 # to keep it read-only.
12 # 2. ZM_CONFIG_SUBDIR is where we place our configuration from the NixOS module
13 # but as the installer will try to put files there, we patch Config.pm after the
16 # 3. ZoneMinder is run with -T passed to the perl interpreter which makes perl
17 # ignore PERL5LIB. We therefore have to do the substitution into -I parameters
18 # ourselves which results in ugly wrappers.
20 # 4. The makefile for the perl modules needs patching to put things into the
21 # right place. That also means we have to not run "make install" for them.
23 # 5. In principal the various ZM_xx variables should be overridable from the
24 # config file but some of them are baked into the perl scripts, so we *have* to
25 # set them here instead of in the configuration in the NixOS module.
27 # 6. I am no PolicyKit expert but the .policy file looks fishy:
28 # a. The user needs to be known at build-time so we should probably throw
29 # upstream's policy file away and generate it from the NixOS module
30 # b. I *think* we may have to substitute the store paths with
31 # /run/current-system/sw/bin paths for it to work.
33 # 7. we manually fix up the perl paths in the scripts as fixupPhase will only
34 # handle pkexec and not perl if both are present.
36 # 8. There are several perl modules needed at runtime which are not checked when
37 # building so if a new version stops working, check if there is a missing
38 # dependency by running the failing component manually.
40 # 9. Parts of the web UI has a hardcoded /zm path so we create a symlink to work
46 path = "scripts/ZoneMinder/lib/ZoneMinder/Control/Xiaomi.pm";
48 url = "https://gist.githubusercontent.com/joshstrange/73a2f24dfaf5cd5b470024096ce2680f/raw/e964270c5cdbf95e5b7f214f7f0fc6113791530e/Xiaomi.pm";
49 sha256 = "04n1ap8fx66xfl9q9rypj48pzbgzikq0gisfsfm8wdsmflarz43v";
55 dirName = "zoneminder";
56 perlBin = "${perl}/bin/perl";
58 in stdenv.mkDerivation rec {
62 src = fetchFromGitHub {
66 hash = "sha256-KUhFZrF7BuLB2Z3LnTcHEEZVA6iosam6YsOd8KWvx7E=";
67 fetchSubmodules = true;
71 ./default-to-http-1dot1.patch
72 ./0001-Don-t-use-file-timestamp-in-cache-filename.patch
76 rm -rf web/api/lib/Cake/Test
78 ${lib.concatStringsSep "\n" (map (e: ''
82 for d in scripts/ZoneMinder onvif/{modules,proxy} ; do
83 substituteInPlace $d/CMakeLists.txt \
84 --replace 'DESTDIR="''${CMAKE_CURRENT_BINARY_DIR}/output"' "PREFIX=$out INSTALLDIRS=site"
85 sed -i '/^install/d' $d/CMakeLists.txt
88 substituteInPlace misc/CMakeLists.txt \
89 --replace '"''${PC_POLKIT_PREFIX}/''${CMAKE_INSTALL_DATAROOTDIR}' "\"$out/share"
91 for f in misc/*.policy.in \
93 scripts/ZoneMinder/lib/ZoneMinder/Memory.pm.in ; do
94 substituteInPlace $f \
95 --replace '/usr/bin/perl' '${perlBin}' \
96 --replace '/bin:/usr/bin' "$out/bin:${lib.makeBinPath [ coreutils procps psmisc ]}"
99 substituteInPlace scripts/zmdbbackup.in \
100 --replace /usr/bin/mysqldump ${mariadb.client}/bin/mysqldump
102 substituteInPlace scripts/zmupdate.pl.in \
103 --replace "'mysql'" "'${mariadb.client}/bin/mysql'" \
104 --replace "'mysqldump'" "'${mariadb.client}/bin/mysqldump'"
106 for f in scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in \
107 scripts/zmupdate.pl.in \
108 src/zm_config_data.h.in \
109 web/api/app/Config/bootstrap.php.in \
110 web/includes/config.php.in ; do
111 substituteInPlace $f --replace @ZM_CONFIG_SUBDIR@ /etc/zoneminder
114 for f in includes/Event.php views/image.php ; do
115 substituteInPlace web/$f \
116 --replace "'ffmpeg " "'${ffmpeg}/bin/ffmpeg "
119 for f in scripts/ZoneMinder/lib/ZoneMinder/Event.pm \
120 scripts/ZoneMinder/lib/ZoneMinder/Storage.pm ; do
121 substituteInPlace $f \
122 --replace '/bin/rm' "${coreutils}/bin/rm"
125 substituteInPlace web/includes/functions.php \
126 --replace "'date " "'${coreutils}/bin/date " \
127 --subst-var-by srcHash "`basename $out`"
131 curl ffmpeg glib libjpeg libselinux libsepol mp4v2 libmysqlclient mariadb pcre perl polkit x264 zlib
132 util-linuxMinimal # for libmount
133 ] ++ (with perlPackages; [
134 # build-time dependencies
135 DateManip DBI DBDmysql LWP SysMmap
136 # run-time dependencies not checked at build-time
137 ClassStdFast DataDump DeviceSerialPort JSONMaybeXS LWPProtocolHttps NumberBytesHuman SysCPU SysMemInfo TimeDate
138 CryptEksblowfish DataEntropy # zmupdate.pl
141 nativeBuildInputs = [ cmake makeWrapper pkg-config ];
145 "-DZM_LOGDIR=/var/log/${dirName}"
146 "-DZM_RUNDIR=/run/${dirName}"
147 "-DZM_SOCKDIR=/run/${dirName}"
148 "-DZM_TMPDIR=/tmp/${dirName}"
149 "-DZM_CONFIG_DIR=${placeholder "out"}/etc/zoneminder"
150 "-DZM_WEB_USER=${user}"
151 "-DZM_WEB_GROUP=${user}"
156 tests = nixosTests.zoneminder;
160 PERL5LIB="$PERL5LIB''${PERL5LIB:+:}$out/${perl.libPrefix}"
163 for i in $(IFS=$'\n'; echo $PERL5LIB | tr ':' "\n" | sort -u); do
164 perlFlags="$perlFlags -I$i"
167 mkdir -p $out/libexec
168 for f in $out/bin/*.pl ; do
170 makeWrapper ${perlBin} $f \
171 --prefix PATH : $out/bin \
172 --add-flags "$perlFlags $out/libexec/$(basename $f)"
175 ln -s $out/share/zoneminder/www $out/share/zoneminder/www/zm
179 description = "Video surveillance software system";
180 homepage = "https://zoneminder.com";
181 license = licenses.gpl3;
183 platforms = platforms.unix;