Edit XMonad configuration with IDE support

The second step of the Make Tech Simple Again project was to switch from i3 to XMonad. Why? Because this opens me up to write complex workflows in Haskell with its type-safety benefits.

Over at FP Zulip, when I floated the idea of writing Haskell DSL for i3 configuration, someone suggested to just use XMonad instead. XMonad is a window manager where your configuration file is just Haskell code.

Because it is all Haskell, we can use haskell-language-server to provide full IDE support – autocomplete, hover popups, documentation links, etc. – for editing window manager configuration.

Here’s how you do it:

  1. Create a cabal project (see Creating a new Haskell project with IDE support using Nix)
  2. Add your XMonad configuration to the Main.hs
  3. Add xmonad, xmonad-contrib and other dependencies to the cabal file
  4. Adjust your NixOS XMonad configuration to use this project

Step 4 basically involves using the Main.hs as the config file, as well as copying over the Cabal dependencies. So, in your configuration.nix you would do something like:

services.xserver.windowManager.xmonad = {
  enable = true;
  extraPackages = haskellPackages: [
  enableContribAndExtras = true;
  config = pkgs.lib.readFile ./xmonad-config/Main.hs;

Your Cabal project lives at ./xmonad-config … and, if you followed the instructions in Creating a new Haskell project with IDE support using Nix to setup IDE configuration, you can simply launch VSCode using code ./xmonad-config to start editing your configuration.