-
-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathflake.nix
More file actions
570 lines (519 loc) · 19.7 KB
/
flake.nix
File metadata and controls
570 lines (519 loc) · 19.7 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
{
description = "A flake for lem";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:nixos/nixpkgs/release-25.11";
};
outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
imports = [
inputs.flake-parts.flakeModules.easyOverlay
];
perSystem =
{ pkgs, ... }:
let
# --- Setup & Helpers ---
lisp = pkgs.sbcl;
# Helper to generate the Lisp build script used by all variants
mkBuildScript =
{
entryPoint ? "lem:main",
}:
pkgs.writeText "build-lem.lisp" ''
(defpackage :nix-cl-user (:use :cl))
(in-package :nix-cl-user)
;; Load ASDF
(load "${lem-base.asdfFasl}/asdf.${lem-base.faslExt}")
(asdf:initialize-output-translations '(:output-translations :disable-cache :inherit-configuration))
;; Load Systems
(mapcar #'asdf:load-system (uiop:split-string (uiop:getenv "systems")))
;; Dump Image
(setf uiop:*image-entry-point* #'${entryPoint})
(uiop:dump-image "lem" :executable t :compression t)
'';
sources = import ./_sources/generated.nix {
inherit (pkgs)
fetchgit
fetchurl
fetchFromGitHub
dockerTools
;
};
# --- Core Lisp Dependencies ---
micros = lisp.buildASDFSystem {
inherit (sources.micros) pname src version;
systems = [ "micros" ];
};
jsonrpc = lisp.buildASDFSystem {
inherit (sources.jsonrpc) pname src version;
systems = [
"jsonrpc"
"jsonrpc/transport/stdio"
"jsonrpc/transport/tcp"
"jsonrpc/transport/websocket"
"jsonrpc/transport/local-domain-socket"
];
lispLibs = with lisp.pkgs; [
yason
alexandria
bordeaux-threads
dissect
chanl
vom
usocket
trivial-timeout
cl_plus_ssl
quri
fast-io
trivial-utf-8
websocket-driver
clack
clack-handler-hunchentoot
event-emitter
hunchentoot
];
};
async-process =
let
c-lib = pkgs.stdenv.mkDerivation {
inherit (sources.async-process) pname src version;
nativeBuildInputs = with pkgs; [
libtool
libffi.dev
automake
autoconf
pkg-config
];
buildPhase = "make PREFIX=$out";
};
in
lisp.buildASDFSystem {
inherit (sources.async-process) pname src version;
systems = [ "async-process" ];
lispLibs = [ lisp.pkgs.cffi ];
nativeLibs = [ c-lib ];
nativeBuildInputs = [ pkgs.pkg-config ];
};
lem-mailbox = lisp.buildASDFSystem {
inherit (sources.lem-mailbox) pname src version;
systems = [ "lem-mailbox" ];
lispLibs = with lisp.pkgs; [
bordeaux-threads
bt-semaphore
queues
queues_dot_simple-cqueue
];
};
# --- Tree-sitter Support ---
# Use local tree-sitter-cl if available, otherwise use nvfetcher source
tree-sitter-cl-src =
let
localPath = /home/user/lem-project/tree-sitter-cl;
in
if builtins.pathExists localPath then localPath else sources.tree-sitter-cl.src;
# C wrapper library for tree-sitter (handles by-value struct returns)
ts-wrapper = pkgs.stdenv.mkDerivation {
pname = "ts-wrapper";
version = "0.1.0";
src = "${tree-sitter-cl-src}/c-wrapper";
buildInputs = [ pkgs.tree-sitter ];
buildPhase =
let
ext = if pkgs.stdenv.isDarwin then "dylib" else "so";
in
''
$CC -shared -fPIC -o libts-wrapper.${ext} ts-wrapper.c \
-I${pkgs.tree-sitter}/include \
-L${pkgs.tree-sitter}/lib \
-ltree-sitter
'';
installPhase =
let
ext = if pkgs.stdenv.isDarwin then "dylib" else "so";
in
''
mkdir -p $out/lib
cp libts-wrapper.${ext} $out/lib/
'';
};
# tree-sitter-cl Lisp bindings (from github.com/lem-project/tree-sitter-cl)
tree-sitter-cl = lisp.buildASDFSystem {
pname = "tree-sitter-cl";
version = sources.tree-sitter-cl.version;
src = tree-sitter-cl-src;
systems = [ "tree-sitter-cl" ];
lispLibs = with lisp.pkgs; [
cffi
alexandria
trivial-garbage
];
nativeLibs = [
pkgs.tree-sitter
ts-wrapper
];
};
# Tree-sitter language grammars
tree-sitter-grammars = {
json = pkgs.tree-sitter-grammars.tree-sitter-json;
markdown = pkgs.tree-sitter-grammars.tree-sitter-markdown;
yaml = pkgs.tree-sitter-grammars.tree-sitter-yaml;
nix = pkgs.tree-sitter-grammars.tree-sitter-nix;
# Languages for Living Canvas multi-language support
python = pkgs.tree-sitter-grammars.tree-sitter-python;
javascript = pkgs.tree-sitter-grammars.tree-sitter-javascript;
typescript = pkgs.tree-sitter-grammars.tree-sitter-typescript;
go = pkgs.tree-sitter-grammars.tree-sitter-go;
perl = pkgs.tree-sitter-grammars.tree-sitter-perl;
# Clojure support
clojure = pkgs.tree-sitter-grammars.tree-sitter-clojure;
};
# --- Webview Specific Dependencies ---
c-webview = pkgs.stdenv.mkDerivation {
pname = "c-webview";
version = "unstable";
src = sources.webview.src;
nativeBuildInputs = with pkgs; [
cmake
ninja
pkg-config
];
buildInputs =
if pkgs.stdenv.isLinux then
[
pkgs.webkitgtk_4_1
pkgs.webkitgtk_6_0
pkgs.gtk3
]
else
[ ];
# Use FETCHCONTENT to use pre-fetched source instead of network
configurePhase = ''
runHook preConfigure
cmake -G Ninja -B build -S c \
-DCMAKE_BUILD_TYPE=Release \
-DFETCHCONTENT_SOURCE_DIR_WEBVIEW=${sources.webview-upstream.src}
runHook postConfigure
'';
buildPhase = "cmake --build build";
installPhase =
let
suffix = if pkgs.stdenv.isLinux then "so" else "dylib";
in
''
mkdir -p $out/lib
cp build/lib/libexample.${suffix} $out/lib/libwebview.${suffix}
'';
};
cl-webview = lisp.buildASDFSystem {
inherit (sources.webview) pname src version;
systems = [ "webview" ];
lispLibs = with lisp.pkgs; [
cffi
float-features
];
nativeLibs = [ c-webview ];
postPatch = ''
# Fix library loading path and name in the Lisp binding
sed -i 's/(define-foreign-library (libwebview/(define-foreign-library libwebview/' webview.lisp
sed -i '/:search-path/,/arm64"))))/d' webview.lisp
sed -i 's/"libwebview\.so\.0\.12\.0"/"libwebview.so"/' webview.lisp
'';
};
# --- Lem Core Definition ---
# List of libraries common to all Lem frontends
commonLispLibs = with lisp.pkgs; [
micros
async-process
jsonrpc
lem-mailbox
tree-sitter-cl
deploy
iterate
closer-mop
trivia
alexandria
trivial-gray-streams
trivial-types
cl-ppcre
inquisitor
babel
bordeaux-threads
yason
log4cl
split-sequence
str
dexador
cl-mustache
esrap
parse-number
cl-package-locks
trivial-utf-8
swank
_3bmd
_3bmd-ext-code-blocks
lisp-preprocessor
trivial-ws
trivial-open-browser
frugal-uuid
hunchentoot
];
# The base derivation that other variants inherit from
lem-base = lisp.buildASDFSystem {
pname = "lem-base";
version = "unstable";
src = ./.;
nativeBuildInputs = [ pkgs.makeBinaryWrapper ];
lispLibs = commonLispLibs;
postPatch = ''
sed -i '1i(pushnew :nix-build *features*)' lem.asd
'';
buildScript = mkBuildScript { entryPoint = "lem:main"; };
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install lem $out/bin
wrapProgram $out/bin/lem \
--prefix LD_LIBRARY_PATH : "$LD_LIBRARY_PATH" \
--prefix DYLD_LIBRARY_PATH : "$DYLD_LIBRARY_PATH"
runHook postInstall
'';
};
# 1. Ncurses Variant
lem-ncurses = lem-base.overrideLispAttrs (o: {
pname = "lem-ncurses";
meta.mainProgram = "lem";
systems = [ "lem-ncurses" "tree-sitter-cl" "lem-tree-sitter" ];
lispLibs =
o.lispLibs
++ (with lisp.pkgs; [
cl-charms
cl-setlocale
]);
nativeLibs = [
pkgs.ncurses
pkgs.tree-sitter
ts-wrapper
];
# Add tree-sitter grammar paths (grammars don't have lib/ subdir)
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install lem $out/bin
wrapProgram $out/bin/lem \
--prefix LD_LIBRARY_PATH : "$LD_LIBRARY_PATH:${tree-sitter-grammars.json}:${tree-sitter-grammars.markdown}:${tree-sitter-grammars.yaml}:${tree-sitter-grammars.nix}:${tree-sitter-grammars.python}:${tree-sitter-grammars.javascript}:${tree-sitter-grammars.typescript}:${tree-sitter-grammars.go}:${tree-sitter-grammars.perl}:${tree-sitter-grammars.clojure}" \
--prefix DYLD_LIBRARY_PATH : "$DYLD_LIBRARY_PATH"
runHook postInstall
'';
});
# 2. SDL2 Variant
lem-sdl2 = lem-base.overrideLispAttrs (o: {
pname = "lem-sdl2";
meta.mainProgram = "lem";
systems = [ "lem-sdl2" "tree-sitter-cl" "lem-tree-sitter" ];
lispLibs =
o.lispLibs
++ (with lisp.pkgs; [
sdl2
sdl2-ttf
sdl2-image
trivial-main-thread
]);
nativeLibs = with pkgs; [
SDL2
SDL2_ttf
SDL2_image
tree-sitter
ts-wrapper
];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install lem $out/bin
wrapProgram $out/bin/lem \
--prefix LD_LIBRARY_PATH : "$LD_LIBRARY_PATH:${tree-sitter-grammars.json}:${tree-sitter-grammars.markdown}:${tree-sitter-grammars.yaml}:${tree-sitter-grammars.nix}:${tree-sitter-grammars.python}:${tree-sitter-grammars.javascript}:${tree-sitter-grammars.typescript}:${tree-sitter-grammars.go}:${tree-sitter-grammars.perl}:${tree-sitter-grammars.clojure}" \
--prefix DYLD_LIBRARY_PATH : "$DYLD_LIBRARY_PATH"
runHook postInstall
'';
});
# 3. Webview Variant
lem-webview = lem-base.overrideLispAttrs (o: {
pname = "lem-webview";
meta.mainProgram = "lem";
systems = [ "lem-webview" "tree-sitter-cl" "lem-tree-sitter" ];
# Use the specific webview entry point
buildScript = mkBuildScript { entryPoint = "lem-webview:main"; };
lispLibs =
o.lispLibs
++ [ cl-webview ]
++ (with lisp.pkgs; [
float-features
command-line-arguments
]);
nativeLibs =
if pkgs.stdenv.isLinux then
[
pkgs.webkitgtk_4_1
pkgs.webkitgtk_6_0
pkgs.gtk3
pkgs.stdenv.cc.cc.lib
c-webview
pkgs.tree-sitter
ts-wrapper
]
else
[
pkgs.stdenv.cc.cc.lib
c-webview
pkgs.tree-sitter
ts-wrapper
];
postPatch =
(o.postPatch or "")
+ (
if pkgs.stdenv.isLinux then
''sed -i 's/fontName:"Monospace"/fontName:"DejaVu Sans Mono"/' frontends/server/frontend/dist/assets/index.js''
else
''sed -i 's/fontName:"Monospace"/fontName:"Menlo"/' frontends/server/frontend/dist/assets/index.js''
);
postInstall =
if pkgs.stdenv.isLinux then
''
wrapProgram $out/bin/lem \
--set FONTCONFIG_FILE "${pkgs.makeFontsConf { fontDirectories = [ pkgs.dejavu_fonts ]; }}" \
--prefix XDG_DATA_DIRS : "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}" \
--prefix XDG_DATA_DIRS : "${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}" \
--prefix LD_LIBRARY_PATH : "${tree-sitter-grammars.json}:${tree-sitter-grammars.markdown}:${tree-sitter-grammars.yaml}:${tree-sitter-grammars.nix}:${tree-sitter-grammars.python}:${tree-sitter-grammars.javascript}:${tree-sitter-grammars.typescript}:${tree-sitter-grammars.go}:${tree-sitter-grammars.perl}:${tree-sitter-grammars.clojure}"
''
else
''
wrapProgram $out/bin/lem \
--prefix LD_LIBRARY_PATH : "${tree-sitter-grammars.json}:${tree-sitter-grammars.markdown}:${tree-sitter-grammars.yaml}:${tree-sitter-grammars.nix}:${tree-sitter-grammars.python}:${tree-sitter-grammars.javascript}:${tree-sitter-grammars.typescript}:${tree-sitter-grammars.go}:${tree-sitter-grammars.perl}:${tree-sitter-grammars.clojure}"
'';
});
in
{
overlayAttrs = {
inherit lem-ncurses lem-sdl2 lem-webview;
};
packages = {
inherit lem-ncurses lem-sdl2 lem-webview;
default = lem-ncurses;
};
apps = {
lem-ncurses = {
type = "app";
program = lem-ncurses;
};
lem-sdl2 = {
type = "app";
program = lem-sdl2;
};
lem-webview = {
type = "app";
program = lem-webview;
};
default = {
type = "app";
program = lem-ncurses;
};
};
devShells.default = pkgs.mkShell {
packages = with pkgs; [
# Lisp development
sbcl
sbclPackages.qlot-cli
# Build tools
gnumake
pkg-config
# Node.js for frontend development
nodejs_22
# Native libraries for frontends
ncurses
SDL2
SDL2_ttf
SDL2_image
# SSL/TLS support
openssl
# Tree-sitter support
tree-sitter
pkgs.tree-sitter-grammars.tree-sitter-json
pkgs.tree-sitter-grammars.tree-sitter-markdown
pkgs.tree-sitter-grammars.tree-sitter-yaml
pkgs.tree-sitter-grammars.tree-sitter-nix
pkgs.tree-sitter-grammars.tree-sitter-python
pkgs.tree-sitter-grammars.tree-sitter-javascript
pkgs.tree-sitter-grammars.tree-sitter-typescript
pkgs.tree-sitter-grammars.tree-sitter-go
pkgs.tree-sitter-grammars.tree-sitter-perl
pkgs.tree-sitter-grammars.tree-sitter-clojure
# Perl Language Server
pkgs.perl538Packages.PLS # provides 'pls' command (used by lem-perl-mode)
# Clojure development
clojure
clojure-lsp
leiningen
babashka
# Code formatting
nixfmt-rfc-style
# Development tools
direnv
] ++ lib.optionals stdenv.isLinux [
# Linux-specific dependencies for webview frontend
webkitgtk_4_1
gtk3
];
# Set up library paths for native dependencies
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath ([
pkgs.ncurses
pkgs.SDL2
pkgs.SDL2_ttf
pkgs.SDL2_image
pkgs.openssl
pkgs.tree-sitter
ts-wrapper
pkgs.tree-sitter-grammars.tree-sitter-json
pkgs.tree-sitter-grammars.tree-sitter-markdown
pkgs.tree-sitter-grammars.tree-sitter-yaml
pkgs.tree-sitter-grammars.tree-sitter-nix
pkgs.tree-sitter-grammars.tree-sitter-python
pkgs.tree-sitter-grammars.tree-sitter-javascript
pkgs.tree-sitter-grammars.tree-sitter-typescript
pkgs.tree-sitter-grammars.tree-sitter-go
pkgs.tree-sitter-grammars.tree-sitter-perl
pkgs.tree-sitter-grammars.tree-sitter-clojure
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
pkgs.webkitgtk_4_1
pkgs.gtk3
]);
shellHook = ''
# Prioritize local tree-sitter-cl c-wrapper for development
if [ -f "$HOME/lem-project/tree-sitter-cl/c-wrapper/libts-wrapper.so" ]; then
export LD_LIBRARY_PATH="$HOME/lem-project/tree-sitter-cl/c-wrapper:$LD_LIBRARY_PATH"
fi
echo "Lem development environment"
echo " SBCL: $(sbcl --version)"
echo " qlot: $(qlot --version 2>/dev/null || echo 'available')"
echo " clojure-lsp: $(clojure-lsp --version 2>/dev/null | head -1 || echo 'available')"
echo ""
echo "Quick start:"
echo " qlot install # Install dependencies"
echo " make ncurses # Build terminal version"
echo " make sdl2 # Build GUI version"
echo ""
echo "Clojure tools:"
echo " clojure-lsp # Clojure Language Server"
echo " clojure / clj # Clojure CLI"
echo " lein # Leiningen build tool"
echo " bb # Babashka scripting"
'';
};
};
};
}