-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflake.nix
More file actions
303 lines (280 loc) · 9.69 KB
/
Copy pathflake.nix
File metadata and controls
303 lines (280 loc) · 9.69 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
{
description = "The whole local AI stack in one executable: run and manage local AI models, and search your files, code, and crawled web pages, with cited answers";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs =
{ self, nixpkgs }:
let
sources = builtins.fromJSON (builtins.readFile ./sources.json);
inherit (sources) version;
systems = builtins.attrNames sources.systems;
forAllSystems = nixpkgs.lib.genAttrs systems;
mkPkgs = system: import nixpkgs { inherit system; };
mkMeta = pkgs: {
description = "The whole local AI stack in one executable: run and manage local AI models, and search your files, code, and crawled web pages, with cited answers";
homepage = "https://github.com/tobocop2/lilbee";
license = pkgs.lib.licenses.mit;
mainProgram = "lilbee";
platforms = systems;
sourceProvenance = [ pkgs.lib.sourceTypes.binaryNativeCode ];
};
mkBin =
pkgs: system:
let
entry = sources.systems.${system};
in
pkgs.stdenvNoCC.mkDerivation {
pname = "lilbee-bin";
inherit version;
src = pkgs.fetchurl {
url = "https://github.com/tobocop2/lilbee/releases/download/v${version}/${entry.asset}";
inherit (entry) sha256;
};
dontUnpack = true;
installPhase = ''
runHook preInstall
install -Dm755 $src $out/bin/lilbee
runHook postInstall
'';
meta = mkMeta pkgs;
};
# The release binary is a Nuitka onefile: it self-extracts at launch
# and dlopen's its bundled .so's via the standard ld.so path.
# buildFHSEnv exposes glibc / libgomp / vulkan-loader at /lib so the
# extracted libs resolve on bare NixOS. Darwin uses @executable_path
# install names and needs no wrapper.
mkLinuxFHS =
pkgs: system:
pkgs.buildFHSEnv {
name = "lilbee";
targetPkgs =
ps: with ps; [
stdenv.cc.cc.lib
glibc
zlib
vulkan-loader
libGL
];
runScript = "${mkBin pkgs system}/bin/lilbee";
meta = mkMeta pkgs;
};
mkLilbee =
system:
let
pkgs = mkPkgs system;
isLinux = pkgs.lib.hasSuffix "linux" system;
in
if isLinux then mkLinuxFHS pkgs system else mkBin pkgs system;
# CUDA variant: lives in sources-cuda.json so the standard publish path
# (which overwrites sources.json) cannot wipe it. Only present on
# x86_64-linux and only when sources-cuda.systems.${system} is populated;
# publish-cuda-packages fills it in after build-gpu-executables runs.
cudaSources = builtins.fromJSON (builtins.readFile ./sources-cuda.json);
cudaSystems = builtins.attrNames cudaSources.systems;
hasCuda = system: builtins.elem system cudaSystems;
mkCudaBin =
pkgs: system:
let
entry = cudaSources.systems.${system};
in
pkgs.stdenvNoCC.mkDerivation {
pname = "lilbee-cuda";
inherit version;
src = pkgs.fetchurl {
url = "https://github.com/tobocop2/lilbee/releases/download/v${version}/${entry.asset}";
inherit (entry) sha256;
};
dontUnpack = true;
installPhase = ''
runHook preInstall
install -Dm755 $src $out/bin/lilbee
runHook postInstall
'';
meta = mkMeta pkgs;
};
# Like mkLinuxFHS but omits vulkan-loader. The CUDA build bundles its
# own cudart/cublas via Nuitka onefile; the host only needs the NVIDIA
# driver, which on NixOS is exposed via hardware.nvidia.* config.
mkCudaLinuxFHS =
pkgs: system:
pkgs.buildFHSEnv {
name = "lilbee-cuda";
targetPkgs =
ps: with ps; [
stdenv.cc.cc.lib
glibc
zlib
libGL
];
runScript = "${mkCudaBin pkgs system}/bin/lilbee";
meta = mkMeta pkgs;
};
mkLilbeeCuda =
system:
let
pkgs = mkPkgs system;
in
mkCudaLinuxFHS pkgs system;
# ROCm variant: same split as CUDA, in sources-rocm.json so the standard
# publish cannot wipe it. publish-rocm-packages fills it in after the ROCm
# executable is attached.
rocmSources = builtins.fromJSON (builtins.readFile ./sources-rocm.json);
rocmSystems = builtins.attrNames rocmSources.systems;
hasRocm = system: builtins.elem system rocmSystems;
mkRocmBin =
pkgs: system:
let
entry = rocmSources.systems.${system};
in
pkgs.stdenvNoCC.mkDerivation {
pname = "lilbee-rocm";
inherit version;
src = pkgs.fetchurl {
url = "https://github.com/tobocop2/lilbee/releases/download/v${version}/${entry.asset}";
inherit (entry) sha256;
};
dontUnpack = true;
installPhase = ''
runHook preInstall
install -Dm755 $src $out/bin/lilbee
runHook postInstall
'';
meta = mkMeta pkgs;
};
# No vulkan-loader, same as CUDA. The ROCm build carries its own userspace,
# so the host supplies only the amdgpu kernel driver, plus libnuma and
# libdrm which must match it.
mkRocmLinuxFHS =
pkgs: system:
pkgs.buildFHSEnv {
name = "lilbee-rocm";
targetPkgs =
ps: with ps; [
stdenv.cc.cc.lib
glibc
zlib
libGL
numactl
libdrm
elfutils
];
runScript = "${mkRocmBin pkgs system}/bin/lilbee";
meta = mkMeta pkgs;
};
mkLilbeeRocm =
system:
let
pkgs = mkPkgs system;
in
mkRocmLinuxFHS pkgs system;
# Pre-Haswell CPU variant: the same Vulkan binary built against the +compat
# lancedb. Kept in sources-compat.json so the standard publish (which
# overwrites sources.json) can't wipe it; present only on x86_64-linux and
# only once publish-compat-packages fills sources-compat.systems.${system}.
compatSources = builtins.fromJSON (builtins.readFile ./sources-compat.json);
compatSystems = builtins.attrNames compatSources.systems;
hasCompat = system: builtins.elem system compatSystems;
mkCompatBin =
pkgs: system:
let
entry = compatSources.systems.${system};
in
pkgs.stdenvNoCC.mkDerivation {
pname = "lilbee-compat";
inherit version;
src = pkgs.fetchurl {
url = "https://github.com/tobocop2/lilbee/releases/download/v${version}/${entry.asset}";
inherit (entry) sha256;
};
dontUnpack = true;
installPhase = ''
runHook preInstall
install -Dm755 $src $out/bin/lilbee
runHook postInstall
'';
meta = mkMeta pkgs;
};
# Same FHS surface as the default build -- the compat binary is still a
# Vulkan onefile, only its bundled lancedb differs.
mkCompatLinuxFHS =
pkgs: system:
pkgs.buildFHSEnv {
name = "lilbee-compat";
targetPkgs =
ps: with ps; [
stdenv.cc.cc.lib
glibc
zlib
vulkan-loader
libGL
];
runScript = "${mkCompatBin pkgs system}/bin/lilbee";
meta = mkMeta pkgs;
};
mkLilbeeCompat =
system:
let
pkgs = mkPkgs system;
in
mkCompatLinuxFHS pkgs system;
in
{
packages = forAllSystems (
system:
{
default = mkLilbee system;
}
// nixpkgs.lib.optionalAttrs (hasCuda system) {
lilbee-cuda = mkLilbeeCuda system;
}
// nixpkgs.lib.optionalAttrs (hasRocm system) {
lilbee-rocm = mkLilbeeRocm system;
}
// nixpkgs.lib.optionalAttrs (hasCompat system) {
lilbee-compat = mkLilbeeCompat system;
}
);
apps = forAllSystems (system: {
default = {
type = "app";
program = nixpkgs.lib.getExe self.packages.${system}.default;
inherit (self.packages.${system}.default) meta;
};
});
formatter = forAllSystems (system: (mkPkgs system).nixfmt-rfc-style);
nixosModules.lilbee =
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.lilbee;
in
{
options.services.lilbee = {
enable = lib.mkEnableOption "lilbee HTTP server as a user-level systemd service";
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${pkgs.system}.default;
defaultText = lib.literalExpression "lilbee.packages.\${pkgs.system}.default";
description = "lilbee package to run.";
};
};
config = lib.mkIf cfg.enable {
systemd.user.services.lilbee = {
description = "lilbee HTTP server";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "default.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${cfg.package}/bin/lilbee serve --host 127.0.0.1 --port 42697";
Restart = "on-failure";
RestartSec = 5;
};
};
};
};
};
}