One has to nixos-rebuild switch
, logout and login back in order to bring the new xmonad.hs
configuration into effect. Can this be avoided entirely? Similar to i3’s config reloading?
I doubt so, as the config is baked/compiled into the binary. After a nixos-rebuild switch
the xmonad
binary for the current config won’t have the same path anymore, and there isn’t a way to communicate this path to the new one.
And even then, it would require to restart itself. Even on non-nix systems that manage xmonad by hand, I think it wouldn’t be possible to reload configuration of it without logging out and in.
My first instinct would be to have a look at home-manager
, and from what people are saying, and reading the code, it does seem to have reloading: https://github.com/nix-community/home-manager/blob/45abf3d38a2b51c00c347cab6950f3734e023bba/modules/services/window-managers/xmonad.nix#L89
Actually it should just work with default keybinding M-q
. xmonad can recompile configuration by itself (outside of nix), and invoke the new executable (passing all the current state to it).
You can use custom xmonad build script in ~/.xmonad/build
for tighter integration with nix (i.e. to have configuration compiled during nixos-rebuild
, and not during actual login), but it’s totally optional. Here is an example of mine - https://github.com/binarin/nixos-config/blob/720b77e730574bd621f4e2729c811d4afdcf3f59/xmonad-config/build
I figured out a solution. Basically it is a two step process:
- Run
nixos-rebuild switch
to build thexmonad
binary on $PATH - Run
xmonad --restart
Step 2 can be bound to keyboard shortcut using the following key binding:
((modKey, xK_q), restart "/run/current-system/sw/bin/xmonad" True),
Xmonad doedsn’t do any recompiling (it is nixos-rebuild that does that; though it would be nice if we can do all of this instantly from VSCode)