summary refs log tree commit diff
path: root/pkgs/applications/networking/irc/weechat
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/applications/networking/irc/weechat')
-rw-r--r--pkgs/applications/networking/irc/weechat/aggregate-commands.patch110
-rw-r--r--pkgs/applications/networking/irc/weechat/default.nix90
-rw-r--r--pkgs/applications/networking/irc/weechat/scripts/default.nix13
-rw-r--r--pkgs/applications/networking/irc/weechat/scripts/wee-slack/default.nix29
-rw-r--r--pkgs/applications/networking/irc/weechat/scripts/weechat-matrix-bridge/default.nix46
-rw-r--r--pkgs/applications/networking/irc/weechat/scripts/weechat-matrix-bridge/library-path.patch28
-rw-r--r--pkgs/applications/networking/irc/weechat/scripts/weechat-xmpp/default.nix36
-rw-r--r--pkgs/applications/networking/irc/weechat/scripts/weechat-xmpp/libpath.patch16
8 files changed, 335 insertions, 33 deletions
diff --git a/pkgs/applications/networking/irc/weechat/aggregate-commands.patch b/pkgs/applications/networking/irc/weechat/aggregate-commands.patch
new file mode 100644
index 000000000000..41e3c54a2d57
--- /dev/null
+++ b/pkgs/applications/networking/irc/weechat/aggregate-commands.patch
@@ -0,0 +1,110 @@
+diff --git a/src/core/wee-command.c b/src/core/wee-command.c
+index 91c3c068d..8105e4171 100644
+--- a/src/core/wee-command.c
++++ b/src/core/wee-command.c
+@@ -8345,10 +8345,20 @@ command_exec_list (const char *command_list)
+ void
+ command_startup (int plugins_loaded)
+ {
++    int i;
++
+     if (plugins_loaded)
+     {
+         command_exec_list (CONFIG_STRING(config_startup_command_after_plugins));
+-        command_exec_list (weechat_startup_commands);
++        if (weechat_startup_commands)
++        {
++            for (i = 0; i < weelist_size (weechat_startup_commands); i++)
++            {
++                command_exec_list (
++                    weelist_string (
++                        weelist_get (weechat_startup_commands, i)));
++            }
++        }
+     }
+     else
+         command_exec_list (CONFIG_STRING(config_startup_command_before_plugins));
+diff --git a/src/core/weechat.c b/src/core/weechat.c
+index f74598ad5..ff2e539d1 100644
+--- a/src/core/weechat.c
++++ b/src/core/weechat.c
+@@ -60,6 +60,7 @@
+ #include "wee-eval.h"
+ #include "wee-hdata.h"
+ #include "wee-hook.h"
++#include "wee-list.h"
+ #include "wee-log.h"
+ #include "wee-network.h"
+ #include "wee-proxy.h"
+@@ -102,7 +103,8 @@ int weechat_no_gnutls = 0;             /* remove init/deinit of gnutls      */
+                                        /* (useful with valgrind/electric-f.)*/
+ int weechat_no_gcrypt = 0;             /* remove init/deinit of gcrypt      */
+                                        /* (useful with valgrind)            */
+-char *weechat_startup_commands = NULL; /* startup commands (-r flag)        */
++struct t_weelist *weechat_startup_commands = NULL; /* startup commands      */
++                                                   /* (option -r)           */
+ 
+ 
+ /*
+@@ -152,9 +154,13 @@ weechat_display_usage ()
+           "  -h, --help               display this help\n"
+           "  -l, --license            display WeeChat license\n"
+           "  -p, --no-plugin          don't load any plugin at startup\n"
+-          "  -r, --run-command <cmd>  run command(s) after startup\n"
+-          "                           (many commands can be separated by "
+-          "semicolons)\n"
++          "  -P, --plugins <plugins>  load only these plugins at startup\n"
++          "                           (see /help weechat.plugin.autoload)\n"
++          "  -r, --run-command <cmd>  run command(s) after startup;\n"
++          "                           many commands can be separated by "
++          "semicolons,\n"
++          "                           this option can be given multiple "
++          "times\n"
+           "  -s, --no-script          don't load any script at startup\n"
+           "      --upgrade            upgrade WeeChat using session files "
+           "(see /help upgrade in WeeChat)\n"
+@@ -276,9 +282,10 @@ weechat_parse_args (int argc, char *argv[])
+         {
+             if (i + 1 < argc)
+             {
+-                if (weechat_startup_commands)
+-                    free (weechat_startup_commands);
+-                weechat_startup_commands = strdup (argv[++i]);
++                if (!weechat_startup_commands)
++                    weechat_startup_commands = weelist_new ();
++                weelist_add (weechat_startup_commands, argv[++i],
++                             WEECHAT_LIST_POS_END, NULL);
+             }
+             else
+             {
+@@ -616,6 +623,8 @@ weechat_shutdown (int return_code, int crash)
+         free (weechat_home);
+     if (weechat_local_charset)
+         free (weechat_local_charset);
++    if (weechat_startup_commands)
++        weelist_free (weechat_startup_commands);
+ 
+     if (crash)
+         abort ();
+diff --git a/src/core/weechat.h b/src/core/weechat.h
+index 9420ff415..cbb565a03 100644
+--- a/src/core/weechat.h
++++ b/src/core/weechat.h
+@@ -96,6 +96,8 @@
+ /* name of environment variable with an extra lib dir */
+ #define WEECHAT_EXTRA_LIBDIR "WEECHAT_EXTRA_LIBDIR"
+ 
++struct t_weelist;
++
+ /* global variables and functions */
+ extern int weechat_headless;
+ extern int weechat_debug_core;
+@@ -112,7 +114,7 @@ extern char *weechat_local_charset;
+ extern int weechat_plugin_no_dlclose;
+ extern int weechat_no_gnutls;
+ extern int weechat_no_gcrypt;
+-extern char *weechat_startup_commands;
++extern struct t_weelist *weechat_startup_commands;
+ 
+ extern void weechat_term_check ();
+ extern void weechat_shutdown (int return_code, int crash);
diff --git a/pkgs/applications/networking/irc/weechat/default.nix b/pkgs/applications/networking/irc/weechat/default.nix
index 16162435e09a..a9de275559db 100644
--- a/pkgs/applications/networking/irc/weechat/default.nix
+++ b/pkgs/applications/networking/irc/weechat/default.nix
@@ -12,7 +12,8 @@
 , tclSupport ? true, tcl
 , extraBuildInputs ? []
 , configure ? { availablePlugins, ... }: { plugins = builtins.attrValues availablePlugins; }
-, runCommand }:
+, runCommand, buildEnv
+}:
 
 let
   inherit (pythonPackages) python;
