The journey to neolight

The journey to neolight
Photo by Lukas / Unsplash

A while ago, I discovered that tool called neolight. I have been using it for a bit over a year now, always on Arch Linux.

Neolight is a very simple program that adds two more layers, on the Caps Lock/$ keys and on the </Menu keys. The first layer contains all the symbols you would ever need while programming (think curly/square braces, quotes, etc.), and the second layer contains different navigation keys, such as positioning arrows at the vim keys positions.

It has been a very useful tool, greatly improving my typing performance at work, since I don’t have to twist my fingers to reach symbol keys anymore, as one would with a QWERTZ keyboard.

The NixOS issue

I've recently been introduced to NixOS, a Linux distribution declaratively configured in so-called Nix files. As one would expect, it is therefore immutable, meaning most system- and package-related files are in a read-only file system, and can only be altered through modifying aforementioned Nix files and rebuilding the system.

So far, the author of neolight, mihi314, only officially supported Arch Linux, and made his own AUR package to help the installation on Arch Linux. He also created an installation script, for installing on FHS-compliant systems, such as Fedora or Ubuntu.

NixOS, sadly, is not an FHS-compliant system. It is, for example, missing the /usr folder, instead offering /run/current-system/sw for user-installed libraries. This folder is part of the read-only file system.

Packaging neolight

At first, I thought packaging it would be as trivial as rewriting paths — write to $out/share instead of /usr/share, as most other packaged programs do. Needless to say, this didn’t work.

I tried tinkering about some more, but the more I tried, the more I noticed I didn’t understand anything about how the Nix packages system worked. This is when I decided to reach out and joined the NixOS dev Matrix room, where I quickly found help towards packaging stuff in general, but also found the maker of the services.xserver.xkb.extraLayouts property, rnhmjoj, which allows one to add custom layouts to their system. They have been a great help, trying to use their own product to make neolight work, and also making me discover Nix VMs, which are virtual machines built entirely from a NixOS configuration file. I also started modifying their code directly, writing to some XKB config files, and could see the beginning of a result.

Sadly, some personal matters caught up to me, and I had to pause the packaging process for a while.

Copy-pasting, a developer's best friend

How many times has a dev copy-pasted code directly from stack overflow? Certainly more than one would expect.

Once I came back to my problem, I started wondering about other solutions. It has been brought to my attention that postInstall was a thing, and it allowed to run arbitrary code once a package has been installed. I started implementing the changes I did to the xkeyboard_config module directly in there, then tried compiling. Apparently, modifying a package on which the entirety of gnome depends is not a good idea — my computer ran out of RAM, and after setting up swap it would eat 50GiB of it. Regardless, I never let it finish compiling because of how long it took.

One of the big voices of NixOS in Switzerland, ners, whom I previously met through social media applications, told me that there was nothing keeping me from making my own package, instead of overriding xkeyboard_config. I tried it, and lo and behold, my configuration was finally applied! Now was just a matter of copying over the install.sh script, modifying the paths as I originally imagined, setting an environment variable as explained by rnhmjoj, and PR #434361 was born!

A word on NixOS

NixOS, due to how different it is from every other distribution, has a very steep learning curve. I never thought I would learn how to use it by packaging such a complicated tool, and am positively impressed with how it turned out. My package could certainly be improved, mainly by not copying over xkeyboard_config, but it works, and to me is what matters.

That being said, I absolutely fell in love with NixOS’s community. Even with a total beginner like me, assuming wrong things and struggling with the tools I was given, they’ve all without exception been understanding, giving me time to figure stuff out.