a modern NixOS desktop deploy with Emacs/EXWM
Published on
This is essentially the representation of my desktop (almost, I cut secrets and various services not needed to be here since just side elements) and how I deploy and maintain it. The purpose is give an idea of a practical modern literate-programming/IaC style single-host management (in the future I add the infra management) where the core is Emacs/org-mode used both to document, compose and act.
The core concept is that a modern system MUST BE REPRODUCIBLE, with ease, MUST BE DOCUMENTED, with ease and the docs must be kept in sync with the code and fresh, must be easy to study for third party to properly handle systems and hand them over from an admin to another.
The complete config is actually very long for an article, but the core while long is here and have to be to clearly give something usable for anyone who want to test. Org-mode offer easy tangle, no special setup or boilerplate needed to act, obviously offer easy documentation, this very article is written in org-mode and in the org-mode source the code is live code, we can tangle, run and so on while we can export the org file containing anything to html or LaTeX (to produce a pdf) easily. A proper export demand a bit of boilerplate, at least to much a website CSS or a LaTeX style of export, but once done it's done, until you decide to change the style the org-mode is independent and work flawlessly. Similarly having code and docs together in a docs-first form force anyone to be clear, the deploy is at first a pure human-language description of the target system, then the code to achieve, a bit of loop if during the coding phase we see that something should be done differently, then a first test deploy with a custom ISO image, also in org-mode (but part of another article since it's already too long for the web the base system alone) and the following normal upkeep is also "automated" in simple org-mode.
The desktop itself boot to Emacs thanks to EXWM so anything is REALLY integrated, immediately accessible and easy. The not-so-easy part is the Nix language witch is the main obstacle to a NixOS diffusion outside a small community of companies and individual who understand the value of having a fully declarative system instead of running a Babel's tower of containers (like popular Docker/k*s) of course with a manually installed base system, binary images built by no-one-know who, full of outdated software, eating an enormous amount of resources just because "entering this model" is far easier than learn Nix, Emacs/org-mode etc, not considering that once learnt a minimum they are useful for life (Emacs is here, alive and kicking since 50+ years just for instance) and anything is quick and done instead of be a continuous race against bugs and issues.
How to use this article to deploy a real system
Well, you need the org-mode source, a working Emacs set up as you like, a NixOS system to create a custom ISO and do the deploy or at least do the deploy by hand on an official NixOS live.
Learning Emacs is a long shot, definitively worth the investment, but goes much beyond using it to deploy hosts, it's useful for anything, from personal notes, emails, file management to host deploy so essentially it's a human-computer interface that allow humans doing ANYTHING inside it thanks to the fact it's a single open application where anything is just a bit of text and code intermixed an live (re)loadable.
To start with NixOS, so without having it, the distro offer some live images. You only need to add Emacs config with this article, now yours, in org-mode, from the network or via a USB stick/partition in the USB stick used to boot (since a single desktop is normally not netbooted from a homeserver, witch will be part of another article about infra deploy).
How to start alone
Just create a repo, put this article in org-mode form in it, let's say in a
NixOS
subdir under the repo root, while you'll create a Emacs
subdir with
you Emacs config on your actual desktop, no matter what.
Once you have learnt enough Emacs to been able to load, change and tangle
the article itself it's time to change the code as you wish and start a
first test deploy. You can just symlink relevant files under Emacs
in your
home and once anything work well enough tag a first release, after the
first NixOS deploy tag another, there is no point to split the repo/using
sub-repos for a while because in the end if the target is a system like the
one coded/described/documented in this article the two are just part of the
same system and they evolve together, repo history is just useful to track
changes, there is no real classical "release" but a continuous stream of
evolutionary step following the project progress and the software here used
progresses. Being not a self-contained system there is no point in trying
enforcing more strict tracking and versioning.
In knowledge terms you need something like The Missing Semester of Your CS Education from MIT plus Emacs knowledge and very basic Nix knowledge. For Emacs the ebook Mastering Emacs will suffice, for Nix unfortunately the docs are a bit scattered and not much coherent so you can start with official docs knowing it will be an a bit complex task.