@@ -29,12 +30,12 @@ let
   weechat =
     assert lib.all (p: p.enabled -> ! (builtins.elem null p.buildInputs)) plugins;
     stdenv.mkDerivation rec {
-      version = "2.1";
+      version = "2.2";
       name = "weechat-${version}";
 
       src = fetchurl {
         url = "http://weechat.org/files/src/weechat-${version}.tar.bz2";
-        sha256 = "0fq68wgynv2c3319gmzi0lz4ln4yrrk755y5mbrlr7fc1sx7ffd8";
+        sha256 = "0p4nhh7f7w4q77g7jm9i6fynndqlgjkc9dk5g1xb4gf9imiisqlg";
       };
 
       outputs = [ "out" "man" ] ++ map (p: p.name) enabledPlugins;
@@ -69,6 +70,13 @@ let
         done
       '';
 
+      # remove when bumping to the latest version.
+      # This patch basically rebases `fcf7469d7664f37e94d5f6d0b3fe6fce6413f88c`
+      # from weechat upstream to weechat-2.2.
+      patches = [
+        ./aggregate-commands.patch
+      ];
+
       meta = {
         homepage = http://www.weechat.org/;
         description = "A fast, light and extensible chat client";
@@ -78,38 +86,38 @@ let
           on https://nixos.org/nixpkgs/manual/#sec-weechat .
         '';
         license = stdenv.lib.licenses.gpl3;
-        maintainers = with stdenv.lib.maintainers; [ lovek323 garbas the-kenny lheckemann ];
+        maintainers = with stdenv.lib.maintainers; [ lovek323 garbas the-kenny lheckemann ma27 ];
         platforms = stdenv.lib.platforms.unix;
       };
     };
 in if configure == null then weechat else
   let
     perlInterpreter = perl;
