Weechat: Difference between revisions

From NixOS Wiki
imported>Thornycrackers
No edit summary
imported>Oxzi
No edit summary
Line 1: Line 1:
''WeeChat'' is an extensible chat client with a command line interface.
''WeeChat'' is an extensible chat client with a command line interface.


== Plugins ==
== Scripts ==
WeeChat can be extended with plugins, which can be written in a variety of scripting languages. As these plugins may depend on external libraries, we need to take care that those are found by WeeChat. For example the [https://weechat.org/scripts/source/jabber.py.html/ Jabber plugin] depends on the <code>xmpppy</code> python library, which is provided in a separate nix package. To make WeeChat find the library, we can override the <code>weechat</code> nix package and add the dependency as an extra build input, e.g. by changing the <code>~/.nixpkgs/config.nix</code> as follows:
WeeChat can be extended with scripts. Those can be written in a variety of scripting languages. As these scripts may depend on external libraries, we need to take care that those are found by WeeChat. This can either be done by adding already packaged scripts or by extending WeeChat's extraBuildInputs.
 
=== Packaged WeeChat Scripts ===
There are multiple prepackaged <code>weechatScripts</code> in the nixpkgs. Those are Nix packages for a WeeChat script with the script's extra dependencies. The easiest way is to create an [[Overlays | overlay]].


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
self: super:
{
{
   packageOverrides = pkgs: rec {
   weechat = super.weechat.override {
     weechat = pkgs.weechat.override { extraBuildInputs = [ pkgs.xmpppy ]; };
     configure = { availablePlugins, ... }: {
      scripts = with super.weechatScripts; [
        weechat-otr
        wee-slack
      ];
    };
   };
   };
}
}
</syntaxhighlight>
</syntaxhighlight>


=== Making the wechat-otr.py plugin work===
=== WeeChat extraBuildInputs ===
For example the [https://weechat.org/scripts/source/jabber.py.html/ Jabber script] depends on the <code>xmpppy</code> python library, which is provided in a separate nix package. To make WeeChat find the library, we can override the <code>weechat</code> nix package and add the dependency as an extra build input, e.g. by changing the <code>~/.nixpkgs/config.nix</code> as follows:


As of 2018-07-14, a workaround is needed. You have to override potr to use an old, vulnerable version of pycrypto (upstream progress in fixing this issue can be found at https://github.com/python-otr/pure-python-otr/issues/68):
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
      (weechat.override {
        configure = { availablePlugins, ... }: {
          plugins = [
            (availablePlugins.python.withPackages (ps: [
              (ps.potr.overridePythonAttrs (oldAttrs:
                {
                  propagatedBuildInputs = [
                    (ps.buildPythonPackage rec {
                      name = "pycrypto-${version}";
                      version = "2.6.1";
                      src = pkgs.fetchurl {
                        url = "mirror://pypi/p/pycrypto/${name}.tar.gz";
                        sha256 = "0g0ayql5b9mkjam8hym6zyg6bv77lbh66rv1fyvgqb17kfc1xkpj";
                      };
                      patches = pkgs.stdenv.lib.singleton (pkgs.fetchpatch {
                        name = "CVE-2013-7459.patch";
                        url = "https://anonscm.debian.org/cgit/collab-maint/python-crypto.git"
                          + "/plain/debian/patches/CVE-2013-7459.patch?h=debian/2.6.1-7";
                        sha256 = "01r7aghnchc1bpxgdv58qyi2085gh34bxini973xhy3ks7fq3ir9";
                      });
                      buildInputs = [ pkgs.gmp ];
                      preConfigure = ''
                        sed -i 's,/usr/include,/no-such-dir,' configure
                        sed -i "s!,'/usr/include/'!!" setup.py
                      '';
                    })
                  ];
                }
              ))
            ]))
          ];
        };
      })
</syntaxhighlight>
An Example ~/.config/nixpkgs/overlays/weechat.nix, if you prefer single file overlays.
<syntaxhighlight lang="nix">
self: super:
{
{
   weechat = super.weechat.override {
   packageOverrides = pkgs: rec {
    configure = { availablePlugins, ... }: {
    weechat = pkgs.weechat.override { extraBuildInputs = [ pkgs.xmpppy ]; };
      plugins = [
        (availablePlugins.python.withPackages (ps: [
          (ps.potr.overridePythonAttrs (oldAttrs:
            {
              propagatedBuildInputs = [
                (ps.buildPythonPackage rec {
                  name = "pycrypto-${version}";
                  version = "2.6.1";
 
                  src = super.fetchurl {
                    url = "mirror://pypi/p/pycrypto/${name}.tar.gz";
                    sha256 = "0g0ayql5b9mkjam8hym6zyg6bv77lbh66rv1fyvgqb17kfc1xkpj";
                  };
 
                  patches = super.stdenv.lib.singleton (super.fetchpatch {
                    name = "CVE-2013-7459.patch";
                    url = "https://anonscm.debian.org/cgit/collab-maint/python-crypto.git"
                      + "/plain/debian/patches/CVE-2013-7459.patch?h=debian/2.6.1-7";
                    sha256 = "01r7aghnchc1bpxgdv58qyi2085gh34bxini973xhy3ks7fq3ir9";
                  });
 
                  buildInputs = [ super.gmp ];
 
                  preConfigure = ''
                    sed -i 's,/usr/include,/no-such-dir,' configure
                    sed -i "s!,'/usr/include/'!!" setup.py
                  '';
                })
              ];
            }
          ))
        ]))
      ] ++ (with availablePlugins; [ perl tcl ruby guile lua ]);
    };
   };
   };
}
}
</syntaxhighlight>


=== Problem loading multiline.pl ===
The script <b>multiline.pl</b> depends on the Pod::Select module. However, since perl version v5.31.1 Pod::Select has been removed. You can either install PodParser or use nix-shell to wrap weechat so it can find it:
<syntaxhighlight lang="shell">
nix-shell -p perl -p perl532Packages.PodParser --run weechat
</syntaxhighlight>
</syntaxhighlight>
This script was also packaged as <code>weechatScripts.multiline</code> and is currently available in the [https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/networking/irc/weechat/scripts/multiline/default.nix unstable release].


== Glowing Bear, nginx, TLS, and Oauth2 Proxy ==
== Glowing Bear, nginx, TLS, and Oauth2 Proxy ==
One can set up Glowing Bear as a web client to Weechat.  However, its best to proxy inbound connections from the internet through a more robust service with TLS enabled.  Lastly, it's convenient to reuse an auth provider to provide access to internal applications.  
One can set up Glowing Bear as a web client to Weechat.  However, its best to proxy inbound connections from the internet through a more robust service with TLS enabled.  Lastly, it's convenient to reuse an auth provider to provide access to internal applications.  


Line 151: Line 88:
     };
     };
}
}
</syntaxhighlight>
== Problem loading multiline.pl ==
The script <b>multiline.pl</b> depends on the Pod::Select module. However, since perl version v5.31.1 Pod::Select has been removed. You can either install PodParser or use nix-shell to wrap weechat so it can find it:
<syntaxhighlight lang="shell">
nix-shell -p perl -p perl532Packages.PodParser --run weechat
</syntaxhighlight>
</syntaxhighlight>

