weechat: 2.1 -> 2.2; improve package configuration

This aims to make the `weechat` package even more configurable. It
allows to specify scripts and commands using the `configure` function
inside a `weechat.override` expression.

The package can be configured like this:

```
with import <nixpkgs> { };
weechat.override {
  plugins = { availablePlugins, ... }: {
    plugins = builtins.attrValues availablePlugins;

    init = ''
      /set foo bar
      /server add freenode chat.freenode.org
    '';

    scripts = [ "/path/to/script.py" ];
  };
}
```

All commands are passed to `weechat --run-command "/set foo bar;/server ..."`.

The `plugins' attribute is not necessarily required anymore, if it's
sufficient to add `init' commands, the `plugins' will be
`builtins.attrValues availablePlugins' by default.

Additionally the result contains `weechat` and `weechat-headless`
(introduced in WeeChat 2.1) now.
This commit is contained in:
Maximilian Bosch 2018-09-05 17:01:45 +02:00
parent b54987715b
commit a8efe61412
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E
10 changed files with 236 additions and 40 deletions

View file

@ -671,6 +671,8 @@ overrides = super: self: rec {
plugins = with availablePlugins; [ python perl ];
}
}</programlisting>
If the <literal>configure</literal> function returns an attrset without the <literal>plugins</literal>
attribute, <literal>availablePlugins</literal> will be used automatically.
</para>
<para>
@ -704,6 +706,55 @@ overrides = super: self: rec {
}; }
</programlisting>
</para>
<para>
WeeChat allows to set defaults on startup using the <literal>--run-command</literal>.
The <literal>configure</literal> method can be used to pass commands to the program:
<programlisting>weechat.override {
configure = { availablePlugins, ... }: {
init = ''
/set foo bar
/server add freenode chat.freenode.org
'';
};
}</programlisting>
Further values can be added to the list of commands when running
<literal>weechat --run-command "your-commands"</literal>.
</para>
<para>
Additionally it's possible to specify scripts to be loaded when starting <literal>weechat</literal>.
These will be loaded before the commands from <literal>init</literal>:
<programlisting>weechat.override {
configure = { availablePlugins, ... }: {
scripts = with pkgs.weechatScripts; [
weechat-xmpp weechat-matrix-bridge wee-slack
];
init = ''
/set plugins.var.python.jabber.key "val"
'':
};
}</programlisting>
</para>
<para>
In <literal>nixpkgs</literal> there's a subpackage which contains derivations for
WeeChat scripts. Such derivations expect a <literal>passthru.scripts</literal> attribute
which contains a list of all scripts inside the store path. Furthermore all scripts
have to live in <literal>$out/share</literal>. An exemplary derivation looks like this:
<programlisting>{ stdenv, fetchurl }:
stdenv.mkDerivation {
name = "exemplary-weechat-script";
src = fetchurl {
url = "https://scripts.tld/your-scripts.tar.gz";
sha256 = "...";
};
passthru.scripts = [ "foo.py" "bar.lua" ];
installPhase = ''
mkdir $out/share
cp foo.py $out/share
cp bar.lua $out/share
'';
}</programlisting>
</para>
</section>
<section xml:id="sec-citrix">
<title>Citrix Receiver</title>

View file

@ -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);

View file

@ -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}\n${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 "${init}"
'') // {
inherit (weechat) name meta;
unwrapped = weechat;
};
in buildEnv {
name = "weechat-bin-env";
paths = [
(mkWeechat "weechat")
(mkWeechat "weechat-headless")
];
}

View file

@ -0,0 +1,11 @@
{ callPackage, luaPackages, pythonPackages }:
{
weechat-xmpp = callPackage ./weechat-xmpp {
inherit (pythonPackages) pydns;
};
weechat-matrix-bridge = callPackage ./weechat-matrix-bridge {
inherit (luaPackages) cjson;
};
}

View file

@ -25,6 +25,8 @@ stdenv.mkDerivation {
--replace "__NIX_LIB_PATH__" "$out/lib/?.so"
'';
passthru.scripts = [ "olm.lua" "matrix.lua" ];
installPhase = ''
mkdir -p $out/{share,lib}

View file

@ -25,6 +25,8 @@ stdenv.mkDerivation {
})
];
passthru.scripts = [ "jabber.py" ];
meta = with stdenv.lib; {
description = "A fork of the jabber plugin for weechat";
homepage = "https://github.com/sleduc/weechat-xmpp";

View file

@ -292,6 +292,8 @@ mapAliases ({
vimprobable2Wrapper = vimprobable2; # added 2015-01
virtviewer = virt-viewer; # added 2015-12-24
vorbisTools = vorbis-tools; # added 2016-01-26
weechat-xmpp = weechatScripts.weechat-xmpp; # added 2018-09-06
weechat-matrix-bridge = weechatScripts.weechat-matrix-bridge; # added 2018-09-06
wineStaging = wine-staging; # added 2018-01-08
winusb = woeusb; # added 2017-12-22
wireguard = wireguard-tools; # added 2018-05-19

View file

@ -19175,13 +19175,7 @@ with pkgs;
guile = guile_2_0;
};
weechat-matrix-bridge = callPackage ../applications/networking/instant-messengers/weechat-matrix-bridge {
inherit (luaPackages) cjson;
};
weechat-xmpp = callPackage ../applications/networking/instant-messengers/weechat-xmpp {
inherit (pythonPackages) pydns;
};
weechatScripts = callPackage ../applications/networking/irc/weechat/scripts { };
westonLite = weston.override {
pango = null;