-    config = configure {
-      availablePlugins = let
-          simplePlugin = name: {pluginFile = "${weechat.${name}}/lib/weechat/plugins/${name}.so";};
-        in rec {
-          python = {
-            pluginFile = "${weechat.python}/lib/weechat/plugins/python.so";
-            withPackages = pkgsFun: (python // {
-              extraEnv = ''
-                export PYTHONHOME="${pythonPackages.python.withPackages pkgsFun}"
-              '';
-            });
-          };
-          perl = (simplePlugin "perl") // {
+    availablePlugins = let
+        simplePlugin = name: {pluginFile = "${weechat.${name}}/lib/weechat/plugins/${name}.so";};
+      in rec {
+        python = {
+          pluginFile = "${weechat.python}/lib/weechat/plugins/python.so";
+          withPackages = pkgsFun: (python // {
             extraEnv = ''
-              export PATH="${perlInterpreter}/bin:$PATH"
+              export PYTHONHOME="${pythonPackages.python.withPackages pkgsFun}"
             '';
-          };
-          tcl = simplePlugin "tcl";
-          ruby = simplePlugin "ruby";
-          guile = simplePlugin "guile";
-          lua = simplePlugin "lua";
+          });
+        };
+        perl = (simplePlugin "perl") // {
+          extraEnv = ''
+            export PATH="${perlInterpreter}/bin:$PATH"
+          '';
         };
+        tcl = simplePlugin "tcl";
+        ruby = simplePlugin "ruby";
+        guile = simplePlugin "guile";
+        lua = simplePlugin "lua";
       };
 
-    inherit (config) plugins;
+    config = configure { inherit availablePlugins; };
+
+    plugins = config.plugins or (builtins.attrValues availablePlugins);
 
     pluginsDir = runCommand "weechat-plugins" {} ''
       mkdir -p $out/plugins
@@ -117,13 +125,29 @@ in if configure == null then weechat else
         ln -s $plugin $out/plugins
       done
     '';
-  in (writeScriptBin "weechat" ''
-    #!${stdenv.shell}
-    export WEECHAT_EXTRA_LIBDIR=${pluginsDir}
-    ${lib.concatMapStringsSep "\n" (p: lib.optionalString (p ? extraEnv) p.extraEnv) plugins}
-    exec ${weechat}/bin/weechat "$@"
-  '') // {
-    name = weechat.name;
-    unwrapped = weechat;
-    meta = weechat.meta;
+
+    init = let
+      init = builtins.replaceStrings [ "\n" ] [ ";" ] (config.init or "");
+
+      mkScript = drv: lib.flip map drv.scripts (script: "/script load ${drv}/share/${script}");
+
+      scripts = builtins.concatStringsSep ";" (lib.foldl (scripts: drv: scripts ++ mkScript drv)
+        [ ] (config.scripts or []));
+    in "${scripts};${init}";
+
+    mkWeechat = bin: (writeScriptBin bin ''
+      #!${stdenv.shell}
+      export WEECHAT_EXTRA_LIBDIR=${pluginsDir}
+      ${lib.concatMapStringsSep "\n" (p: lib.optionalString (p ? extraEnv) p.extraEnv) plugins}
+      exec ${weechat}/bin/${bin} "$@" --run-command ${lib.escapeShellArg init}
+    '') // {
+      inherit (weechat) name meta;
+      unwrapped = weechat;
+    };
+  in buildEnv {
+    name = "weechat-bin-env";
+    paths = [
+      (mkWeechat "weechat")
+      (mkWeechat "weechat-headless")
+    ];
   }
