1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.xserver.windowManager.exwm;
7 loadScript = pkgs.writeText "emacs-exwm-load" ''
8 ${cfg.loadScript}
9 ${optionalString cfg.enableDefaultConfig ''
10 (require 'exwm-config)
11 (exwm-config-default)
12 ''}
13 '';
14 packages = epkgs: cfg.extraPackages epkgs ++ [ epkgs.exwm ];
15 exwm-emacs = pkgs.emacsWithPackages packages;
16in
17
18{
19 options = {
20 services.xserver.windowManager.exwm = {
21 enable = mkEnableOption (lib.mdDoc "exwm");
22 loadScript = mkOption {
23 default = "(require 'exwm)";
24 type = types.lines;
25 example = ''
26 (require 'exwm)
27 (exwm-enable)
28 '';
29 description = lib.mdDoc ''
30 Emacs lisp code to be run after loading the user's init
31 file. If enableDefaultConfig is true, this will be run
32 before loading the default config.
33 '';
34 };
35 enableDefaultConfig = mkOption {
36 default = true;
37 type = lib.types.bool;
38 description = lib.mdDoc "Enable an uncustomised exwm configuration.";
39 };
40 extraPackages = mkOption {
41 type = types.functionTo (types.listOf types.package);
42 default = epkgs: [];
43 defaultText = literalExpression "epkgs: []";
44 example = literalExpression ''
45 epkgs: [
46 epkgs.emms
47 epkgs.magit
48 epkgs.proofgeneral
49 ]
50 '';
51 description = lib.mdDoc ''
52 Extra packages available to Emacs. The value must be a
53 function which receives the attrset defined in
54 {var}`emacs.pkgs` as the sole argument.
55 '';
56 };
57 };
58 };
59
60 config = mkIf cfg.enable {
61 services.xserver.windowManager.session = singleton {
62 name = "exwm";
63 start = ''
64 ${exwm-emacs}/bin/emacs -l ${loadScript}
65 '';
66 };
67 environment.systemPackages = [ exwm-emacs ];
68 };
69}