blog.lazkani.io/content/posts/weechat-and-emacs.md

78 lines
3.2 KiB
Markdown

+++
title = "Weechat and Emacs"
author = ["Elia el Lazkani"]
date = 2020-09-03T21:00:00+02:00
lastmod = 2021-06-28T00:01:47+02:00
tags = ["weechat", "emacs", "weechat-el"]
categories = ["irc"]
draft = false
+++
In the last few blog posts, I mentioned a few migrations caused by my _VSCode_
discovery a few weeks ago [Emacs and Org-mode]({{< relref "emacs-and-org-mode" >}}).
As I was configuring _Doom_, I noticed that there was a configuration for _weechat_ in there. I checked it out very briefly and found that it was a _[weechat.el](https://github.com/the-kenny/weechat.el)_ package for _Emacs_.
<!--more-->
At the time, I didn't have too much time to spend on this so I quickly passed it over with plans to come back to it, _eventually_.
The time has come for me to configure and try this at least !
I already have my _weechat_ installation running remotely behind an _nginx_ **reverse proxy**. I tried to connecting using that endpoint, unfortunately no dice.
## The Problem {#the-problem}
As I was asking in _#weechat.el_ on **freenode** for help, the very quick to help _[FlashCode](https://github.com/flashcode)_ sprung into action. He wasn't able to help me but he pointed me in the right direction.
I asked why would _Glowing Bear_ work but not _weechat.el_ ?
The answer was along the line that _Glowing Bear_ uses a _websocket_. Alright that made sense. Maybe _weechat.el_ does not do _websocket_.
## The Solution {#the-solution}
So, we are behind an _nginx_ **reverse proxy** instance. What we need to do is expose our service as a _TCP reverse proxy_ instead of our usual _HTTP_ one. We are moving down networking layers to the **TCP/IP** instead of **HTTP**.
What we need to do is add a _stream_ section to our _nginx_ to accomplish this.
```text
stream {
server {
listen 9000 ssl;
ssl_certificate /path/to/chain.pem;
ssl_certificate_key /path/to/cert.pem;
proxy_pass 127.0.0.1:9000;
}
}
```
<div class="admonition warning">
<p class="admonition-title">warning</p>
The `stream` section has to be outside the `http` section.
If you add this configuration next to your other `server` sections, it will fail.
</div>
In the previous block we make a few assumptions.
- We are behind SSL: I use the _nginx_ reverse proxy for _SSL termination_ as it handles reloading certificates automatically. If I leave it to _weechat_, I have to reload the _certificates_ manually and often.
- Weechat is listening on port 9000 locally: The _weechat_ relay needs to be configured to listen on **localhost** and on port **9000** for this configuration to work. Make sure to change it to fit your needs.
Now that the configuration is out of the way, let's test it.
Open emacs and run `M-x` followed by `weechat-connect`. This should get you going.
## Conclusion {#conclusion}
It was a nice path down the road of packets. It's always a good day when you learn new things. I have never used _TCP_ forwarding with _nginx_ before but I'm glad it is supported.
Now that you know how to do the same as well, I hope you give both projects a try. I think they are worth it.
I'm also thankful to have so many different awesome projects created by the open source community.