in emacs

Connecting to IRC with GNU Emacs and ERC.

⚠️ Update October 2025: Freenode ceased to exist in 2021 after a hostile takeover of the network (announcement from the original staff). The free software community migrated en masse to Libera.Chat, a new network founded by the original Freenode staff. This article has been updated to reflect the modern configuration.

Current IRC networks for FLOSS:

  • Libera.Chat – Official replacement for Freenode for free software projects (official announcement)
  • OFTC – Official network of Debian and other projects

References about the migration:

GNU Emacs comes with the ERC package built in, so we can connect to IRC.

In this article we publish how to automate the process of connecting to the Freenode Libera.Chat and OFTC networks, authenticating our nick with NickServ, and joining the channels we define.

In turn, for more security, the keys will be encrypted with GPG.

It is assumed beforehand that:

  • GPG has been configured on the system
  • The users have been registered with the respective NickServ of each IRC server

1. Create the .authinfo file

machine irc.freenode.net login **** password ****

machine irc.libera.chat login **** password ****
machine irc.oftc.net login **** password ****

Note: we omit the real values of the nick and the password.

2. Encrypt the .authinfo file

From Emacs:

M-x epa-encrypt-file

We select .authinfo

This will create the .authinfo.gpg file

Note 1: The module that makes this possible is called EasyPG. Note 2: From now on, we can delete .authinfo. Every time Emacs opens the .authinfo.gpg file it will decrypt it automatically so that it can be edited, and it will encrypt it when saving.

3. Automate the connection to the ERC servers

📁 Where should this configuration go?

Doom Emacs: Add the code in ~/.doom.d/config.el Then run: doom sync and restart Emacs

Spacemacs: Add the code in ~/.spacemacs inside the dotspacemacs/user-config function

Vanilla Emacs (no distribution): Add the code in ~/.emacs or ~/.emacs.d/init.el

use-package (recommended for modular configuration): Create a separate file like ~/.emacs.d/lisp/setup-erc.el and load it from your init.el with: (load "~/.emacs.d/lisp/setup-erc.el")

Basic Configuration

;; Lectura de las claves encriptadas en .authinfo.gpg
(setq auth-sources
      '((:source "~/.authinfo.gpg")))

(setq erc-autojoin-timing 'ident)
(setq erc-prompt-for-nickserv-password nil)

Automatic joining of the channels of each IRC server

(setq erc-autojoin-channels-alist
      '(("freenode.net" "#emacs-es" "#debian" "#nethack"
         "libera.chat" "#emacs-es" "#debian" "#nethack" "#emacs" "#guix" "#lisp")
        ("oftc.net" "#debian-next" "#oftc"
                    "#debian-mentors"      ; Para aspirantes Debian Maintainer
                    "#debian-devel"        ; Desarrollo general Debian
                    "#debian-multimedia"   ; Paquetes multimedia
                    "#debian-qa"           ; Quality Assurance
                    "#debian-es")))        ; Comunidad Debian española

Identifying with each server

Change the nick value appropriately in each case.

(erc-tls :server "irc.freenode.net" :port 6697 :nick "****")
(erc-tls :server "irc.libera.chat" :port 6697 :nick "****")
(erc-tls :server "irc.oftc.net" :port 6697 :nick "****")

4. Use a personal certificate with OFTC (alternative to NickServ)

📁 Certificate location: The keyfile and certfile files are usually stored in: ~/.ssl/oftc/ or ~/.config/ssl/oftc/

Replace /path/to/your/keyfile and /path/to/your/certfile with the real paths, for example: ("/home/tuusuario/.ssl/oftc/nick.key" "/home/tuusuario/.ssl/oftc/nick.crt")

As an alternative to validation by key or password, there is the possibility of using certificates to connect to the server.

To use a certificate with OFTC: https://www.oftc.net/NickServ/CertFP/

The instructions for Emacs versions 27 or 28 are here: https://www.emacswiki.org/emacs/ErcSSL

We create the certificate as indicated on the oftc.net page and add this to our emacs init files:

