vifm: 0.13 -> 0.14 (#380559)
[NixPkgs.git] / pkgs / by-name / zo / zoneminder / package.nix
blobf58c5e7de804a8eb4b9be727fae1b06de2d5dcb6
2   stdenv,
3   lib,
4   fetchFromGitHub,
5   fetchurl,
6   cmake,
7   makeWrapper,
8   pkg-config,
9   curl,
10   ffmpeg,
11   glib,
12   libjpeg,
13   libselinux,
14   libsepol,
15   mp4v2,
16   libmysqlclient,
17   mariadb,
18   pcre,
19   perl,
20   perlPackages,
21   polkit,
22   util-linuxMinimal,
23   x264,
24   zlib,
25   coreutils,
26   procps,
27   psmisc,
28   nixosTests,
31 # NOTES:
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
39 # install.
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
66 # around it.
68 let
69   addons = [
70     {
71       path = "scripts/ZoneMinder/lib/ZoneMinder/Control/Xiaomi.pm";
72       src = fetchurl {
73         url = "https://gist.githubusercontent.com/joshstrange/73a2f24dfaf5cd5b470024096ce2680f/raw/e964270c5cdbf95e5b7f214f7f0fc6113791530e/Xiaomi.pm";
74         sha256 = "04n1ap8fx66xfl9q9rypj48pzbgzikq0gisfsfm8wdsmflarz43v";
75       };
76     }
77   ];
79   user = "zoneminder";
80   dirName = "zoneminder";
81   perlBin = "${perl}/bin/perl";
84 stdenv.mkDerivation rec {
85   pname = "zoneminder";
86   version = "1.36.35";
88   src = fetchFromGitHub {
89     owner = "ZoneMinder";
90     repo = "zoneminder";
91     rev = version;
92     hash = "sha256-0mpT3qjF8zlcsd6OlNIvrabDsz+oJPPy9Vn2TQSuHAI=";
93     fetchSubmodules = true;
94   };
96   patches = [
97     ./default-to-http-1dot1.patch
98     ./0001-Don-t-use-file-timestamp-in-cache-filename.patch
99   ];
101   postPatch = ''
102     rm -rf web/api/lib/Cake/Test
104     ${lib.concatStringsSep "\n" (
105       map (e: ''
106         cp ${e.src} ${e.path}
107       '') addons
108     )}
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
114     done
116     substituteInPlace misc/CMakeLists.txt \
117       --replace '"''${PC_POLKIT_PREFIX}/''${CMAKE_INSTALL_DATAROOTDIR}' "\"$out/share"
119     for f in misc/*.policy.in \
120              scripts/*.pl* \
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:${
125           lib.makeBinPath [
126             coreutils
127             procps
128             psmisc
129           ]
130         }"
131     done
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
146     done
148     for f in includes/Event.php views/image.php ; do
149       substituteInPlace web/$f \
150         --replace "'ffmpeg " "'${ffmpeg}/bin/ffmpeg "
151     done
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"
157     done
159     substituteInPlace web/includes/functions.php \
160       --replace "'date " "'${coreutils}/bin/date " \
161       --subst-var-by srcHash "`basename $out`"
162   '';
164   buildInputs =
165     [
166       curl
167       ffmpeg
168       glib
169       libjpeg
170       libselinux
171       libsepol
172       mp4v2
173       libmysqlclient
174       mariadb
175       pcre
176       perl
177       polkit
178       x264
179       zlib
180       util-linuxMinimal # for libmount
181     ]
182     ++ (with perlPackages; [
183       # build-time dependencies
184       DateManip
185       DBI
186       DBDmysql
187       LWP
188       SysMmap
189       # run-time dependencies not checked at build-time
190       ClassStdFast
191       DataDump
192       DeviceSerialPort
193       JSONMaybeXS
194       LWPProtocolHttps
195       NumberBytesHuman
196       SysCPU
197       SysMemInfo
198       TimeDate
199       CryptEksblowfish
200       DataEntropy # zmupdate.pl
201     ]);
203   nativeBuildInputs = [
204     cmake
205     makeWrapper
206     pkg-config
207   ];
209   cmakeFlags = [
210     "-DWITH_SYSTEMD=ON"
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}"
218   ];
220   passthru = {
221     inherit dirName;
222     tests = nixosTests.zoneminder;
223   };
225   postInstall = ''
226     PERL5LIB="$PERL5LIB''${PERL5LIB:+:}$out/${perl.libPrefix}"
228     perlFlags="-wT"
229     for i in $(IFS=$'\n'; echo $PERL5LIB | tr ':' "\n" | sort -u); do
230       perlFlags="$perlFlags -I$i"
231     done
233     mkdir -p $out/libexec
234     for f in $out/bin/*.pl ; do
235       mv $f $out/libexec/
236       makeWrapper ${perlBin} $f \
237         --prefix PATH : $out/bin \
238         --add-flags "$perlFlags $out/libexec/$(basename $f)"
239     done
241     ln -s $out/share/zoneminder/www $out/share/zoneminder/www/zm
242   '';
244   meta = with lib; {
245     description = "Video surveillance software system";
246     homepage = "https://zoneminder.com";
247     license = licenses.gpl3;
248     maintainers = [ ];
249     platforms = platforms.unix;
250   };