-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
192 lines (159 loc) · 5.57 KB
/
flake.nix
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
{
description = "stem-split";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
npmPackageSerokell = {
url = "github:serokell/nix-npm-buildpackage";
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane, npmPackageSerokell, ... }:
let
supportedSystems = [ "aarch64-darwin" ];
in
flake-utils.lib.eachSystem supportedSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
config = {
allowUnfree = true;
};
};
lib = pkgs.lib;
rustNightly = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer-preview" ];
targets = [ "x86_64-unknown-linux-gnu" ];
};
rustPlatform = pkgs.makeRustPlatform {
inherit (rustNightly) cargo rustc;
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustNightly;
libtorch = pkgs.callPackage (import ./nix/torch-bin.nix) { };
tauriConfFilter = path: _type: builtins.match ".*tauri\.conf\.json$" path != null;
othersFilter = path: _type: builtins.match ".*(json|ico|icns|png|toml)$" path != null;
srcFilter = path: type: (craneLib.filterCargoSources path type) || (tauriConfFilter path type) || (othersFilter path type);
cargoVendorDir = craneLib.vendorCargoDeps {
src = craneLib.cleanCargoSource (craneLib.path ./src-tauri);
};
npmPackage = pkgs.callPackage npmPackageSerokell { };
stemsplit-bin = craneLib.buildPackage {
src = lib.cleanSourceWith {
src = craneLib.path ./src-tauri; # The original, unfiltered source
filter = srcFilter;
};
doInstallCargoArtifacts = true;
cargoExtraArgs = "--config target.aarch64-apple-darwin.linker=\\'c++\\'";
LIBTORCH = "${libtorch}";
DYLD_LIBRARY_PATH = "${libtorch}/lib";
nativeBuildInputs = with pkgs; [
rustNightly
llvmPackages.libcxxStdenv
curl
protobuf
fftw
nodejs
pkg-config
cmake
fftw
];
buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin
(with pkgs; [
darwin.libobjc
]) ++ (with pkgs.darwin.apple_sdk.frameworks; [
Carbon
AudioUnit
WebKit
]);
};
stemsplit-models = pkgs.stdenv.mkDerivation {
name = "stemsplit-models";
src = pkgs.fetchzip {
url = "https://pub-20137d58397b4f8f8c86ff1a178685ff.r2.dev/models.zip";
hash = "sha256-xxOUkxHCNLjFKvsp6KphQ6AC1fghk4/AdkwRuxPJGrs=";
stripRoot = false;
};
installPhase = ''
cp -r $src $out
'';
};
stemsplit-dmg = npmPackage.buildNpmPackage {
src = lib.cleanSource ./.;
nativeBuildInputs = with pkgs; [
rustNightly
llvmPackages.libcxxStdenv
curl
protobuf
pkg-config
cmake
fftw
];
buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin
(with pkgs; [
darwin.libobjc
]) ++ (with pkgs.darwin.apple_sdk.frameworks; [
Carbon
AudioUnit
WebKit
]);
postConfigure = ''
${pkgs.zstd}/bin/zstd -d ${stemsplit-bin}/target.tar.zst --stdout | tar -xvf - -C ./src-tauri/
directory_line=$(grep "directory" ${cargoVendorDir}/config.toml)
vendor_dir=$(echo "$directory_line" | awk -F'=' '{print $2}' | tr -d '[:space:]' | tr -d '"')
echo $vendor_dir
cat <<DONE >> src-tauri/.cargo/config.toml
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "''$vendor_dir"
DONE
rm -rf src-tauri/models/
cp -r ${stemsplit-models}/models src-tauri/models
# '';
npmBuild = ''
export LIBTORCH="${libtorch}";
export DYLD_LIBRARY_PATH="${libtorch}/lib:$";
export STEMSPLIT_RESOURCES_PATH='../Resources/'
npm run tauri build -- --ci -- --offline || true
'';
installPhase = ''
mkdir -p $out/target
cp -r ./src-tauri/target/ $out/.
'';
};
in
{
devShell = pkgs.mkShell {
LIBTORCH = "${libtorch}";
nativeBuildInputs = with pkgs; [
rustNightly
llvmPackages.libcxxStdenv
llvmPackages.openmp
libtorch
curl
protobuf
pkg-config
cmake
fftw
];
buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin
(with pkgs; [
darwin.libobjc
]) ++ (with pkgs.darwin.apple_sdk.frameworks; [
Carbon
AudioUnit
WebKit
]);
};
defaultPackage = stemsplit-bin;
packages = {
inherit stemsplit-bin stemsplit-dmg stemsplit-models;
};
libtorch = libtorch;
});
}