-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdefault.nix
More file actions
167 lines (146 loc) · 3.84 KB
/
Copy pathdefault.nix
File metadata and controls
167 lines (146 loc) · 3.84 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{
lib,
stdenv,
pkg-config,
installShellFiles,
cairo,
libxkbcommon,
pango,
wayland,
wayland-scanner,
wayland-protocols,
libx11,
libxinerama,
# customization
backend ? "both",
patches ? [ ],
# wks file support
wksFile ? null,
wksContent ? null,
wksDirs ? null,
}:
with builtins;
with lib;
let
# Backend validation and configuration
validBackends = [
"both"
"x11"
"wayland"
];
backendValid = elem backend validBackends;
backends = {
hasX11 = backend == "both" || backend == "x11";
hasWayland = backend == "both" || backend == "wayland";
};
# WKS configuration and validation
wks = rec {
# Input validation
hasContent = wksContent != null;
hasFile = wksFile != null;
hasDirs = wksDirs != null && (isList wksDirs && length wksDirs > 0);
# Validation flags
contentConflicts = hasContent && hasFile;
dirsRequiresEntryPoint = wksDirs != null && !(hasFile || hasContent);
dirsValid = wksDirs == null || (isList wksDirs && length wksDirs > 0);
# Determine which wks source to use
fileToUse = if hasContent then builtins.toFile "key_chords.wks" wksContent else wksFile;
# Whether we're using custom wks configuration
isCustom = fileToUse != null || hasDirs;
# Determine Make target based on backend and wks usage
makeTarget =
if !isCustom then
(if backend == "both" then "all" else backend)
else if backend == "both" then
"from-wks"
else
"from-wks-${backend}";
};
# Helper functions for preBuild
copyWksFile = file: "cp ${file} config/key_chords.wks";
copyWksDirs =
dirs:
concatMapStringsSep "\n" (d: ''
cp -r ${d} config/${baseNameOf d}
'') dirs;
in
# Assertions
assert assertMsg backendValid
"Invalid backend '${backend}'. Must be one of: ${concatStringsSep ", " validBackends}";
assert assertMsg (!wks.contentConflicts) "wksContent cannot be used with wksFile";
assert assertMsg (
!wks.dirsRequiresEntryPoint
) "wksDirs requires either wksFile or wksContent to be specified";
assert assertMsg wks.dirsValid "wksDirs must be a non-empty list if provided";
stdenv.mkDerivation (finalAttrs: {
pname = "wk";
version = lib.fileContents ./VERSION;
src =
with fileset;
toSource {
root = ./.;
fileset = unions [
./VERSION
./Makefile
# Include all config files except generated key_chords.h
(difference ./config (maybeMissing ./config/key_chords.h))
./completions
./man
./src
];
};
strictDeps = true;
nativeBuildInputs = [
pkg-config
installShellFiles
]
++ optionals backends.hasWayland [
wayland-scanner
];
buildInputs = [
cairo
pango
]
++ optionals backends.hasWayland [
# Wayland
libxkbcommon
wayland
wayland-protocols
]
++ optionals backends.hasX11 [
# X11
libx11
libxinerama
];
inherit patches;
makeFlags = [ "PREFIX=$(out)" ];
# When using custom wks, copy it to config/
preBuild = optionalString wks.isCustom (
copyWksFile wks.fileToUse + optionalString wks.hasDirs ("\n" + copyWksDirs wksDirs)
);
buildPhase = ''
runHook preBuild
make ${wks.makeTarget}
runHook postBuild
'';
passthru = {
# Backend information
inherit backend;
inherit (backends) hasX11 hasWayland;
# WKS configuration info
isCustomWks = wks.isCustom;
};
meta = {
homepage = "https://github.com/3L0C/wk";
description = "Which-Key via X11 and Wayland";
longDescription = ''
wk is a popup menu for your custom keyboard shortcuts. Inspired by
emacs-which-key, dmenu, and bemenu. It supports both X11 and Wayland
backends with a custom scripting language (wks) for defining key chord
mappings.
'';
license = licenses.gpl3Plus;
platforms = platforms.linux;
mainProgram = "wk";
};
})