-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
363 lines (347 loc) · 12.7 KB
/
flake.nix
File metadata and controls
363 lines (347 loc) · 12.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
{
description = "Nightly Logseq wrapper flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
nixConfig = {
extra-substituters = [
"https://nix-logseq-git-flake.cachix.org"
];
extra-trusted-public-keys = [
"nix-logseq-git-flake.cachix.org-1:DSBNW07PSRyCvS926tpIWahb53OIydwwZhsP6LhJNZo="
];
};
outputs =
{
self,
nixpkgs,
flake-utils,
git-hooks,
}:
let
systems = flake-utils.lib.defaultSystems;
in
flake-utils.lib.eachSystem systems (
system:
let
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
manifest = import ./lib/loadManifest.nix {
inherit lib;
manifestPath = ./data/logseq-nightly.json;
};
runtimeLibs = import ./lib/runtime-libs.nix;
runtimeLibList = runtimeLibs pkgs;
runtimeLibPath = lib.makeLibraryPath runtimeLibList;
payload = pkgs.fetchzip {
url = manifest.assetUrl;
hash = manifest.assetSha256;
stripRoot = false;
};
logseqSrc = pkgs.fetchFromGitHub {
owner = "logseq";
repo = "logseq";
rev = manifest.logseqRev;
hash = manifest.cliSrcHash;
};
logseqTree = pkgs.runCommand "logseq-tree" { } ''
mkdir -p $out/share/logseq
src="${payload}"
if [ -d "$src/Logseq-linux-x64" ]; then
cp -r "$src/Logseq-linux-x64/." $out/share/logseq/
else
cp -r "$src/." $out/share/logseq/
fi
# electron-builder (upstream after logseq#12517) names the exe
# lowercase `logseq`; older electron-forge nightlies shipped `Logseq`.
# Expose both so the launcher and `runScript` work either way.
cd $out/share/logseq
if [ -x logseq ] && [ ! -e Logseq ]; then
ln -s logseq Logseq
elif [ -x Logseq ] && [ ! -e logseq ]; then
ln -s Logseq logseq
fi
'';
fhsBase =
{
additionalPkgs ? (_pkgs: [ ]),
}:
pkgs.buildFHSEnv {
name = "logseq-fhs";
targetPkgs = pkgs: runtimeLibs pkgs ++ additionalPkgs pkgs;
extraBwrapArgs = [
"--bind-try"
"/etc/nixos"
"/etc/nixos"
"--ro-bind-try"
"/etc/xdg"
"/etc/xdg"
];
extraInstallCommands = ''
ln -s ${logseqTree}/share $out/share
'';
runScript = "${logseqTree}/share/logseq/logseq";
};
logseqFhs = fhsBase { };
desktopEntry = pkgs.writeTextFile {
name = "logseq-desktop";
destination = "/share/applications/logseq.desktop";
text = ''
[Desktop Entry]
Type=Application
Name=Logseq
Exec=logseq %U
Icon=logseq
Terminal=false
Categories=Office;Productivity;
StartupWMClass=Logseq
MimeType=x-scheme-handler/logseq;
'';
};
icon = pkgs.runCommand "logseq-icon" { } ''
mkdir -p $out/share/icons/hicolor/512x512/apps
cp ${logseqSrc}/resources/icon.png \
$out/share/icons/hicolor/512x512/apps/logseq.png
'';
launcher = pkgs.writeShellScriptBin "logseq" ''
base_ld="${runtimeLibPath}"
if [ -n "''${LD_LIBRARY_PATH-}" ]; then
base_ld="$base_ld:''${LD_LIBRARY_PATH}"
fi
if [ -d /run/opengl-driver ]; then
export LD_LIBRARY_PATH="/run/opengl-driver/lib:/run/opengl-driver-32/lib:$base_ld"
export LIBGL_DRIVERS_PATH="''${LIBGL_DRIVERS_PATH:-/run/opengl-driver/lib/dri}"
export LIBVA_DRIVERS_PATH="''${LIBVA_DRIVERS_PATH:-/run/opengl-driver/lib/dri}"
if ls /run/opengl-driver/lib/libnvidia-*.so >/dev/null 2>&1; then
export __NV_PRIME_RENDER_OFFLOAD="''${__NV_PRIME_RENDER_OFFLOAD:-1}"
export __VK_LAYER_NV_optimus="''${__VK_LAYER_NV_optimus:-NVIDIA_only}"
export LIBVA_DRIVER_NAME="''${LIBVA_DRIVER_NAME:-nvidia}"
# Electron relies on EGL/ANGLE; forcing a GLX vendor breaks PRIME on NVIDIA (Invalid visual ID).
if [ -n "''${LOGSEQ_GLX_VENDOR-}" ]; then
export __GLX_VENDOR_LIBRARY_NAME="''${__GLX_VENDOR_LIBRARY_NAME:-''${LOGSEQ_GLX_VENDOR}}"
fi
if [ -z "''${VK_ICD_FILENAMES-}" ] && [ -f /run/opengl-driver/share/vulkan/icd.d/nvidia_icd.json ]; then
export VK_ICD_FILENAMES=/run/opengl-driver/share/vulkan/icd.d/nvidia_icd.json
fi
fi
else
export LD_LIBRARY_PATH="$base_ld"
export LIBGL_DRIVERS_PATH="''${LIBGL_DRIVERS_PATH:-${pkgs.mesa}/lib/dri}"
export LIBVA_DRIVERS_PATH="''${LIBVA_DRIVERS_PATH:-${pkgs.mesa}/lib/dri}"
fi
exec ${logseqFhs}/bin/logseq-fhs "$@"
'';
afterFormatting = [ "treefmt" ];
afterLinters = [
"deadnix"
"statix"
"actionlint"
"shellcheck"
];
lockPatchExcludes = [
"\\.lock$"
"\\.patch$"
];
preCommit = git-hooks.lib.${system}.run {
src = ./.;
hooks = {
treefmt = {
enable = true;
settings = {
fail-on-change = true;
# NOTE: This applies to both local hooks and `nix flake check`.
# Deterministic behavior is preferred over speed here.
no-cache = true;
formatters = [
pkgs.nixfmt
pkgs.biome
pkgs.prettier
pkgs.shfmt
];
};
};
deadnix = {
enable = true;
after = afterFormatting;
};
statix = {
enable = true;
after = afterFormatting;
};
actionlint = {
enable = true;
after = afterFormatting;
};
shellcheck = {
enable = true;
after = afterFormatting;
};
trim-trailing-whitespace = {
enable = true;
after = afterLinters;
excludes = lockPatchExcludes;
};
end-of-file-fixer = {
enable = true;
after = afterLinters;
excludes = lockPatchExcludes;
};
check-merge-conflicts = {
enable = true;
after = afterLinters;
excludes = lockPatchExcludes;
};
check-json = {
enable = true;
after = afterLinters;
};
check-yaml = {
enable = true;
after = afterLinters;
};
};
};
cli = pkgs.callPackage ./lib/cli.nix {
inherit (manifest)
logseqRev
cliSrcHash
cliVersion
cliPnpmDepsHash
cliVendorHash
;
};
logseqDesktop = pkgs.stdenv.mkDerivation {
pname = "logseq-desktop";
version = manifest.logseqVersion;
dontUnpack = true;
buildCommand = ''
mkdir -p $out
cp -r --no-preserve=mode,ownership ${logseqTree}/share $out/
cp -r --no-preserve=mode,ownership ${icon}/share $out/
cp -r --no-preserve=mode,ownership ${desktopEntry}/share $out/
mkdir -p $out/bin
ln -s ${launcher}/bin/logseq $out/bin/logseq
'';
meta = with lib; {
description = "Logseq nightly desktop app";
homepage = "https://github.com/logseq/logseq";
license = licenses.agpl3Plus;
platforms = platforms.linux;
mainProgram = "logseq";
};
passthru = {
fhs = logseqFhs;
fhsWithPackages = fhsBase;
};
};
in
{
packages = {
logseq = logseqDesktop;
logseq-cli = cli;
default = pkgs.symlinkJoin {
name = "logseq-nightly";
paths = [
logseqDesktop
cli
];
};
};
apps.logseq = {
type = "app";
program = "${logseqDesktop}/bin/logseq";
meta = {
description = "Launch the nightly Logseq build packaged from the upstream master branch";
homepage = "https://github.com/logseq/logseq";
source = self.outPath;
};
};
checks = {
logseq = pkgs.runCommand "logseq-check" { } ''
${pkgs.coreutils}/bin/test -x ${logseqDesktop}/bin/logseq
touch $out
'';
logseq-cli = pkgs.runCommand "logseq-cli-check" { } ''
${pkgs.coreutils}/bin/test -x ${cli}/bin/logseq-cli
touch $out
'';
# Runtime smoke test: invoking the CLI exercises nbb-logseq's
# classpath (cli/src + cli/vendor/src). Any missing vendor
# namespace (the regression class fixed in PR #21) crashes here
# on the first loadFile, so passing both probes is a strong
# signal that the FOD copy still produces a working tree.
#
# Both probes assert on stable upstream substrings (`Usage:`,
# `mcp-server`, `database version`). If upstream rewords any of
# these, the grep fails closed — that's the right direction for
# a regression guard, and the failing line in the build log
# points at the exact substring to update.
#
# Probe order matters: probe 1 (`--help`) populates
# `NBB_CACHE_DIR` before probe 2 (`list`) reuses it. That keeps
# probe 2 fast at the cost of not independently verifying empty-
# cache population — probe 1 covers that case implicitly.
logseq-cli-help = pkgs.runCommand "logseq-cli-help-check" { } ''
export HOME=$TMPDIR
export XDG_CACHE_HOME=$TMPDIR/cache
# Probe 1: --help exercises the help renderer's namespace.
help_output=$(${cli}/bin/logseq-cli --help 2>&1)
help_status=$?
if [ "$help_status" -ne 0 ]; then
echo "logseq-cli --help exited $help_status" >&2
echo "$help_output" >&2
exit 1
fi
# `Usage:` and `mcp-server` are stable substrings of the help
# output produced by the upstream CLI; require both so a future
# silent fallthrough (e.g. nbb prints a stack trace but still
# exits 0) doesn't get rubber-stamped.
echo "$help_output" | ${pkgs.gnugrep}/bin/grep -q '^Usage:'
echo "$help_output" | ${pkgs.gnugrep}/bin/grep -q 'mcp-server'
# Probe 2: `list` against an empty HOME forces the
# graph-discovery namespace (the original regression site —
# `logseq.common.graph-dir`) to load. With no graphs present
# the CLI emits a stable warning string and exits 0; a missing
# vendor namespace would crash before reaching that point.
list_output=$(${cli}/bin/logseq-cli list 2>&1)
list_status=$?
if [ "$list_status" -ne 0 ]; then
echo "logseq-cli list exited $list_status" >&2
echo "$list_output" >&2
exit 1
fi
echo "$list_output" | ${pkgs.gnugrep}/bin/grep -qF 'database version'
touch $out
'';
pre-commit-check = preCommit;
};
devShells =
let
hookShell = pkgs.mkShell {
packages = preCommit.enabledPackages ++ [
pkgs.coreutils
pkgs.git
pkgs.pre-commit
];
inherit (preCommit) shellHook;
};
in
{
default = hookShell;
# Compatibility alias for older docs/scripts: `nix develop .#hooks`.
hooks = hookShell;
};
formatter = pkgs.nixfmt-tree;
}
)
// {
overlays.default = import ./overlays {
inherit (self) packages;
};
};
}