(with-eval-after-load 'erc

  ;; erc hack for gnutls for client cert.
  (defvar *uconf/erc-certs* nil
    "erc client certs used by gnutls package for :keylist.")

  ;; copied from the gnutls lib but set :keylist to client certs.
  ;; this function is called from `open-network-stream' with :type tls.
  (defun uconf/open-gnutls-stream (name buffer host service &optional nowait)
    (let ((process (open-network-stream
                    name buffer host service
                    :nowait nowait
                    :tls-parameters
                    (and nowait
                         (cons 'gnutls-x509pki
                               (gnutls-boot-parameters
                                :type 'gnutls-x509pki
                                :keylist *uconf/erc-certs* ;;added parameter to pass the cert.
                                :hostname (puny-encode-domain host)))))))
      (if nowait
          process
        (gnutls-negotiate :process process
                          :type 'gnutls-x509pki
                          :keylist *uconf/erc-certs* ;;added parameter to pass the cert.
                          :hostname (puny-encode-domain host)))))

  ;; only set the global variable when used from `erc-tls'.
  (defun uconf/erc-open-tls-stream (name buffer host port)
    (unwind-protect
        (progn
          (setq *uconf/erc-certs*
                '(("/path/to/your/keyfile" "/path/to/your/certfile")))
          (open-network-stream name buffer host port
                               :nowait t
                               :type 'tls))
      (setq *uconf/erc-certs* nil)))

  (advice-add 'open-gnutls-stream :override #'uconf/open-gnutls-stream)
  (advice-add 'erc-open-tls-stream :override #'uconf/erc-open-tls-stream)
  )

Advanced Configuration (Optional)

💡 Note on modular configuration:

For Doom Emacs: All this advanced configuration goes in ~/.doom.d/config.el

For a clean organisation (any Emacs): You can create a separate file ~/.emacs.d/erc-config.el with all the ERC configuration and load it from your main init:

;; En tu ~/.emacs o ~/.doom.d/config.el
(when (file-exists-p "~/.emacs.d/erc-config.el")
  (load "~/.emacs.d/erc-config.el"))

This keeps your configuration modular and easy to maintain.

Improved Logging and Tracking

;; Guardar logs de conversaciones
(setq erc-log-channels-directory "~/.erc/logs/"
      erc-save-buffer-on-part t
      erc-save-queries-on-quit t
      erc-log-write-after-send t
      erc-log-write-after-insert t)

;; Tracking mejorado - ignora mensajes de sistema
(setq erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE"
                                 "324" "329" "332" "333" "353" "477")
      erc-track-enable-keybindings t
      erc-track-visibility nil)

;; Timestamps visibles
(setq erc-timestamp-format "[%H:%M]"
      erc-insert-timestamp-function 'erc-insert-timestamp-left)

Quick Connection Function

(defun my/erc-connect ()
  "Connect to IRC servers."
  (interactive)
  ;; Libera.Chat (reemplaza Freenode)
  (erc-tls :server "irc.libera.chat" :port 6697 :nick "tu-nick")

  ;; OFTC (para Debian)
  (erc-tls :server "irc.oftc.net" :port 6697 :nick "tu-nick"))

;; Keybinding para conexión rápida
(global-set-key (kbd "C-c e c") 'my/erc-connect)

On OFTC (irc.oftc.net):

  • #debian-mentors – Aspiring Debian Developers/Maintainers
  • #debian-devel – General Debian development
  • #debian-multimedia – Multimedia packages (relevant for Stremio, VLC, etc)
  • #debian-qa – Quality Assurance and testing
  • #debian-es – Spanish-speaking Debian community
  • #debian-next – Testing and Sid

On Libera.Chat (irc.libera.chat):

  • #emacs – General Emacs community
  • #emacs-es – Spanish-speaking Emacs community
  • #lisp – Common Lisp
  • #guix – GNU Guix

References and Resources

Tags

  • #emacs
  • #erc
  • #freenode
  • #irc
  • #oftc