First of all hello to the forum. I'd like to post about a Weechat setup as I saw users asking about it. Weechat can be used for chats on the decentralized Matrix network. There is weechat-python and also a python plugin for Weechat called weechat-matrix (btw. there are also a lua and a newly developed rust plugins), which lets Weechat communicate over the Matrix protocol.
It requires Olm (an implementation of the Double Ratchet cryptographic ratchet) for encryption. Luckily there is an Olm package available on OpenBSD 6.8. weechat-matrix can be built from source using python-olm 3.1.4 from ports (6.7). Some time ago I found a guide for this configuration, which I just updated for 6.8. If there is an easier way to achieve the same config (apart from using gomuks, the terminal based matrix client) or some steps could be improved, comments are welcome.
- First install the weechat and olm packages:
doas pkg_add weechat weechat-python olm
- weechat-matrix will be built from source. Python 3.8 should be installed.
Check PYTHONPATH.
/usr/local/lib/python3.8/site-packages and ~/.local/bin should be set.
You can check it by running:
$PYTHONPATH
It can be set in ~/.xsession:
export PYTHONPATH=/usr/local/lib/python3.8/site-packages:/home/USERNAME/.local/bin
If it's just set, reboot (logout/login might work too).
- When building weechat-matrix, python-olm is required.
python-olm can be built from the OpenBSD olm-3.1.4 package. First download olm-3.1.4.tar.gz for your architecture from the OpenBSD 6.7 ports. Extract the package to where it is supposed to be built:
tar -zxvf olm-3.1.4.tar.gz
cd olm-3.1.4
cd python
(- pycparser might be needed
python3 -m pip install --user pycparser
It's better NOT to install python-related modules as root. That will mess up the filesystem checksums.)
-Run:
gmake olm-python3
python-olm will be installed to olm-3.1.4/python/usr/local/lib/python3.8/site-packages
Copy the content of this directory to ~/.local/lib/python3.8/site-packages
- As we have python-olm available, we can install weechat-matrix from source:
git clone https://github.com/poljar/weechat-matrix.git
cd weechat-matrix
(- more-itertools might be needed:
python3 -m pip install --user more-itertools
Again: DON'T install python modules as root)
First install the requirements:
python3 -m pip install --user -r requirements.txt
There is an issue with the MAKEFILE on OpenBSD as it has been changed
(the new one has wrong syntax for OpenBSD). Here is the older version, which works fine:
.PHONY: install install-lib install-dir uninstall phony test typecheck
WEECHAT_HOME ?= $(HOME)/.weechat
PREFIX ?= $(WEECHAT_HOME)
PYTHON ?= python
lib := $(patsubst matrix/%.py, $(DESTDIR)$(PREFIX)/python/matrix/%.py, \
$(wildcard matrix/*.py))
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
install: install-dir install-lib ## Install the plugin to $(DESTDIR)/$(PREFIX)
install -m644 main.py $(DESTDIR)$(PREFIX)/python/matrix.py
install-lib: $(lib)
install-dir:
install -d $(DESTDIR)$(PREFIX)/python/matrix
uninstall: ## Uninstall the plugin from $(PREFIX)
rm $(DESTDIR)$(PREFIX)/python/matrix.py $(DESTDIR)$(PREFIX)/python/matrix/*
rmdir $(DESTDIR)$(PREFIX)/python/matrix
phony:
$(DESTDIR)$(PREFIX)/python/matrix/%.py: matrix/%.py phony
install -m644 $< $@
test: ## Run automated tests
python3 -m pytest
python2 -m pytest
typecheck: ## Run type check
mypy -p matrix --ignore-missing-imports --warn-redundant-casts
After the older version of the MAKEFILE is in place, run (without doas):
make install
There should be matrix.py installed in ~/.weechat/python.
Check the ~/.weechat/python/matrix folder and if it is empty as expected, copy over the content from the weechat-matrix/matrix folder.
- We have the python plugin installed. Start weechat:
weechat
Configure the plugin:
/script load matrix.py
/set matrix.server.matrix_org.username johndoe
/set matrix.server.matrix_org.password jd_is_awesome
/matrix connect matrix_org
VII. This is how encrypted passwords can be configured:
https://weechat.org/files/doc/devel/weechat_user.en.html#secured_data
There are different features of Weechat available. E.g. alt+arrows is for moving around, pg-up/down is for scrolling and the command /buffer merge 2 3 gets the messages from to rooms into one window (ctrl+x is for switching, /buffer unmerge to stop it).
Addendum: As I mentioned above, it's not a good idea to install python modules systemwide with pip as root. It will mess up the checksums of the installed files. Check:
doas pkg_check -vvvvv
If there is an output like:
checksum for /usr/local/lib/python2.7/email/mime/init.pyc does not match
After delete:
doas rm -rv /usr/local/lib/python2.7/email/mime/init.pyc
(Actually it's not necessary to delete it as a re-install would rename it, but it's better to avoid the clutter.)
doas pkg_check -vvvvv will complain:
--- python-2.7.18p0 -------------------
/usr/local/lib/python2.7/email/mime/init.pyc should exist
/usr/local/lib/python2.7/email/mime/init.pyc is not a file
can't read /usr/local/lib/python2.7/email/mime/init.pyc
In order to fix this, reinstall:
doas pkg_add -u -D checksum -D installed python-2.7.18p0
Now pkg_check should be fine:
doas pkg_check -vvvvv
Project status of weechat-matrix (python):
weechat-matrix is stable and quite usable as a daily driver. It already supports large parts of the Matrix protocol, including end-to-end encryption (though some features like cross-signing and session unwedging are unimplemented). However, due to some inherent limitations of Weechat scripts, development has moved to weechat-matrix-rs, a Weechat plugin written in Rust. As such, weechat-matrix is in maintenance mode and will likely not be receiving substantial new features.