-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
273 lines (223 loc) · 7.96 KB
/
Copy pathflake.nix
File metadata and controls
273 lines (223 loc) · 7.96 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
{
description = "HyperWhisper - Type 3x faster, without lifting a finger";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
};
# Runtime dependencies
runtimeDeps = with pkgs; [
webkitgtk_4_1
gtk3
glib
gdk-pixbuf
cairo
pango
harfbuzz
librsvg
libsoup_3
openssl
alsa-lib
libxkbcommon
# GStreamer for audio/video
gst_all_1.gstreamer
gst_all_1.gst-plugins-base
gst_all_1.gst-plugins-good
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-ugly
gst_all_1.gst-libav
gst_all_1.gst-vaapi
# For typing text
wtype
ydotool
# ONNX Runtime for local transcription
onnxruntime
];
# Build dependencies
buildDeps = with pkgs; [
pkg-config
gobject-introspection
cmake
clang
llvmPackages.libclang
# Vulkan for whisper-rs GPU acceleration
vulkan-headers
vulkan-loader
shaderc
# ONNX Runtime for whisper/moonshine models
onnxruntime
];
# Fetch node_modules as a fixed-output derivation
nodeModules = pkgs.stdenv.mkDerivation {
pname = "hyperwhisper-node-modules";
version = "0.1.0";
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
let baseName = baseNameOf path;
in baseName == "package.json" || baseName == "bun.lockb" || baseName == "bun.lock";
};
nativeBuildInputs = [ pkgs.bun pkgs.cacert ];
buildPhase = ''
export HOME=$(mktemp -d)
bun install --frozen-lockfile
'';
installPhase = ''
mkdir -p $out
cp -r node_modules $out/
'';
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "sha256-3Mbrhp7OEQQIPt8ZYVo0P0CYrgIcpCLgePjgaVXuz1Q=";
};
# Fetch cargo dependencies
# To update this hash after changing Cargo.toml: set to "" and run `nix build`, then copy the "got:" hash
cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
src = ./src-tauri;
hash = "sha256-jj1Rov0DgulNQDFSwc95Vr7o1wDntAEKMbSebc0GZl0=";
};
# Build the frontend
frontend = pkgs.stdenv.mkDerivation {
pname = "hyperwhisper-frontend";
version = "0.1.0";
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
let
baseName = baseNameOf path;
relativePath = pkgs.lib.removePrefix (toString ./. + "/") path;
in
# Include frontend source files
baseName == "package.json"
|| baseName == "tsconfig.json"
|| baseName == "tsconfig.node.json"
|| baseName == "vite.config.ts"
|| baseName == "index.html"
|| pkgs.lib.hasPrefix "src/" relativePath
|| baseName == "src"
|| baseName == "components.json";
};
nativeBuildInputs = [ pkgs.bun pkgs.nodejs-slim ];
buildPhase = ''
export HOME=$(mktemp -d)
# Copy node_modules (need writable copy to patch shebangs)
cp -r ${nodeModules}/node_modules node_modules
chmod -R u+w node_modules
# Patch shebangs in node_modules binaries
patchShebangs node_modules
# Build using bun directly instead of npm scripts
./node_modules/.bin/tsc
./node_modules/.bin/vite build
'';
installPhase = ''
mkdir -p $out
cp -r dist/* $out/
'';
};
in
{
packages.default = pkgs.stdenv.mkDerivation {
pname = "hyperwhisper";
version = "0.1.0";
src = pkgs.lib.cleanSource ./.;
nativeBuildInputs = buildDeps ++ (with pkgs; [
makeWrapper
rustToolchain
cargo-tauri
]);
buildInputs = runtimeDeps ++ (with pkgs; [
at-spi2-atk
atkmm
]);
# Environment variables for build
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
ORT_LIB_LOCATION = "${pkgs.onnxruntime}/lib";
# Don't run cmake configure phase
dontUseCmakeConfigure = true;
buildPhase = ''
runHook preBuild
# Copy frontend dist
mkdir -p dist
cp -r ${frontend}/* dist/
# Debug: show what's in dist
echo "Frontend dist contents:"
ls -la dist/
# Generate icons from logo.png
echo "Generating icons from logo.png..."
cargo tauri icon logo.png
# Setup cargo vendor directory
mkdir -p .cargo
cat > .cargo/config.toml <<EOF
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "${cargoDeps}"
EOF
# Also put cargo config in src-tauri
mkdir -p src-tauri/.cargo
cp .cargo/config.toml src-tauri/.cargo/
# Build using cargo-tauri for proper frontend embedding
# Skip the beforeBuildCommand since we already built the frontend
export TAURI_SKIP_DEVSERVER_CHECK=true
# Use cargo tauri build which properly embeds frontend
# Pass --ci to skip prompts, --no-bundle to skip packaging
# Override config to skip beforeBuildCommand (frontend already built)
cargo tauri build --no-bundle --ci --config '{"build":{"beforeBuildCommand":""}}' -- --offline
echo "Build complete, checking for binary:"
ls -la src-tauri/target/release/
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp src-tauri/target/release/hyperwhisper $out/bin/
wrapProgram $out/bin/hyperwhisper \
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath runtimeDeps}" \
--prefix PATH : "${pkgs.lib.makeBinPath [ pkgs.wtype pkgs.ydotool ]}"
runHook postInstall
'';
meta = with pkgs.lib; {
description = "Type 3x faster, without lifting a finger";
homepage = "https://github.com/hyperwhisper/app";
license = licenses.gpl3Plus;
maintainers = [ ];
platforms = platforms.linux;
mainProgram = "hyperwhisper";
};
};
# Expose nodeModules for hash updating
packages.nodeModules = nodeModules;
devShells.default = pkgs.mkShell {
nativeBuildInputs = buildDeps ++ (with pkgs; [
rustToolchain
cargo-tauri
bun
nodejs-slim
]);
buildInputs = runtimeDeps ++ (with pkgs; [
at-spi2-atk
atkmm
]);
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath runtimeDeps;
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
shellHook = ''
echo "HyperWhisper development environment"
echo "Run 'bun run tauri dev' to start development"
'';
};
}
);
}