Revision as of 13:28, 23 February 2021

WeeChat is an extensible chat client with a command line interface.

Scripts

WeeChat can be extended with scripts. Those can be written in a variety of scripting languages. As these scripts may depend on external libraries, we need to take care that those are found by WeeChat. This can either be done by adding already packaged scripts or by extending WeeChat's extraBuildInputs.

Packaged WeeChat Scripts

There are multiple prepackaged weechatScripts in the nixpkgs. Those are Nix packages for a WeeChat script with the script's extra dependencies. The easiest way is to create an overlay.

self: super:
{
  weechat = super.weechat.override {
    configure = { availablePlugins, ... }: {
      scripts = with super.weechatScripts; [
        weechat-otr
        wee-slack
      ];
    };
  };
}

WeeChat extraBuildInputs

For example the Jabber script depends on the xmpppy python library, which is provided in a separate nix package. To make WeeChat find the library, we can override the weechat nix package and add the dependency as an extra build input, e.g. by changing the ~/.nixpkgs/config.nix as follows:

{
  packageOverrides = pkgs: rec {
    weechat = pkgs.weechat.override { extraBuildInputs = [ pkgs.xmpppy ]; };
  };
}

Problem loading multiline.pl

The script multiline.pl depends on the Pod::Select module. However, since perl version v5.31.1 Pod::Select has been removed. You can either install PodParser or use nix-shell to wrap weechat so it can find it:

nix-shell -p perl -p perl532Packages.PodParser --run weechat

This script was also packaged as weechatScripts.multiline and is currently available in the unstable release.

Glowing Bear, nginx, TLS, and Oauth2 Proxy

One can set up Glowing Bear as a web client to Weechat. However, its best to proxy inbound connections from the internet through a more robust service with TLS enabled. Lastly, it's convenient to reuse an auth provider to provide access to internal applications.

This configuration snippet can illustrate how to configure it:

{ config, pkgs, ... }:
{
  services.weechat.enable = true;

  # Go read the terms at https://letsencrypt.org/repository/
  security.acme.acceptTerms = false;
  security.acme.email = "";

  services.nginx = {
    enable = true;
    recommendedGzipSettings = true;
    recommendedOptimisation = true;
    recommendedProxySettings = true;
    recommendedTlsSettings = true;
    # You'd think this is a good idea, but Safari doesn't support 1.3 on websockets yet from my testing in 2020.  If one is only using Chrome, consider it.
    # sslProtocols = "TLSv1.3";
    virtualHosts = {
      "irc.your.fqdn.goes.here" = {
        forceSSL = true;
        enableACME = true;
        locations."^~ /weechat" = {
          proxyPass = "http://127.0.0.1:9000";
          proxyWebsockets = true;
        };
        locations."/" = {
          root = pkgs.glowing-bear;
        };
      };
    };

    services.oauth2.proxy = {
      enable = true;
      email.addresses = ''
        # your email goes here for authorization
      '';
      nginx.virtualhosts = [
        "irc.your.fqdn.goes.here"
      ];
      clientID = "";
      keyFile = "";
    };
}