1 { stdenv, lib, fetchurl, makeWrapper
2 , gawk, gnused, gnugrep, coreutils, which
4 , withMySQL ? false, zlib, mariadb-connector-c
5 , withPgSQL ? false, postgresql
6 , withSQLite ? false, sqlite
11 drivers = lib.concatStringsSep ","
13 ++ lib.optional withMySQL "mysql_drv"
14 ++ lib.optional withPgSQL "pgsql_drv"
15 ++ lib.optional withSQLite "sqlite3_drv"
16 ++ lib.optional withDB "libdb4_drv"
18 maintenancePath = lib.makeBinPath [ gawk gnused gnugrep coreutils which ];
20 in stdenv.mkDerivation rec {
25 url = "mirror://sourceforge/dspam/dspam/${pname}-${version}/${pname}-${version}.tar.gz";
26 sha256 = "1acklnxn1wvc7abn31l3qdj8q6k13s51k5gv86vka7q20jb5cxmf";
29 # https://gist.github.com/WhiteAnthrax/613136c76882e0ead3cb3bdad6b3d551
33 buildInputs = [ perlPackages.perl ]
34 ++ lib.optionals withMySQL [ zlib mariadb-connector-c.out ]
35 ++ lib.optional withPgSQL postgresql
36 ++ lib.optional withSQLite sqlite
37 ++ lib.optional withDB db;
38 nativeBuildInputs = [ makeWrapper ];
39 # patch out libmysql >= 5 check, since mariadb-connector is at 3.x
41 sed -i 's/atoi(m) >= 5/1/g' configure m4/mysql_drv.m4
45 "--with-storage-driver=${drivers}"
46 "--sysconfdir=/etc/dspam"
47 "--localstatedir=/var"
48 "--with-dspam-home=/var/lib/dspam"
49 "--with-logdir=/var/log/dspam"
50 "--with-logfile=/var/log/dspam/dspam.log"
55 "--enable-large-scale"
56 "--enable-virtual-users"
57 "--enable-split-configuration"
58 "--enable-preferences-extension"
59 "--enable-long-usernames"
60 "--enable-external-lookup"
61 ] ++ lib.optionals withMySQL [
62 "--with-mysql-includes=${mariadb-connector-c.dev}/include/mysql"
63 "--with-mysql-libraries=${mariadb-connector-c.out}/lib/mysql"
65 ++ lib.optional withPgSQL "--with-pgsql-libraries=${postgresql.lib}/lib";
67 # Workaround build failure on -fno-common toolchains like upstream
68 # gcc-10. Otherwise build fails as:
69 # ld: .libs/hash_drv.o:/build/dspam-3.10.2/src/util.h:96: multiple definition of `verified_user';
70 # .libs/libdspam.o:/build/dspam-3.10.2/src/util.h:96: first defined here
71 env.NIX_CFLAGS_COMPILE = "-fcommon";
73 # Lots of things are hardwired to paths like sysconfdir. That's why we install with both "prefix" and "DESTDIR"
74 # and fix directory structure manually after that.
75 installFlags = [ "DESTDIR=$(out)" ];
78 cp -r $out/$out/* $out
79 rm -rf $out/$(echo "$out" | cut -d "/" -f2)
82 wrapProgram $out/bin/dspam_notify \
83 --set PERL5LIB "${perlPackages.makePerlPath [ perlPackages.libnet ]}"
86 mkdir -p $out/share/dspam/sql
88 cp src/tools.mysql_drv/mysql_*.sql $out/share/dspam/sql
89 for i in src/tools.mysql_drv/{purge*.sql,virtual*.sql}; do
90 cp "$i" $out/share/dspam/sql/mysql_$(basename "$i")
93 cp src/tools.pgsql_drv/pgsql_*.sql $out/share/dspam/sql
94 for i in src/tools.pgsql_drv/{purge*.sql,virtual*.sql}; do
95 cp "$i" $out/share/dspam/sql/pgsql_$(basename "$i")
98 for i in src/tools.sqlite_drv/purge*.sql; do
99 cp "$i" $out/share/dspam/sql/sqlite_$(basename "$i")
102 # Install maintenance script
103 install -Dm755 contrib/dspam_maintenance/dspam_maintenance.sh $out/bin/dspam_maintenance
105 -e "2iexport PATH=$out/bin:${maintenancePath}:\$PATH" \
106 -e 's,/usr/[a-z0-9/]*,,g' \
107 -e 's,^DSPAM_CONFIGDIR=.*,DSPAM_CONFIGDIR=/etc/dspam,' \
108 -e "s,^DSPAM_HOMEDIR=.*,DSPAM_HOMEDIR=/var/lib/dspam," \
109 -e "s,^DSPAM_PURGE_SCRIPT_DIR=.*,DSPAM_PURGE_SCRIPT_DIR=$out/share/dspam/sql," \
110 -e "s,^DSPAM_BIN_DIR=.*,DSPAM_BIN_DIR=$out/bin," \
111 -e "s,^MYSQL_BIN_DIR=.*,MYSQL_BIN_DIR=/run/current-system/sw/bin," \
112 -e "s,^PGSQL_BIN_DIR=.*,PGSQL_BIN_DIR=/run/current-system/sw/bin," \
113 -e "s,^SQLITE_BIN_DIR=.*,SQLITE_BIN_DIR=/run/current-system/sw/bin," \
114 -e "s,^SQLITE3_BIN_DIR=.*,SQLITE3_BIN_DIR=/run/current-system/sw/bin," \
115 -e 's,^DSPAM_CRON_LOCKFILE=.*,DSPAM_CRON_LOCKFILE=/run/dspam/dspam_maintenance.pid,' \
116 $out/bin/dspam_maintenance
120 homepage = "https://dspam.sourceforge.net/";
121 description = "Community Driven Antispam Filter";
122 license = licenses.agpl3Plus;
123 platforms = platforms.linux;
124 maintainers = with maintainers; [ abbradar ];