-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathflake.nix
More file actions
272 lines (251 loc) · 9.09 KB
/
Copy pathflake.nix
File metadata and controls
272 lines (251 loc) · 9.09 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
{
description = "Sonora - a native 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
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
forEachSystem =
fn:
nixpkgs.lib.genAttrs systems (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
in
fn pkgs
);
release = {
version = "0.32.0";
assets = {
x86_64-linux = {
target = "x86_64-unknown-linux-gnu";
hash = "sha256-Ezlc1ORI/UrMN/KppR//Y/6lZ8CgGY/ap0R+PXFUnD4=";
};
aarch64-linux = {
target = "aarch64-unknown-linux-gnu";
hash = "sha256-roHKrJfF5U9BjpWvU2cWqwvXYOHDqQRjUlhk29WFVtA=";
};
aarch64-darwin = {
target = "macos";
hash = "sha256-6MAj6q547yDmdzqJIyufWzuyhibqAj556fnJIcndnQ8=";
};
};
};
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
]
else
[ ];
asset = release.assets.${pkgs.stdenv.hostPlatform.system};
alsaPluginDirectory = pkgs.symlinkJoin {
name = "sonora-alsa-plugins";
paths = [
"${pkgs.pipewire}/lib/alsa-lib"
"${pkgs.alsa-plugins}/lib/alsa-lib"
];
};
sonora-bin = pkgs.stdenv.mkDerivation {
pname = "sonora-bin";
inherit (release) version;
src = pkgs.fetchurl {
url = "https://github.com/sonorahq/sonora/releases/download/v${release.version}/sonora-v${release.version}-${asset.target}${
if pkgs.stdenv.hostPlatform.isDarwin then ".dmg" else ""
}";
inherit (asset) hash;
};
dontUnpack = true;
dontStrip = true;
nativeBuildInputs =
pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.makeWrapper ]
++ pkgs.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"
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 = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
patchelf \
--set-interpreter "${pkgs.stdenv.cc.bintools.dynamicLinker}" \
--add-rpath "${pkgs.lib.makeLibraryPath (runtimeLibraries ++ [ pkgs.stdenv.cc.cc.lib ])}" \
"$out/bin/sonora"
wrapProgram "$out/bin/sonora" \
--set ALSA_PLUGIN_DIR ${alsaPluginDirectory}
'';
meta = {
description = "A native music streaming client, built with Rust and GPUI";
mainProgram = "sonora";
license = with pkgs.lib.licenses; [
gpl3Plus
ofl
isc
];
platforms =
if pkgs.stdenv.hostPlatform.isLinux then pkgs.lib.platforms.linux else pkgs.lib.platforms.darwin;
};
};
in
{
inherit sonora-bin;
sonora = sonora-bin;
default = sonora-bin;
}
);
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
]
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
])
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.mold ];
buildInputs = runtimeLibraries;
LD_LIBRARY_PATH = pkgs.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 =
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"
fi
''
# 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; the Nix clang keeps building against SDKROOT regardless.
+ pkgs.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"
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;
};
}