-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkmonad.nix
91 lines (82 loc) · 2.41 KB
/
kmonad.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{ config, lib, ... }:
with lib;
let
cfg = config.services.kmonad;
keyboardOpts = { name, ... }: {
options = {
name = mkOption {
type = types.str;
readOnly = true;
description = ''
Unique name of the keyboard. This is set to the attribute name of the
keyboard configuration.
'';
};
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable the kmonad service for this keyboard.
'';
};
device = mkOption {
type = with types; either path str;
description = ''
The path to the device file.
'';
};
config = mkOption {
type = types.lines;
default = "";
description = ''
The kmonad configuration for this keyboard.
'';
};
};
config = { name = mkDefault name; };
};
in {
options.services.kmonad = {
keyboards = mkOption {
type = types.attrsOf (types.submodule keyboardOpts);
default = { };
description = "List of keyboard configurations.";
};
package = mkOption {
type = types.package;
example = "pkgs.kmonad";
description = ''
The KMonad package.
'';
};
};
# NOTE: the top-level attrs assigned to config cannot be created by a fold or
# merge over cfg.keyboards, it seems, as that results in an infinite
# recursion.
config =
let enabledKeyboards = filterAttrs (name: kb: kb.enable) cfg.keyboards;
in mkIf (cfg.keyboards != { }) {
xdg.configFile = mapAttrs' (name: kb:
nameValuePair "kmonad/kmonad-${name}.kbd" { text = kb.config; })
enabledKeyboards;
systemd.user.paths = mapAttrs' (name: kb:
nameValuePair "kmonad-${name}" {
Unit.Description = "Trigger for KMonad for ${name}";
Install.WantedBy = [ "default.target" ];
Path = {
Unit = "kmonad-${name}.service";
PathExists = kb.device;
};
}) enabledKeyboards;
systemd.user.services = mapAttrs' (name: kb:
nameValuePair "kmonad-${name}" {
Unit.Description = "KMonad for ${name}";
Service = {
Type = "simple";
ExecStart = "${cfg.package}/bin/kmonad ${
config.xdg.configFile."kmonad/kmonad-${name}.kbd".source
}";
};
}) enabledKeyboards;
};
}