Repository navigation
Expand file tree
/
Copy pathdarwin-module.nix
More file actions
339 lines (329 loc) · 11.8 KB
/
Copy pathdarwin-module.nix
File metadata and controls
339 lines (329 loc) · 11.8 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
self:
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.blit;
inherit (lib)
mkEnableOption
mkOption
types
mkIf
;
in
{
options.services.blit = {
enable = mkEnableOption "blit terminal multiplexer";
package = mkOption {
type = types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.blit;
defaultText = "self.packages.\${system}.blit";
description = "The blit package to use.";
};
shell = mkOption {
type = types.nullOr types.str;
default = null;
example = "/run/current-system/sw/bin/fish";
description = "Shell to spawn for new PTYs. Defaults to the user's login shell.";
};
scrollback = mkOption {
type = types.int;
default = 10000;
description = "Scrollback buffer size in rows per PTY.";
};
languageServers = mkOption {
type = types.listOf types.package;
default = [ ];
example = lib.literalExpression "[ pkgs.nixd pkgs.rust-analyzer pkgs.gopls ]";
description = ''
Language servers to place on the blit server's PATH so
<literal>blit lsp</literal> (docs/design/lsp.md) can discover and
spawn them. blit ships none; list the servers you want available
and their binaries are prepended to the server process's PATH.
blit matches them to files by project marker and extension, keeps
them warm across connections, and never downloads anything. Empty
by default. Set <option>BLIT_LSP=0</option> via the environment to
disable the family entirely.
'';
};
audio = {
enable = mkEnableOption "audio forwarding (Linux only — no-op on Darwin)";
bitrate = mkOption {
type = types.int;
default = 64000;
description = "Opus encoder bitrate in bits/sec. Only effective on Linux.";
};
};
socketPath = mkOption {
type = types.nullOr types.str;
default = null;
description = "Unix socket path for blit server. Defaults to $TMPDIR/blit-default.sock.";
};
gateways = mkOption {
type = types.attrsOf (
types.submodule {
options = {
port = mkOption {
type = types.port;
default = 3264;
description = "Port to listen on.";
};
addr = mkOption {
type = types.str;
default = "127.0.0.1";
description = "Address to bind to.";
};
passFile = mkOption {
type = types.path;
description = "File containing BLIT_PASSPHRASE=<passphrase> or BLIT_PASSPHRASE=<argon2 PHC hash>.";
};
fontDirs = mkOption {
type = types.listOf types.str;
default = [ ];
example = [
"/Library/Fonts"
"~/Library/Fonts"
];
description = "Extra font directories to search.";
};
quic = mkOption {
type = types.bool;
default = false;
description = "Enable WebTransport (QUIC/HTTP3) alongside WebSocket.";
};
tlsCert = mkOption {
type = types.nullOr types.path;
default = null;
description = "PEM certificate file for WebTransport TLS. Auto-generated if null.";
};
tlsKey = mkOption {
type = types.nullOr types.path;
default = null;
description = "PEM private key file for WebTransport TLS. Auto-generated if null.";
};
remoteFile = mkOption {
type = types.nullOr types.path;
default = null;
example = "/etc/blit/remotes";
description = ''
Path to a <literal>blit.remotes</literal>-format file listing
named destinations for this gateway. When unset, the gateway
uses <literal>~/.config/blit/blit.remotes</literal> (the
user's default remotes file, writable via
<literal>blit remote add</literal>). The file is
live-reloaded on change; no gateway restart required.
'';
};
storeConfig = mkOption {
type = types.bool;
default = false;
description = "Sync browser settings to ~/.config/blit/blit.conf.";
};
webrtcProxy = mkOption {
type = types.bool;
default = false;
description = ''
Enable gateway-side WebRTC proxying for
<literal>share:</literal> remotes (<literal>BLIT_GATEWAY_WEBRTC=1</literal>).
When enabled, the gateway connects to the signaling hub as a
WebRTC consumer and bridges <literal>share:</literal> sessions
to browsers over WebSocket/WebTransport.
Without this, <literal>share:</literal> entries in
<literal>blit.remotes</literal> are ignored by the gateway.
'';
};
hub = mkOption {
type = types.nullOr types.str;
default = null;
example = "hub.blit.sh";
description = ''
Signaling hub URL for <literal>share:</literal> remotes
(sets <literal>BLIT_HUB</literal>).
Only used when <option>webrtcProxy</option> is enabled.
Defaults to <literal>hub.blit.sh</literal>.
'';
};
package = mkOption {
type = types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.blit;
defaultText = "self.packages.\${system}.blit";
description = "The blit package to use for the gateway.";
};
};
}
);
default = { };
description = "Named blit gateway instances.";
};
shares = mkOption {
type = types.attrsOf (
types.submodule {
options = {
passFile = mkOption {
type = types.path;
description = "File containing BLIT_PASSPHRASE=<passphrase>.";
};
hub = mkOption {
type = types.nullOr types.str;
default = null;
description = "Signaling hub URL. Defaults to hub.blit.sh.";
};
quiet = mkOption {
type = types.bool;
default = true;
description = "Don't print the sharing URL.";
};
verbose = mkOption {
type = types.bool;
default = false;
description = "Print detailed connection diagnostics to stderr.";
};
verboseWebrtc = mkOption {
type = types.bool;
default = false;
description = "Enable WebRTC-level tracing (BLIT_WEBRTC_VERBOSE=1): ICE candidates, STUN/TURN results, SDP exchange, and DataChannel events.";
};
package = mkOption {
type = types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.blit;
defaultText = "self.packages.\${system}.blit";
description = "The blit package to use for the share service.";
};
};
}
);
default = { };
description = "Named blit share instances exposing blit server sessions via WebRTC.";
};
};
config = mkIf cfg.enable {
launchd.user.agents = {
blit = {
serviceConfig = {
Label = "com.blit.server";
ProgramArguments = [
"/bin/sh"
"-lc"
# Language servers on PATH so `blit lsp` can discover them
# (docs/design/lsp.md); prepended so a user-installed server
# does not shadow the pinned one.
(
# launchd does not expand `~` in WorkingDirectory — it fails the
# spawn with EX_CONFIG (78) before the job ever runs, so cd here
# instead.
''cd "$HOME" || exit 1; ''
+ ''[ -n "$LANG" ] || export LANG="$(defaults read -g AppleLocale 2>/dev/null | sed 's/@.*//' || echo en_US).UTF-8"; ''
+ lib.optionalString (
cfg.languageServers != [ ]
) ''export PATH="${lib.makeBinPath cfg.languageServers}:$PATH"; ''
+ ''exec ${cfg.package}/bin/blit server''
)
];
EnvironmentVariables = {
BLIT_SCROLLBACK = toString cfg.scrollback;
}
// lib.optionalAttrs (cfg.socketPath != null) {
BLIT_SOCK = cfg.socketPath;
}
// lib.optionalAttrs (cfg.shell != null) {
SHELL = cfg.shell;
};
RunAtLoad = true;
KeepAlive = true;
StandardOutPath = "/tmp/blit-server.log";
StandardErrorPath = "/tmp/blit-server.log";
};
};
}
// builtins.listToAttrs (
lib.mapAttrsToList (name: gw: {
name = "blit-gateway-${name}";
value =
let
effectiveRemoteFile = gw.remoteFile;
in
{
serviceConfig = {
Label = "com.blit.gateway.${name}";
ProgramArguments = [
"/bin/sh"
"-lc"
". ${gw.passFile} && exec ${gw.package}/bin/blit gateway"
];
EnvironmentVariables = {
BLIT_ADDR = "${gw.addr}:${toString gw.port}";
}
// lib.optionalAttrs (cfg.socketPath != null) {
BLIT_SOCK = cfg.socketPath;
}
// lib.optionalAttrs (effectiveRemoteFile != null) {
BLIT_REMOTES = effectiveRemoteFile;
}
// lib.optionalAttrs (gw.fontDirs != [ ]) {
BLIT_FONT_DIRS = lib.concatStringsSep ":" gw.fontDirs;
}
// lib.optionalAttrs gw.storeConfig {
BLIT_STORE_CONFIG = "1";
}
// lib.optionalAttrs gw.quic {
BLIT_QUIC = "1";
}
// lib.optionalAttrs (gw.tlsCert != null) {
BLIT_TLS_CERT = gw.tlsCert;
}
// lib.optionalAttrs (gw.tlsKey != null) {
BLIT_TLS_KEY = gw.tlsKey;
}
// lib.optionalAttrs gw.webrtcProxy {
BLIT_GATEWAY_WEBRTC = "1";
}
// lib.optionalAttrs (gw.hub != null) {
BLIT_HUB = gw.hub;
};
RunAtLoad = true;
KeepAlive = true;
StandardOutPath = "/tmp/blit-gateway-${name}.log";
StandardErrorPath = "/tmp/blit-gateway-${name}.log";
};
};
}) cfg.gateways
)
// builtins.listToAttrs (
lib.mapAttrsToList (name: shr: {
name = "blit-share-${name}";
value = {
serviceConfig = {
Label = "com.blit.share.${name}";
ProgramArguments = [
"/bin/sh"
"-lc"
(
". ${shr.passFile} && exec ${shr.package}/bin/blit share"
+ lib.optionalString shr.quiet " --quiet"
+ lib.optionalString shr.verbose " --verbose"
)
];
EnvironmentVariables =
{ }
// lib.optionalAttrs (cfg.socketPath != null) {
BLIT_SOCK = cfg.socketPath;
}
// lib.optionalAttrs (shr.hub != null) {
BLIT_HUB = shr.hub;
}
// lib.optionalAttrs shr.verboseWebrtc {
BLIT_WEBRTC_VERBOSE = "1";
};
RunAtLoad = true;
KeepAlive = true;
StandardOutPath = "/tmp/blit-share-${name}.log";
StandardErrorPath = "/tmp/blit-share-${name}.log";
};
};
}) cfg.shares
);
};
}