33 # 1. ZM_CONFIG_DIR is set to $out/etc/zoneminder as the .conf file distributed
34 # by upstream contains defaults and is not supposed to be edited so it is fine
35 # to keep it read-only.
37 # 2. ZM_CONFIG_SUBDIR is where we place our configuration from the NixOS module
38 # but as the installer will try to put files there, we patch Config.pm after the
41 # 3. ZoneMinder is run with -T passed to the perl interpreter which makes perl
42 # ignore PERL5LIB. We therefore have to do the substitution into -I parameters
43 # ourselves which results in ugly wrappers.
45 # 4. The makefile for the perl modules needs patching to put things into the
46 # right place. That also means we have to not run "make install" for them.
48 # 5. In principal the various ZM_xx variables should be overridable from the
49 # config file but some of them are baked into the perl scripts, so we *have* to
50 # set them here instead of in the configuration in the NixOS module.
52 # 6. I am no PolicyKit expert but the .policy file looks fishy:
53 # a. The user needs to be known at build-time so we should probably throw
54 # upstream's policy file away and generate it from the NixOS module
55 # b. I *think* we may have to substitute the store paths with
56 # /run/current-system/sw/bin paths for it to work.
58 # 7. we manually fix up the perl paths in the scripts as fixupPhase will only
59 # handle pkexec and not perl if both are present.
61 # 8. There are several perl modules needed at runtime which are not checked when
62 # building so if a new version stops working, check if there is a missing
63 # dependency by running the failing component manually.
65 # 9. Parts of the web UI has a hardcoded /zm path so we create a symlink to work
71 path = "scripts/ZoneMinder/lib/ZoneMinder/Control/Xiaomi.pm";
73 url = "https://gist.githubusercontent.com/joshstrange/73a2f24dfaf5cd5b470024096ce2680f/raw/e964270c5cdbf95e5b7f214f7f0fc6113791530e/Xiaomi.pm";
74 sha256 = "04n1ap8fx66xfl9q9rypj48pzbgzikq0gisfsfm8wdsmflarz43v";
80 dirName = "zoneminder";
81 perlBin = "${perl}/bin/perl";
84 stdenv.mkDerivation rec {
88 src = fetchFromGitHub {
92 hash = "sha256-0mpT3qjF8zlcsd6OlNIvrabDsz+oJPPy9Vn2TQSuHAI=";
93 fetchSubmodules = true;
97 ./default-to-http-1dot1.patch
98 ./0001-Don-t-use-file-timestamp-in-cache-filename.patch
102 rm -rf web/api/lib/Cake/Test
104 ${lib.concatStringsSep "\n" (
106 cp ${e.src} ${e.path}
110 for d in scripts/ZoneMinder onvif/{modules,proxy} ; do
111 substituteInPlace $d/CMakeLists.txt \
112 --replace 'DESTDIR="''${CMAKE_CURRENT_BINARY_DIR}/output"' "PREFIX=$out INSTALLDIRS=site"
113 sed -i '/^install/d' $d/CMakeLists.txt
116 substituteInPlace misc/CMakeLists.txt \
117 --replace '"''${PC_POLKIT_PREFIX}/''${CMAKE_INSTALL_DATAROOTDIR}' "\"$out/share"
119 for f in misc/*.policy.in \
121 scripts/ZoneMinder/lib/ZoneMinder/Memory.pm.in ; do
122 substituteInPlace $f \
123 --replace '/usr/bin/perl' '${perlBin}' \
124 --replace '/bin:/usr/bin' "$out/bin:${
133 substituteInPlace scripts/zmdbbackup.in \
134 --replace /usr/bin/mysqldump ${mariadb.client}/bin/mysqldump
136 substituteInPlace scripts/zmupdate.pl.in \
137 --replace "'mysql'" "'${mariadb.client}/bin/mysql'" \
138 --replace "'mysqldump'" "'${mariadb.client}/bin/mysqldump'"
140 for f in scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in \
141 scripts/zmupdate.pl.in \
142 src/zm_config_data.h.in \
143 web/api/app/Config/bootstrap.php.in \
144 web/includes/config.php.in ; do
145 substituteInPlace $f --replace @ZM_CONFIG_SUBDIR@ /etc/zoneminder
148 for f in includes/Event.php views/image.php ; do
149 substituteInPlace web/$f \
150 --replace "'ffmpeg " "'${ffmpeg}/bin/ffmpeg "
153 for f in scripts/ZoneMinder/lib/ZoneMinder/Event.pm \
154 scripts/ZoneMinder/lib/ZoneMinder/Storage.pm ; do
155 substituteInPlace $f \
156 --replace '/bin/rm' "${coreutils}/bin/rm"
159 substituteInPlace web/includes/functions.php \
160 --replace "'date " "'${coreutils}/bin/date " \
161 --subst-var-by srcHash "`basename $out`"
180 util-linuxMinimal # for libmount
182 ++ (with perlPackages; [
183 # build-time dependencies
189 # run-time dependencies not checked at build-time
200 DataEntropy # zmupdate.pl
203 nativeBuildInputs = [
211 "-DZM_LOGDIR=/var/log/${dirName}"
212 "-DZM_RUNDIR=/run/${dirName}"
213 "-DZM_SOCKDIR=/run/${dirName}"
214 "-DZM_TMPDIR=/tmp/${dirName}"
215 "-DZM_CONFIG_DIR=${placeholder "out"}/etc/zoneminder"
216 "-DZM_WEB_USER=${user}"
217 "-DZM_WEB_GROUP=${user}"
222 tests = nixosTests.zoneminder;
226 PERL5LIB="$PERL5LIB''${PERL5LIB:+:}$out/${perl.libPrefix}"
229 for i in $(IFS=$'\n'; echo $PERL5LIB | tr ':' "\n" | sort -u); do
230 perlFlags="$perlFlags -I$i"
233 mkdir -p $out/libexec
234 for f in $out/bin/*.pl ; do
236 makeWrapper ${perlBin} $f \
237 --prefix PATH : $out/bin \
238 --add-flags "$perlFlags $out/libexec/$(basename $f)"
241 ln -s $out/share/zoneminder/www $out/share/zoneminder/www/zm
245 description = "Video surveillance software system";
246 homepage = "https://zoneminder.com";
247 license = licenses.gpl3;
249 platforms = platforms.unix;