diff --git a/pkgs/applications/networking/irc/weechat/scripts/default.nix b/pkgs/applications/networking/irc/weechat/scripts/default.nix
new file mode 100644
index 000000000000..21038a2fa966
--- /dev/null
+++ b/pkgs/applications/networking/irc/weechat/scripts/default.nix
@@ -0,0 +1,13 @@
+{ callPackage, luaPackages, pythonPackages }:
+
+{
+  weechat-xmpp = callPackage ./weechat-xmpp {
+    inherit (pythonPackages) pydns;
+  };
+
+  weechat-matrix-bridge = callPackage ./weechat-matrix-bridge {
+    inherit (luaPackages) cjson;
+  };
+
+  wee-slack = callPackage ./wee-slack { };
+}
diff --git a/pkgs/applications/networking/irc/weechat/scripts/wee-slack/default.nix b/pkgs/applications/networking/irc/weechat/scripts/wee-slack/default.nix
new file mode 100644
index 000000000000..1b6e52157449
--- /dev/null
+++ b/pkgs/applications/networking/irc/weechat/scripts/wee-slack/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "wee-slack-${version}";
+  version = "2.1.1";
+
+  src = fetchFromGitHub {
+    repo = "wee-slack";
+    owner = "wee-slack";
+    rev = "v${version}";
+    sha256 = "05caackz645aw6kljmiihiy7xz9jld8b9blwpmh0cnaihavgj1wc";
+  };
+
+  passthru.scripts = [ "wee_slack.py" ];
+
+  installPhase = ''
+    mkdir -p $out/share
+    cp wee_slack.py $out/share/wee_slack.py
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/wee-slack/wee-slack;
+    license = licenses.mit;
+    maintainers = with maintainers; [ ma27 ];
+    description = ''
+      A WeeChat plugin for Slack.com. Synchronizes read markers, provides typing notification, search, etc..
+    '';
+  };
+}
diff --git a/pkgs/applications/networking/irc/weechat/scripts/weechat-matrix-bridge/default.nix b/pkgs/applications/networking/irc/weechat/scripts/weechat-matrix-bridge/default.nix
new file mode 100644
index 000000000000..1018e46ec625
--- /dev/null
+++ b/pkgs/applications/networking/irc/weechat/scripts/weechat-matrix-bridge/default.nix
@@ -0,0 +1,46 @@
+{ stdenv, curl, fetchFromGitHub, cjson, olm, luaffi }:
+
+stdenv.mkDerivation {
+  name = "weechat-matrix-bridge-2018-05-29";
+  src = fetchFromGitHub {
+    owner = "torhve";
+    repo = "weechat-matrix-protocol-script";
+    rev = "ace3fefc0e35a627f8a528032df2e3111e41eb1b";
+    sha256 = "1snf8vn5n9wzrnqnvdrcli4199s5p114jbjlgrj5c27i53173wqw";
+  };
+
+  patches = [
+    ./library-path.patch
+  ];
+
+  buildInputs = [ curl cjson olm luaffi ];
+
+  postPatch = ''
+    substituteInPlace matrix.lua \
+      --replace "/usr/bin/curl" "${curl}/bin/curl" \
+      --replace "__NIX_LIB_PATH__" "$out/lib/?.so" \
+      --replace "__NIX_OLM_PATH__" "$out/share/?.lua"
+
+    substituteInPlace olm.lua \
+      --replace "__NIX_LIB_PATH__" "$out/lib/?.so"
+  '';
+
+  passthru.scripts = [ "olm.lua" "matrix.lua" ];
+
+  installPhase = ''
+    mkdir -p $out/{share,lib}
+
+    cp {matrix.lua,olm.lua} $out/share
+    cp ${cjson}/lib/lua/5.2/cjson.so $out/lib/cjson.so
+    cp ${olm}/lib/libolm.so $out/lib/libolm.so
+    cp ${luaffi}/lib/ffi.so $out/lib/ffi.so
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A WeeChat script in Lua that implements the matrix.org chat protocol";
+    homepage = https://github.com/torhve/weechat-matrix-protocol-script;
+    maintainers = with maintainers; [ ma27 ];
+    license = licenses.mit; # see https://github.com/torhve/weechat-matrix-protocol-script/blob/0052e7275ae149dc5241226391c9b1889ecc3c6b/matrix.lua#L53
+    platforms = platforms.unix;
+  };
+}
diff --git a/pkgs/applications/networking/irc/weechat/scripts/weechat-matrix-bridge/library-path.patch b/pkgs/applications/networking/irc/weechat/scripts/weechat-matrix-bridge/library-path.patch
new file mode 100644
index 000000000000..d9945c2993b7
--- /dev/null
+++ b/pkgs/applications/networking/irc/weechat/scripts/weechat-matrix-bridge/library-path.patch
@@ -0,0 +1,28 @@
+diff --git a/matrix.lua b/matrix.lua
+index b79f500..32b37a2 100644
+--- a/matrix.lua
++++ b/matrix.lua
+@@ -43,6 +43,9 @@ This script maps this as follows:
+ 
+ ]]
+ 
++package.cpath = package.cpath .. ";__NIX_LIB_PATH__"
++package.path = package.path .. ";__NIX_OLM_PATH__"
++
+ local json = require 'cjson' -- apt-get install lua-cjson
+ local olmstatus, olm = pcall(require, 'olm') -- LuaJIT olm FFI binding ln -s ~/olm/olm.lua /usr/local/share/lua/5.1
+ local w = weechat
+diff --git a/olm.lua b/olm.lua
+index 114649c..4828371 100644
+--- a/olm.lua
++++ b/olm.lua
+@@ -17,6 +17,9 @@
+  * limitations under the License.
+  */
+ --]]
++
++package.cpath = package.cpath .. ";__NIX_LIB_PATH__"
++
+ local ffi = require'ffi'
+ 
+ ffi.cdef[[
diff --git a/pkgs/applications/networking/irc/weechat/scripts/weechat-xmpp/default.nix b/pkgs/applications/networking/irc/weechat/scripts/weechat-xmpp/default.nix
new file mode 100644
index 000000000000..dad5b9c5e02a
--- /dev/null
+++ b/pkgs/applications/networking/irc/weechat/scripts/weechat-xmpp/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, fetchFromGitHub, xmpppy, pydns, substituteAll, buildEnv }:
+
+stdenv.mkDerivation {
+  name = "weechat-jabber-2017-08-30";
+
+  src = fetchFromGitHub {
+    repo = "weechat-xmpp";
+    owner = "sleduc";
+    sha256 = "0s02xs0ynld9cxxzj07al364sfglyc5ir1i82133mq0s8cpphnxv";
+    rev = "8f6c21f5a160c9318c7a2d8fd5dcac7ab2e0d843";
+  };
+
+  installPhase = ''
+    mkdir -p $out/share
+    cp jabber.py $out/share/jabber.py
+  '';
+
+  patches = [
+    (substituteAll {
+      src = ./libpath.patch;
+      env = "${buildEnv {
+        name = "weechat-xmpp-env";
+        paths = [ pydns xmpppy ];
+      }}/lib/python2.7/site-packages";
+    })
+  ];
+
+  passthru.scripts = [ "jabber.py" ];
+
+  meta = with stdenv.lib; {
+    description = "A fork of the jabber plugin for weechat";
+    homepage = "https://github.com/sleduc/weechat-xmpp";
+    maintainers = with maintainers; [ ma27 ];
+    license = licenses.gpl3Plus;
+  };
+}
diff --git a/pkgs/applications/networking/irc/weechat/scripts/weechat-xmpp/libpath.patch b/pkgs/applications/networking/irc/weechat/scripts/weechat-xmpp/libpath.patch
new file mode 100644
index 000000000000..372c83944a27
--- /dev/null
+++ b/pkgs/applications/networking/irc/weechat/scripts/weechat-xmpp/libpath.patch
@@ -0,0 +1,16 @@
+diff --git a/jabber.py b/jabber.py
+index 27006a3..e53c2c0 100644
+--- a/jabber.py
++++ b/jabber.py
+@@ -95,6 +95,11 @@ SCRIPT_COMMAND = SCRIPT_NAME
+ import re
+ import warnings
+ 
++import sys
++
++sys.path.append('@env@')
++
++
+ import_ok = True
+ 
+ try: