-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdefault.nix
More file actions
265 lines (236 loc) · 7.13 KB
/
Copy pathdefault.nix
File metadata and controls
265 lines (236 loc) · 7.13 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
{
pkgs ? import <nixpkgs> { },
craneLib ? null,
version ? "0.4.0-dev.12",
}:
let
# Per-channel install identity. Mirrors the runtime `ReleaseChannel` and the
# deb/rpm packaging: a nightly build installs under distinct binary/desktop/
# icon names so a stable and a nightly package can coexist in one profile
# (e.g. a home-manager `buildEnv`) without colliding on `bin/dbflux`.
isNightly = pkgs.lib.hasInfix "nightly" version;
appId = if isNightly then "dbflux-nightly" else "dbflux";
appName = if isNightly then "DBFlux Nightly" else "DBFlux";
brandDir = if isNightly then "nightly" else "stable";
# Build inputs needed at runtime
buildInputs = with pkgs; [
openssl
sqlite
zstd
zlib
fontconfig
freetype
wayland
libxkbcommon
xorg.libX11
xorg.libxcb
xorg.libXcursor
xorg.libXrandr
xorg.libXi
vulkan-loader
vulkan-headers
alsa-lib
libgit2
curl
libsecret
libssh2
dbus
tree-sitter
];
# Build inputs needed only at build time
nativeBuildInputs = with pkgs; [
pkg-config
cmake
makeWrapper
openssl.dev
# Required by .cargo/config.toml, which links the x86_64-unknown-linux-gnu
# target with -fuse-ld=mold. Needed by every cargo invocation over this tree
# (package builds and dev shells), so it lives here and is inherited.
mold
];
# Library path for runtime
runtimeLibraryPath = pkgs.lib.makeLibraryPath [
pkgs.wayland
pkgs.libxkbcommon
pkgs.vulkan-loader
pkgs.xorg.libX11
pkgs.xorg.libxcb
pkgs.openssl
pkgs.libgit2
pkgs.libssh2
pkgs.dbus
pkgs.zstd
pkgs.sqlite
pkgs.curl
];
# Full source including resources
fullSrc = pkgs.lib.cleanSourceWith {
src = ./.;
filter =
path: type:
(builtins.match ".*\\.git$" path) == null
&& (builtins.match ".*flake\\.nix$" path) == null
&& (builtins.match ".*flake\\.lock$" path) == null
&& (builtins.match ".*shell\\.nix$" path) == null
&& (builtins.match ".*default\\.nix$" path) == null
&& (builtins.match ".*\\.envrc$" path) == null
&& (builtins.match ".*\\.direnv$" path) == null
&& (builtins.match ".*target$" path) == null;
};
# Post-install script to copy resources
postInstallScript = ''
mkdir -p $out/share/applications
mkdir -p $out/share/icons/hicolor/scalable/apps
mkdir -p $out/share/mime/packages
mkdir -p $out/share/dbflux
# cargo always emits a binary named `dbflux`; rename it for non-stable
# channels so two channels can coexist in one profile.
${pkgs.lib.optionalString isNightly "mv $out/bin/dbflux $out/bin/${appId}"}
# Copy desktop file and resolve the templated placeholders
install -Dm644 ${fullSrc}/resources/desktop/dbflux.desktop $out/share/applications/${appId}.desktop
substituteInPlace $out/share/applications/${appId}.desktop \
--replace '@EXEC_PATH@' "$out/bin/${appId}" \
--replace '@APP_NAME@' '${appName}' \
--replace '@APP_ID@' '${appId}'
# Copy icon
install -Dm644 ${fullSrc}/resources/branding/${brandDir}/mark.svg $out/share/icons/hicolor/scalable/apps/${appId}.svg
# Copy mime type
install -Dm644 ${fullSrc}/resources/mime/dbflux-sql.xml $out/share/mime/packages/${appId}-sql.xml
substituteInPlace $out/share/mime/packages/${appId}-sql.xml \
--replace '@APP_ID@' '${appId}'
# Copy resources (with proper permissions)
cp -r --no-preserve=mode ${fullSrc}/resources $out/share/dbflux/
chmod -R u+w $out/share/dbflux/resources
# Copy scripts
mkdir -p $out/share/dbflux/scripts
cp -r --no-preserve=mode ${fullSrc}/scripts/* $out/share/dbflux/scripts/ 2>/dev/null || true
chmod -R u+w $out/share/dbflux/scripts 2>/dev/null || true
# Wrap binary with LD_LIBRARY_PATH for Wayland/Vulkan/X11
# Include common system paths for GPU drivers on non-NixOS systems
wrapProgram $out/bin/${appId} \
--prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}" \
--suffix LD_LIBRARY_PATH : "/run/opengl-driver/lib:/usr/lib/x86_64-linux-gnu:/usr/lib64:/usr/lib"
'';
# Build with crane (for flake usage)
buildWithCrane =
craneLib:
let
commonArgs = {
src = fullSrc;
inherit buildInputs nativeBuildInputs;
strictDeps = true;
ZSTD_SYS_USE_PKG_CONFIG = "1";
};
cargoArtifacts = craneLib.buildDepsOnly (
commonArgs
// {
pname = "dbflux-deps";
inherit version;
}
);
in
craneLib.buildPackage (
commonArgs
// {
pname = appId;
inherit version cargoArtifacts;
cargoExtraArgs = "-p dbflux";
postInstall = postInstallScript;
meta.mainProgram = appId;
}
);
# Build with rustPlatform (for non-flake usage)
buildWithRustPlatform = pkgs.rustPlatform.buildRustPackage {
pname = appId;
inherit version;
src = fullSrc;
cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};
inherit buildInputs nativeBuildInputs;
ZSTD_SYS_USE_PKG_CONFIG = "1";
cargoBuildFlags = [
"-p"
"dbflux"
];
cargoTestFlags = [
"-p"
"dbflux"
];
postInstall = postInstallScript;
postFixup = ''
wrapProgram $out/bin/${appId} \
--prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}" \
--suffix LD_LIBRARY_PATH : "/run/opengl-driver/lib:/usr/lib/x86_64-linux-gnu:/usr/lib64:/usr/lib"
'';
meta = with pkgs.lib; {
description = "A fast, keyboard-first database client";
homepage = "https://github.com/0xErwin1/dbflux";
license = with licenses; [
mit
asl20
];
maintainers = [ ];
platforms = platforms.linux;
mainProgram = appId;
};
};
in
{
inherit
buildInputs
nativeBuildInputs
runtimeLibraryPath
fullSrc
;
inherit buildWithCrane buildWithRustPlatform;
# Default package (non-flake)
package = buildWithRustPlatform;
# Development shell
shell =
let
rustToolchainInputs =
if pkgs ? rust-bin then
[
(pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"rust-analyzer"
];
})
]
else
[
pkgs.rustc
pkgs.cargo
];
in
pkgs.mkShell {
nativeBuildInputs =
nativeBuildInputs
++ rustToolchainInputs
++ [
pkgs.rust-analyzer
pkgs.python3
# Faster, process-isolated test runner: `cargo nextest run`.
# (mold is already provided via nativeBuildInputs above.)
pkgs.cargo-nextest
];
inherit buildInputs;
# Include system GPU driver paths for non-NixOS systems
LD_LIBRARY_PATH = pkgs.lib.concatStringsSep ":" [
runtimeLibraryPath
"/run/opengl-driver/lib"
"/usr/lib/x86_64-linux-gnu"
"/usr/lib64"
"/usr/lib"
];
ZSTD_SYS_USE_PKG_CONFIG = "1";
shellHook = ''
echo "DBFlux development environment loaded"
echo "Run 'cargo build' to build the project"
echo "Run 'nix-build' to build the package"
'';
};
}