nix-modeline is an Emacs minor mode that displays how many
Nix instantiations are in progress on your modeline. It’s very useful for
lorri and nix-direnv users as a UI for which projects are building in the
background, and fills in for both Nix and lorri’s lack of a stable event
notification API. For CPU and power efficency, nix-modeline relies on Emacs’
built-in filenotify library to monitor Nix, which lets it sleep until the
instant a Nix operation begins or ends.
nix-modeline is compatible with any Linux system running Nix including NixOS,
as well as macOS. It may work under Windows Subsystem for Linux, but your
mileage will vary. The nix-modeline-process-counter variable is worth looking
at when running on an unsupported operating system.
- Modify your Nix configuration to pull in the
nix-modelineoverlay (for better expression caching, replacemasterin the URL with the latest commit in this repo, and add a validsha256attribute under that):
nixpkgs.overlays = [
(import (builtins.fetchTarball {
url = "https://github.com/ocelot-project/nix-modeline/archive/master.tar.gz";
}))
];- After that, override your
emacsderivation with one that pulls in thenix-modelinepackage. For example, in/etc/nixos/configuration.nixon a NixOS system:
environment.systemPackages = [
# Replace any existing emacs derivation with:
(pkgs.emacsPackagesGen pkgs.emacs).emacsWithPackages (epkgs: [
pkgs.nix-modeline
])
];nix-modeline is available on MELPA. If MELPA is part of your configured
package-archives, installing should be as simple as choosing nix-modeline in
the list-packages interface. Note that Emacs distributions like Doom,
Spacemacs, and Prelude will be configured to use MELPA, but generally have their
own way of configuring packages. See your distro’s manual for information.
- First, clone
nix-modeline:
git clone https://github.com/ocelot-project/nix-modeline.git- Then add the directory containing
nix-modelineto your Emacsload-path:
(push "/path/to/nix-modeline" load-path)- Note that Emacs distros like Doom, Spacemacs, and Prelude have their own way to install packages. See your distro’s manual for information.
- For plain Emacs, just
(require 'nix-modeline)and execute(nix-modeline-mode)to enable the minor mode. - Doom, Spacemacs, Prelude, and other Emacs distros have more efficient ways to
pull in
nix-modeline. See your distro’s manual on how to configure packages.
nix-modeline has a lot of configuration options. See the `defcustom`
expressions in `nix-modeline.el` for a complete list. Some of the most important
options are:
| Option | Description |
|---|---|
nix-modeline-*-text | Change the modeline text for a given Nix state |
nix-modeline-*-face | Change the modeline text color for a given Nix state |
Set nix-modeline-idle-text to "", and Emacs won’t render nix-modeline
when Nix isn’t doing anything.
By default, nix-modeline only shows your Nix processes. To change that, set
nix-modeline-users to either 'self-and-root (which will include
nixos-rebuild switch and other root-owned Nix processes) or 'all.
You can! Use nix-modeline-hook, which runs whenever a Nix operation begins or
ends. Note that this hook only works when nix-modeline is enabled.
Unfortunately not. Nix, lorri, and direnv all lack a stable event stream I can tap into, as well as any usable standardized operation logs. If there’s enough popular demand for the feature, getting an event stream implemented in Nix isn’t out of the realm of possibility.
The default text that nix-modeline displays uses Unicode characters that your
Emacs font might not support. The variables used to control this text look like
nix-modeline-*-text; change their value to a string that doesn’t contain
Unicode chraracters, and toggle nix-modeline off and on again.
That’s a shame. Previous iterations of nix-modeline utilized a shell scripting
oriented approach, based around ~entr~:
while [ true ]; do
echo /nix/var/nix/db/db.sqlite | entr -dns "sleep 0.025; pgrep -U $(id -u)";
doneThis should be portable to other editors like vim and vscode, or to tools that
support displaying the output of a shell script as a widget.