anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / applications / networking / irc / weechat / default.nix
blob513c257c9b9faaf8f9bd63ffe3623a7e3c8b7afc
1 { stdenv, fetchurl, lib
2 , ncurses, openssl, aspell, cjson, gnutls, gettext
3 , zlib, curl, pkg-config, libgcrypt
4 , cmake, libobjc, libresolv, libiconv
5 , asciidoctor # manpages
6 , enableTests ? !stdenv.hostPlatform.isDarwin, cpputest
7 , guileSupport ? true, guile
8 , luaSupport ? true, lua5
9 , perlSupport ? true, perl
10 , pythonSupport ? true, python3Packages
11 , rubySupport ? true, ruby
12 , tclSupport ? true, tcl
13 , phpSupport ? !stdenv.hostPlatform.isDarwin, php, systemd, libxml2, pcre2, libargon2
14 , extraBuildInputs ? []
17 let
18   inherit (python3Packages) python;
19   php-embed = php.override {
20     embedSupport = true;
21     apxs2Support = false;
22   };
23   plugins = [
24     { name = "perl"; enabled = perlSupport; cmakeFlag = "ENABLE_PERL"; buildInputs = [ perl ]; }
25     { name = "tcl"; enabled = tclSupport; cmakeFlag = "ENABLE_TCL"; buildInputs = [ tcl ]; }
26     { name = "ruby"; enabled = rubySupport; cmakeFlag = "ENABLE_RUBY"; buildInputs = [ ruby ]; }
27     { name = "guile"; enabled = guileSupport; cmakeFlag = "ENABLE_GUILE"; buildInputs = [ guile ]; }
28     { name = "lua"; enabled = luaSupport; cmakeFlag = "ENABLE_LUA"; buildInputs = [ lua5 ]; }
29     { name = "python"; enabled = pythonSupport; cmakeFlag = "ENABLE_PYTHON3"; buildInputs = [ python ]; }
30     { name = "php"; enabled = phpSupport; cmakeFlag = "ENABLE_PHP"; buildInputs = [
31       php-embed.unwrapped.dev libxml2 pcre2 libargon2
32     ] ++ lib.optional stdenv.hostPlatform.isLinux systemd; }
33   ];
34   enabledPlugins = builtins.filter (p: p.enabled) plugins;
36   in
37     assert lib.all (p: p.enabled -> ! (builtins.elem null p.buildInputs)) plugins;
38     stdenv.mkDerivation rec {
39       version = "4.4.3";
40       pname = "weechat";
42       hardeningEnable = [ "pie" ];
44       src = fetchurl {
45         url = "https://weechat.org/files/src/weechat-${version}.tar.xz";
46         hash = "sha256-KVYS+NwkryjJGCV9MBTrUzQqXQd9Xj2aPq3zA72P6/o=";
47       };
49       # Why is this needed? https://github.com/weechat/weechat/issues/2031
50       patches = lib.optional gettext.gettextNeedsLdflags ./gettext-intl.patch;
52       outputs = [ "out" "man" ] ++ map (p: p.name) enabledPlugins;
54       cmakeFlags = [
55         "-DENABLE_MAN=ON"
56         "-DENABLE_DOC=ON"
57         "-DENABLE_DOC_INCOMPLETE=ON"
58         "-DENABLE_TESTS=${if enableTests then "ON" else "OFF"}"
59       ]
60         ++ lib.optionals stdenv.hostPlatform.isDarwin ["-DICONV_LIBRARY=${libiconv}/lib/libiconv.dylib"]
61         ++ map (p: "-D${p.cmakeFlag}=" + (if p.enabled then "ON" else "OFF")) plugins
62         ;
64       nativeBuildInputs = [ cmake pkg-config asciidoctor ] ++ lib.optional enableTests cpputest;
65       buildInputs = [ ncurses openssl aspell cjson gnutls gettext zlib curl libgcrypt ]
66         ++ lib.optionals stdenv.hostPlatform.isDarwin [ libobjc libresolv ]
67         ++ lib.concatMap (p: p.buildInputs) enabledPlugins
68         ++ extraBuildInputs;
70       env.NIX_CFLAGS_COMPILE = "-I${python}/include/${python.libPrefix}"
71         # Fix '_res_9_init: undefined symbol' error
72         + (lib.optionalString stdenv.hostPlatform.isDarwin "-DBIND_8_COMPAT=1 -lresolv");
74       postInstall = ''
75         for p in ${lib.concatMapStringsSep " " (p: p.name) enabledPlugins}; do
76           from=$out/lib/weechat/plugins/$p.so
77           to=''${!p}/lib/weechat/plugins/$p.so
78           mkdir -p $(dirname $to)
79           mv $from $to
80         done
81       '';
83       doInstallCheck = true;
84       installCheckPhase = ''
85         $out/bin/weechat --version
86       '';
88       meta = {
89         homepage = "https://weechat.org/";
90         changelog = "https://weechat.org/files/doc/weechat/ChangeLog-${version}.html";
91         description = "Fast, light and extensible chat client";
92         longDescription = ''
93           You can find more documentation as to how to customize this package
94           (e.g. adding python modules for scripts that would require them, etc.)
95           on https://nixos.org/nixpkgs/manual/#sec-weechat .
96         '';
97         license = lib.licenses.gpl3;
98         maintainers = with lib.maintainers; [ ncfavier ];
99         mainProgram = "weechat";
100         platforms = lib.platforms.unix;
101       };
102     }