Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
494 lines (456 loc) · 18.3 KB
/
Copy pathflake.nix
File metadata and controls
494 lines (456 loc) · 18.3 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
{
description = "A native, familiar music streaming client";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
rust-overlay,
...
}:
let
inherit (nixpkgs) lib;
forEachSystem =
fn:
lib.genAttrs lib.systems.flakeExposed (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
in
fn pkgs
);
release = {
version = "0.48.1";
assets = {
x86_64-linux = {
target = "x86_64-unknown-linux-gnu";
hash = "sha256-NtES2hlXk5piA+vwnmg3LXiIO9y5wlFkdrMHHQCqFU4=";
};
aarch64-linux = {
target = "aarch64-unknown-linux-gnu";
hash = "sha256-fpBU6OlWnxuZYCGn7mafz+vLJTLUX+pzx3obpVLrx5g=";
};
aarch64-darwin = {
target = "macos";
hash = "sha256-sKA7pCS5yFBaPSpLeBtv1bpGxrMihJmw5Z6b3Rg8P3A=";
};
};
};
# The nightly prerelease, in the same shape as `release` plus its tag. Only the commit the
# nightly workflow tags `nightly` carries this file, so `github:sonorahq/sonora/nightly` is
# the one flake ref that installs it.
nightly = lib.optionalAttrs (builtins.pathExists ./nix/nightly.json) (
lib.importJSON ./nix/nightly.json
);
in
{
packages = forEachSystem (
pkgs:
let
runtimeLibraries =
with pkgs;
if pkgs.stdenv.hostPlatform.isLinux then
[
vulkan-loader
wayland
libxkbcommon
libxcb
libx11
libxcursor
libxi
fontconfig
freetype
alsa-lib
dbus
sqlite
webkitgtk_4_1
glib-networking
]
else
[ ];
inherit (pkgs.stdenv.hostPlatform) system;
# WebKit plays a page's media through GStreamer and aborts its web process when no
# audio sink element exists. The Nix webkitgtk closure carries only core and base, and
# autoaudiosink lives in good, so the plugin path has to name all three.
gstPluginPath = pkgs.lib.makeSearchPathOutput "lib" "lib/gstreamer-1.0" (
with pkgs.gst_all_1;
[
gstreamer
gst-plugins-base
gst-plugins-good
]
);
alsaPluginDirectory = pkgs.symlinkJoin {
name = "sonora-alsa-plugins";
paths = [
"${pkgs.pipewire}/lib/alsa-lib"
"${pkgs.alsa-plugins}/lib/alsa-lib"
];
};
# The source build uses the toolchain the devShell and CI pin, not whatever rustc
# nixpkgs carries that day.
rustPlatform =
let
toolchain =
pkgs.rust-bin.stable.${(lib.importTOML ./rust-toolchain.toml).toolchain.channel}.minimal;
in
pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
# Points the Linux binary at its runtime libraries and environment. Both packages run
# it, since webkitgtk and the GPU and audio stacks are opened with dlopen and never
# show up as link-time dependencies.
linuxFixup = lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
patchelf \
--set-interpreter "${pkgs.stdenv.cc.bintools.dynamicLinker}" \
--add-rpath "${lib.makeLibraryPath (runtimeLibraries ++ [ pkgs.stdenv.cc.cc.lib ])}" \
"$out/bin/sonora"
wrapProgram "$out/bin/sonora" \
--set ALSA_PLUGIN_DIR ${alsaPluginDirectory} \
--prefix GIO_EXTRA_MODULES : ${pkgs.glib-networking}/lib/gio/modules \
--prefix GST_PLUGIN_SYSTEM_PATH_1_0 : ${gstPluginPath}
'';
sonora-src = rustPlatform.buildRustPackage (final: {
pname = "sonora";
inherit ((lib.importTOML (final.src + /Cargo.toml)).workspace.package) version;
src = ./.;
cargoLock = {
lockFile = final.src + /Cargo.lock;
allowBuiltinFetchGit = true;
};
cargoBuildFlags = [
"--package"
"sonora"
];
doCheck = false;
dontCargoUseSystemLibs = true;
nativeBuildInputs =
with pkgs;
lib.flatten [
cmake
pkg-config
(lib.optionals stdenv.hostPlatform.isLinux [
makeWrapper
mold
])
(lib.optionals stdenv.hostPlatform.isDarwin [
(
let
pkgs' = import nixpkgs {
inherit (stdenv.hostPlatform) system;
config.allowUnfree = true;
};
in
runCommandLocal "metal-shader-compiler" { } ''
mkdir -p "$out/bin"
ln -s ${pkgs'.darwin.xcode}/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/metal "$out/bin/metal"
ln -s ${pkgs'.darwin.xcode}/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/metallib "$out/bin/metallib"
''
)
])
];
buildInputs =
with pkgs;
lib.flatten [
sqlite
(lib.optionals stdenv.hostPlatform.isLinux [
dbus
fontconfig
libxcb
libxkbcommon
libx11
pipewire
stdenv.cc.cc.lib
(alsa-lib-with-plugins.override {
plugins = [
alsa-plugins
pipewire
];
})
])
(lib.optionals stdenv.hostPlatform.isDarwin [
apple-sdk_15
(darwinMinVersionHook "10.15")
])
];
installPhase = ''
runHook preInstall
install -Dm755 "target/${pkgs.stdenv.hostPlatform.rust.cargoShortTarget}/$cargoBuildType/sonora" "$out/bin/sonora"
${
if pkgs.stdenv.hostPlatform.isDarwin then
''
install -Dm755 "target/${pkgs.stdenv.hostPlatform.rust.cargoShortTarget}/$cargoBuildType/sonora" "$out/Applications/Sonora.app/Contents/MacOS/sonora"
install -Dm444 "$src/assets/macos/sonora.icns" \
"$out/Applications/Sonora.app/Contents/Resources/sonora.icns"
sed \
"s/@VERSION@/$version/g" \
"$src/assets/macos/Info.plist" \
> "$out/Applications/Sonora.app/Contents/Info.plist"
LICENSE_DIR="$out/Applications/Sonora.app/Contents/Resources"
''
else
''
install -Dm444 "$src/assets/linux/sonora.desktop" \
"$out/share/applications/sonora.desktop"
install -Dm444 "$src/assets/linux/sonora.svg" \
"$out/share/icons/hicolor/scalable/apps/sonora.svg"
for icon in "$src"/assets/linux/icons/hicolor/*/apps/sonora.png; do
size="$(basename "$(dirname "$(dirname "$icon")")")"
install -Dm444 "$icon" \
"$out/share/icons/hicolor/$size/apps/sonora.png"
done
LICENSE_DIR="$out/share/licenses/sonora"
''
}
install -Dm444 "$src/COPYING" "$LICENSE_DIR/LICENSE"
install -Dm444 "$src/THIRD-PARTY.md" "$LICENSE_DIR/THIRD-PARTY.md"
install -Dm444 "$src/assets/fonts/LICENSE.txt" \
"$LICENSE_DIR/sonora/LICENSE.Inter"
for licence in "$src/assets/icons"/*/LICENSE; do
pack="$(basename "$(dirname "$licence")")"
install -Dm444 "$licence" \
"$LICENSE_DIR/icons/LICENSE.$pack"
done
install -Dm444 "$src/assets/icons/LICENSE" \
"$LICENSE_DIR/icons/LICENSE"
runHook postInstall
'';
postFixup = linuxFixup;
inherit meta;
});
meta = {
description = "A native, familiar music streaming client";
mainProgram = "sonora";
license = with lib.licenses; [
gpl3Plus
ofl
isc
];
platforms = lib.platforms.linux ++ lib.platforms.darwin;
};
# Installs the binaries a GitHub release publishes under `tag`. Every asset is named
# `sonora-<tag>-<target>`, and `assets` maps a Nix system to its target and hash.
prebuilt =
{
pname,
version,
tag,
assets,
}:
let
asset = assets.${system};
in
pkgs.stdenv.mkDerivation {
inherit pname version meta;
src = pkgs.fetchurl {
url = "https://github.com/sonorahq/sonora/releases/download/${tag}/sonora-${tag}-${asset.target}${
if pkgs.stdenv.hostPlatform.isDarwin then ".dmg" else ""
}";
inherit (asset) hash;
};
dontUnpack = true;
dontStrip = true;
nativeBuildInputs =
lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.makeWrapper ]
++ lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
pkgs.makeBinaryWrapper
pkgs.undmg
];
installPhase =
if pkgs.stdenv.hostPlatform.isLinux then
''
runHook preInstall
install -Dm755 "$src" "$out/bin/sonora"
${lib.optionalString (tag == "nightly") ''
mkdir -p "$out/lib/sonora"
cp ${
pkgs.writeText "sonora-build.json" (
builtins.toJSON {
inherit version;
channel = "nightly";
}
)
} "$out/lib/sonora/build.json"
''}
install -Dm444 ${./assets/linux/sonora.desktop} \
"$out/share/applications/sonora.desktop"
install -Dm444 ${./assets/linux/sonora.svg} \
"$out/share/icons/hicolor/scalable/apps/sonora.svg"
for icon in ${./assets/linux/icons}/hicolor/*/apps/sonora.png; do
size="$(basename "$(dirname "$(dirname "$icon")")")"
install -Dm444 "$icon" \
"$out/share/icons/hicolor/$size/apps/sonora.png"
done
install -Dm444 ${./COPYING} "$out/share/licenses/sonora/LICENSE"
install -Dm444 ${./THIRD-PARTY.md} "$out/share/licenses/sonora/THIRD-PARTY.md"
install -Dm444 ${./assets/fonts/LICENSE.txt} \
"$out/share/licenses/sonora/LICENSE.Inter"
for licence in ${./assets/icons}/*/LICENSE; do
pack="$(basename "$(dirname "$licence")")"
install -Dm444 "$licence" \
"$out/share/licenses/sonora/icons/LICENSE.$pack"
done
install -Dm444 ${./assets/icons/LICENSE} \
"$out/share/licenses/sonora/icons/LICENSE"
runHook postInstall
''
else
''
runHook preInstall
mnt="$(mktemp -d)"
/usr/bin/hdiutil attach -readonly -nobrowse -mountpoint "$mnt" "$src"
mkdir -p "$out/Applications" "$out/bin"
cp -R "$mnt/Sonora.app" "$out/Applications/Sonora.app"
/usr/bin/hdiutil detach "$mnt"
makeBinaryWrapper \
"$out/Applications/Sonora.app/Contents/MacOS/sonora" \
"$out/bin/sonora"
runHook postInstall
'';
postFixup = linuxFixup;
};
sonora-bin = prebuilt {
pname = "sonora-bin";
inherit (release) version assets;
tag = "v${release.version}";
};
sonora-nightly = prebuilt {
pname = "sonora-nightly";
inherit (nightly) version tag assets;
};
in
# `default` and `sonora` resolve to the release binary wherever one is published and to
# the source build elsewhere. `sonora-src` and `sonora-bin` always mean one or the other.
# At the `nightly` tag both resolve to the nightly binary instead.
{
inherit sonora-src;
sonora = sonora-src;
default = sonora-src;
}
// lib.optionalAttrs (builtins.hasAttr system release.assets) {
inherit sonora-bin;
sonora = sonora-bin;
default = sonora-bin;
}
// lib.optionalAttrs (nightly ? assets && builtins.hasAttr system nightly.assets) {
inherit sonora-nightly;
sonora = sonora-nightly;
default = sonora-nightly;
}
);
devShells = forEachSystem (
pkgs:
let
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
runtimeLibraries =
with pkgs;
if pkgs.stdenv.hostPlatform.isLinux then
[
vulkan-loader
wayland
libxkbcommon
libxcb
libx11
libxcursor
libxi
fontconfig
freetype
alsa-lib
dbus
sqlite
openssl
webkitgtk_4_1
glib-networking
]
else
[ ];
# Apple's own xcrun, so `xcrun metal` can reach the Metal toolchain that
# Xcode 26 mounts outside DEVELOPER_DIR. The xcbuild shim the Apple SDK
# drags onto PATH cannot, and neither can any xcrun pointed at the Nix SDK.
xcodeXcrun = pkgs.runCommandLocal "xcode-xcrun" { } ''
mkdir -p $out/bin
ln -s /usr/bin/xcrun $out/bin/xcrun
'';
in
{
default = pkgs.mkShell {
nativeBuildInputs =
(with pkgs; [
pkg-config
cmake
rustToolchain
sccache
])
++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.mold ];
buildInputs = runtimeLibraries;
LD_LIBRARY_PATH = lib.makeLibraryPath runtimeLibraries;
ALSA_PLUGIN_DIR =
if pkgs.stdenv.hostPlatform.isLinux then
"${pkgs.symlinkJoin {
name = "alsa-plugins-combined";
paths = [
"${pkgs.alsa-plugins}/lib/alsa-lib"
"${pkgs.pipewire}/lib/alsa-lib"
];
}}"
else
"";
shellHook =
# WebKit composites through EGL, which has to find the same drivers.
pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
if [ ! -d /run/opengl-driver ]; then
export VK_DRIVER_FILES="${pkgs.mesa}/share/vulkan/icd.d"
export VK_IMPLICIT_LAYER_PATH="${pkgs.mesa}/share/vulkan/implicit_layer.d"
export __EGL_VENDOR_LIBRARY_DIRS="${pkgs.mesa}/share/glvnd/egl_vendor.d"
export LIBGL_DRIVERS_PATH="${pkgs.mesa}/lib/dri"
export GBM_BACKENDS_PATH="${pkgs.mesa}/lib/gbm"
fi
export GIO_EXTRA_MODULES="${pkgs.glib-networking}/lib/gio/modules''${GIO_EXTRA_MODULES:+:$GIO_EXTRA_MODULES}"
export GST_PLUGIN_SYSTEM_PATH_1_0="${
pkgs.lib.makeSearchPathOutput "lib" "lib/gstreamer-1.0" (
with pkgs.gst_all_1;
[
gstreamer
gst-plugins-base
gst-plugins-good
]
)
}''${GST_PLUGIN_SYSTEM_PATH_1_0:+:$GST_PLUGIN_SYSTEM_PATH_1_0}"
''
# gpui_apple compiles its shaders with `xcrun -sdk macosx metal` at build
# time. The Nix Apple SDK has no Metal toolchain, so hand xcrun back to the
# installed Xcode. Clang follows DEVELOPER_DIR too and then reads Xcode's C
# headers beside the Nix libc++, which breaks any C++ a build script compiles,
# so C++ compiles are pinned to the Nix SDK through CXXFLAGS. Only compiles: the
# link still has to see Xcode's SDK, which is where libsqlite3 comes from.
+ lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
# xcode-select echoes DEVELOPER_DIR back when it is set, so ask with it unset.
if xcode="$(env -u DEVELOPER_DIR /usr/bin/xcode-select -p 2>/dev/null)"; then
export DEVELOPER_DIR="$xcode"
export PATH="${xcodeXcrun}/bin:$PATH"
export CXXFLAGS="''${CXXFLAGS:-} -isysroot $SDKROOT"
fi
'';
};
}
);
overlays.default = final: _prev: {
sonora = self.packages.${final.stdenv.hostPlatform.system}.default;
};
homeManagerModules = {
default = import ./nix/modules/hm-module.nix self;
sonora = import ./nix/modules/hm-module.nix self;
};
homeModules = self.homeManagerModules;
};
}