This repository was archived by the owner on Jun 24, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathflake.nix
More file actions
234 lines (207 loc) · 7.87 KB
/
flake.nix
File metadata and controls
234 lines (207 loc) · 7.87 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
{
description = "TriliumNext Notes (experimental flake)";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
pnpm2nix = {
url = "github:FliegendeWurst/pnpm2nix-nzbr";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
pnpm2nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
electron = pkgs."electron_${lib.versions.major packageJsonDesktop.devDependencies.electron}";
nodejs = pkgs.nodejs_22;
pnpm = pkgs.pnpm_10;
inherit (pkgs)
copyDesktopItems
darwin
lib
makeBinaryWrapper
makeDesktopItem
makeShellWrapper
moreutils
removeReferencesTo
stdenv
wrapGAppsHook3
xcodebuild
;
fullCleanSourceFilter =
name: type:
(lib.cleanSourceFilter name type)
&& (
let
baseName = baseNameOf (toString name);
in
# No need to copy the flake.
# Don't copy local development instance of NX cache.
baseName != "flake.nix" && baseName != "flake.lock" && baseName != ".nx"
);
fullCleanSource =
src:
lib.cleanSourceWith {
filter = fullCleanSourceFilter;
src = src;
};
packageJson = builtins.fromJSON (builtins.readFile ./package.json);
packageJsonDesktop = builtins.fromJSON (builtins.readFile ./apps/desktop/package.json);
makeApp =
{
app,
buildTask,
mainProgram,
installCommands,
preBuildCommands ? "",
}:
pnpm2nix.packages.${system}.mkPnpmPackage rec {
pname = "triliumnext-${app}";
version = packageJson.version + (lib.optionalString (self ? shortRev) "-${self.shortRev}");
src = fullCleanSource ./.;
packageJSON = ./package.json;
pnpmLockYaml = ./pnpm-lock.yaml;
workspace = fullCleanSource ./.;
pnpmWorkspaceYaml = ./pnpm-workspace.yaml;
inherit nodejs pnpm;
extraNodeModuleSources = [
rec {
name = "patches";
value = ./patches;
}
];
# remove pnpm version override
preConfigure = ''
cat package.json | grep -v 'packageManager' | sponge package.json
'';
postConfigure =
''
chmod +x node_modules/.pnpm/electron@*/node_modules/electron/install.js
patchShebangs --build node_modules
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
node_modules/.pnpm/sass-embedded-linux-x64@*/node_modules/sass-embedded-linux-x64/dart-sass/src/dart
'';
extraNativeBuildInputs =
[
moreutils # sponge
nodejs.python
removeReferencesTo
]
++ lib.optionals (app == "desktop") [
copyDesktopItems
# required for NIXOS_OZONE_WL expansion
# https://github.com/NixOS/nixpkgs/issues/172583
makeShellWrapper
wrapGAppsHook3
]
++ lib.optionals (app == "server") [
makeBinaryWrapper
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
xcodebuild
darwin.cctools
];
dontWrapGApps = true;
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
preBuild = ''
${preBuildCommands}
'';
scriptFull = "pnpm nx ${buildTask} --outputStyle stream --verbose";
installPhase = ''
runHook preInstall
${installCommands}
runHook postInstall
'';
components = [
"packages/ckeditor5"
"packages/ckeditor5-admonition"
"packages/ckeditor5-footnotes"
"packages/ckeditor5-keyboard-marker"
"packages/ckeditor5-math"
"packages/ckeditor5-mermaid"
"packages/codemirror"
"packages/commons"
"packages/express-partial-content"
"packages/highlightjs"
"packages/turndown-plugin-gfm"
"apps/client"
"apps/db-compare"
"apps/desktop"
"apps/dump-db"
"apps/edit-docs"
"apps/server"
"apps/server-e2e"
];
desktopItems = lib.optionals (app == "desktop") [
(makeDesktopItem {
name = "TriliumNext Notes";
exec = meta.mainProgram;
icon = "trilium";
comment = meta.description;
desktopName = "TriliumNext Notes";
categories = [ "Office" ];
startupWMClass = "TriliumNext Notes";
})
];
meta = {
description = "TriliumNext: ${app}";
inherit mainProgram;
};
};
desktop = makeApp {
app = "desktop";
preBuildCommands = "export npm_config_nodedir=${electron.headers}";
buildTask = "run desktop:rebuild-deps";
mainProgram = "trilium";
installCommands = ''
remove-references-to -t ${electron.headers} apps/desktop/dist/node_modules/better-sqlite3/build/config.gypi
remove-references-to -t ${nodejs.python} apps/desktop/dist/node_modules/better-sqlite3/build/config.gypi
mkdir -p $out/{bin,share/icons/hicolor/512x512/apps,opt/trilium}
cp --archive apps/desktop/dist/* $out/opt/trilium
cp apps/client/src/assets/icon.png $out/share/icons/hicolor/512x512/apps/trilium.png
makeShellWrapper ${lib.getExe electron} $out/bin/trilium \
"''${gappsWrapperArgs[@]}" \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
--set-default ELECTRON_IS_DEV 0 \
--set TRILIUM_RESOURCE_DIR $out/opt/trilium \
--add-flags $out/opt/trilium/main.cjs
'';
};
server = makeApp {
app = "server";
preBuildCommands = "pushd apps/server; pnpm rebuild; popd";
buildTask = "--project=server build";
mainProgram = "trilium-server";
installCommands = ''
remove-references-to -t ${nodejs.python} apps/server/dist/node_modules/better-sqlite3/build/config.gypi
remove-references-to -t ${pnpm} apps/server/dist/node_modules/better-sqlite3/build/config.gypi
pushd apps/server/dist
rm -rf node_modules/better-sqlite3/build/Release/obj \
node_modules/better-sqlite3/build/Release/obj.target \
node_modules/better-sqlite3/build/Release/sqlite3.a \
node_modules/better-sqlite3/build/{Makefile,better_sqlite3.target.mk,test_extension.target.mk,binding.Makefile} \
node_modules/better-sqlite3/deps/sqlite3
popd
mkdir -p $out/{bin,opt/trilium-server}
cp --archive apps/server/dist/* $out/opt/trilium-server
makeWrapper ${lib.getExe nodejs} $out/bin/trilium-server \
--add-flags $out/opt/trilium-server/main.cjs
'';
};
in
{
packages.desktop = desktop;
packages.server = server;
packages.default = desktop;
}
);
}