nixpkgs/nixos/modules/services/x11/window-managers
Ivan b90c5cb703
XMonad: configured recompile (#107696)
* nixos/xmonad: xmonad config w/ghc+xmessage

When the "config" option isn't set, we use xmonad-with-packages to
provide xmonad with runtime access to an isolated ghc, ensuring it can
recompile and exec a user's local config (e.g. $HOME/.xmonad/xmonad.hs)
regardless of which ghc (if any) is on PATH.

When the "config" option is set, however, we compile a configured xmonad
executable upfront (during nixos-rebuild), and prior to this commit, it
was not provided with runtime access to an isolated ghc.

As a result, with the "config" option set, it was not possible
to recompile and exec a user's local config unless there was a
compatible version of ghc on PATH with the necessary packages (xmonad,
xmonad-contrib, etc.) in its package database. Adding such a ghc to
environment.systemPackages, e.g.

  (haskellPackages.ghcWithPackages (ps: with ps; [xmonad xmonad-contrib]))

is problematic because it adds both ghc and an unconfigured xmonad to
PATH, e.g.

  $ ls -l $(which xmonad ghc)
  lrwxrwxrwx ... /run/current-system/sw/bin/ghc -> /nix/store/...-ghc-8.10.2-with-packages/bin/ghc
  lrwxrwxrwx ... /run/current-system/sw/bin/xmonad -> /nix/store/...-ghc-8.10.2-with-packages/bin/xmonad

Having the unconfigured xmonad on PATH is particularly bad because
restarting xmonad will dump the user into the unconfigured version, and
if no local config exists (e.g. in $HOME/.xmonad/xmonad.hs), they'll be
left in this unconfigured state.

In this commmit, we give the configured xmonad runtime access to ghc
like xmonad-with-packages does for the unconfigured version. The aim
is to allow the user to switch between the nixos module's config and a
local config (e.g. $HOME/.xmonad/xmonad.hs) at will, so they can try out
config changes without performing a nixos-rebuild.

Since the xmonad on PATH is the configured executable, there's no
danger a user could unwittingly restart into the unconfigured version,
and because xmonad will refuse to recompile when no local config
exists, there's no danger a user could unwittingly recompile into an
unconfigured version.

Given that a local config exists, the recompile/restart behavior depends
on two factors:
- which entry point is used
  * 'XMonad.xmonad' (default)
  * 'XMonad.launch' (recommended in "config" option description)
- what operation is triggered (i.e. via mod+q)
  * `spawn "xmonad --recompile && xmonad --restart"` (default)
  * `restart "xmonad" True`
  * custom function

If the default 'XMonad.xmonad' entrypoint and default mod+q operation
are used, hitting mod+q will compile and exec the local config, which
will remain in use until next time the display manager is restarted.

If the entrypoint is changed to 'XMonad.launch' but mod+q left with its
default operation, hitting mod+q will have no visible effect. The logs
(as seen by running `journalctl --identifier xmonad --follow`) will show
an error,
  X Error of failed request:  BadAccess (attempt to access private resource denied)
which indicates that the shell was unable to start xmonad because
another window manager is already running (namely, the nixos-configured
xmonad).
https://wiki.haskell.org/Xmonad/Frequently_asked_questions#X_Error_of_failed_request:_BadAccess_.28attempt_to_access_private_resource_denied.29

Changing the mod+q operation to `restart "xmonad" True` (as recommended
in the "config" option's description) will allow a restart of the
nixos-configured xmonad to be triggeredy by hitting mod+q.

Finally, if the entrypoint is 'XMonad.launch', mod+q has been
bound to `restart "xmonad" True` and another key bound to a custom
recompile/restart function (e.g. `compileRestart` as shown in the
"config" option example), the user can switch between the nixos module's
config and their local config, with the custom key switching to the
local config and mod+q switching back.

* nixos/xmonad: refactor let binding

* nixos/xmonad: refactor (eliminate duplicate code)

* nixos/xmonad: install man pages

Prior to this commit, man pages were not installed if the "config"
option was set.

* nixos/xmonad: comment grammar fixups

* nixos/xmonad: writeStateToFile in example config

Calling writeStateToFile prior to recompiling and restarting allows
state (workspaces, etc.) to be preserved across the restart.

* nixos/xmonad: add ivanbrennan to maintainers

* nixos/xmonad: adjust compileRestart example

* nixos/xmonad: add missing import to example config
2020-12-28 17:27:36 +01:00
..
2bwm.nix avoid package attributes starting with a digit 2018-01-16 21:13:16 +01:00
afterstep.nix Getting rid of mkOption in NixOS window manager modules 2015-12-04 07:38:23 -02:00
awesome.nix nixos/awesome: Add noArgb option 2018-06-13 19:47:26 +02:00
berry.nix berry: init at 0.1.5 2020-05-13 21:32:54 -03:00
bspwm.nix nixos/bspwm: spawn bpswm process in the background and properly set waiPID (#39707) 2018-04-30 17:03:05 +00:00
clfswm.nix Getting rid of mkOption in NixOS window manager modules 2015-12-04 07:38:23 -02:00
cwm.nix nixos/cwm: init 2019-09-29 23:26:08 +02:00
default.nix lwm: init at 1.2.4 2020-05-13 21:32:54 -03:00
dwm.nix nixos dwm: start user installed dwm if available 2019-03-11 20:18:08 +01:00
evilwm.nix nixos/*: fix indentation 2020-11-23 08:42:51 +10:00
exwm.nix nixos/exwm: allow custom Emacs load script 2019-05-27 02:18:42 +01:00
fluxbox.nix Fix evaluation after merge of #11450. 2015-12-04 15:40:47 +01:00
fvwm.nix fvwm module: init; now fvwm can be used as an xserver.windowManager 2017-04-05 11:12:46 -04:00
herbstluftwm.nix herbstluftwm module: add configFile option 2017-02-21 05:46:13 +01:00
i3.nix nixos/window-managers/i3: write config file to /etc/i3/config 2019-04-26 21:12:52 +02:00
icewm.nix Getting rid of mkOption in NixOS window manager modules 2015-12-04 07:38:23 -02:00
jwm.nix jwm: window manager module addition 2016-03-07 16:07:13 -03:00
leftwm.nix leftwm: enable service 2019-05-26 01:27:04 +09:00
lwm.nix lwm: init at 1.2.4 2020-05-13 21:32:54 -03:00
metacity.nix nixos/metacity: switch to gnome3.metacity 2018-08-09 17:36:47 +02:00
mwm.nix motif: init at 2.3.6 2016-07-28 01:33:45 +03:00
none.nix Revert "nixos/none: remove" 2020-04-02 04:07:18 -04:00
notion.nix Getting rid of mkOption in NixOS window manager modules 2015-12-04 07:38:23 -02:00
openbox.nix [bot] treewide: remove unused 'inherit' in let blocks 2018-07-20 19:38:19 +00:00
oroborus.nix
pekwm.nix pekwm: init at 0.1.17 2016-07-09 22:26:24 -03:00
qtile.nix nixos/modules: remove trailing whitespace 2020-08-07 14:45:39 +01:00
ratpoison.nix Getting rid of mkOption in NixOS window manager modules 2015-12-04 07:38:23 -02:00
sawfish.nix Getting rid of mkOption in NixOS window manager modules 2015-12-04 07:38:23 -02:00
smallwm.nix smallwm: init at 2020-02-28 2020-05-13 21:32:54 -03:00
spectrwm.nix Getting rid of mkOption in NixOS window manager modules 2015-12-04 07:38:23 -02:00
stumpwm.nix nixos: stumpwm: switch from package marked as broken to working quicklisp package (#40501) 2018-05-14 18:37:53 +02:00
tinywm.nix tinywm: init at 2014-04-22 2020-05-08 15:29:25 -03:00
twm.nix Getting rid of mkOption in NixOS window manager modules 2015-12-04 07:38:23 -02:00
windowlab.nix WindowLab: initial pkg at 1.40 2015-12-30 11:10:30 +01:00
windowmaker.nix Getting rid of mkOption in NixOS window manager modules 2015-12-04 07:38:23 -02:00
wmii.nix Merge pull request #43863 from volth/unused4 2018-07-21 16:39:08 +01:00
xmonad.nix XMonad: configured recompile (#107696) 2020-12-28 17:27:36 +01:00
yeahwm.nix yeahwm: init at 0.3.5 2020-05-13 21:32:54 -03:00