-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
161 lines (135 loc) · 5.05 KB
/
flake.nix
File metadata and controls
161 lines (135 loc) · 5.05 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
{
description = "Jambi - a blazing-fast voice transcription application built with Rust";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, rust-overlay, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
# Rust toolchain
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "clippy" "rustfmt" ];
};
# Vosk library - fetch as a fixed-output derivation
voskVersion = "0.3.45";
voskLibrary = pkgs.fetchzip {
url = "https://github.com/alphacep/vosk-api/releases/download/v${voskVersion}/vosk-linux-x86_64-${voskVersion}.zip";
sha256 = "sha256-ToMDbD5ooFMHU0nNlfpLynF29kkfMknBluKO5PipLFY="; # You'll need to update this
stripRoot = true;
};
# Build inputs
commonBuildInputs = with pkgs; [
# Audio libraries
alsa-lib
pulseaudio
jack2
# System libraries
openssl
pkg-config
stdenv.cc.cc
bzip2
# Runtime dependencies
sox
wl-clipboard
xclip
libnotify
];
# Build jambi
jambi = pkgs.rustPlatform.buildRustPackage {
pname = "jambi";
version = "0.1.0";
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = with pkgs; [
rustToolchain
pkg-config
makeWrapper
];
buildInputs = commonBuildInputs;
# Set up vosk library before build
preBuild = ''
export VOSK_LIB_DIR="${voskLibrary}"
export RUSTFLAGS="-L ${voskLibrary}"
export LD_LIBRARY_PATH="${voskLibrary}:$LD_LIBRARY_PATH"
'';
# Environment variables for build
PKG_CONFIG_PATH = "${pkgs.lib.makeSearchPath "lib/pkgconfig" commonBuildInputs}";
# Wrap binary with runtime dependencies and vosk library
postInstall = ''
# Copy vosk library to output
mkdir -p $out/lib
cp $VOSK_LIB_DIR/libvosk.so $out/lib/
wrapProgram $out/bin/jambi \
--prefix PATH : ${pkgs.lib.makeBinPath (with pkgs; [ sox wl-clipboard xclip ])} \
--prefix LD_LIBRARY_PATH : "$out/lib:${pkgs.stdenv.cc.cc.lib}/lib" \
--set ALSA_PCM_CARD default \
--set ALSA_PCM_DEVICE 0
'';
meta = with pkgs.lib; {
description = "Fast Voice Transcription with Vosk";
homepage = "https://github.com/guttermonk/jambi";
license = with licenses; [ mit asl20 ];
maintainers = [ ];
platforms = platforms.linux;
};
};
in
{
# Default package
packages.default = jambi;
packages.jambi = jambi;
# Development shell
devShells.default = pkgs.mkShell {
buildInputs = commonBuildInputs ++ (with pkgs; [
rustToolchain
rust-analyzer
bacon
cargo-watch
gdb
wget
unzip
]);
PKG_CONFIG_PATH = "${pkgs.lib.makeSearchPath "lib/pkgconfig" commonBuildInputs}";
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
RUST_BACKTRACE = "1";
ALSA_PCM_CARD = "default";
ALSA_PCM_DEVICE = "0";
# Setup vosk for development
shellHook = ''
echo "🎙️ Jambi Development Environment"
echo "Rust version: $(rustc --version)"
# Download vosk for development if needed
VOSK_VERSION="0.3.45"
VOSK_DEV_DIR="$HOME/.cache/vosk"
if [ ! -f "$VOSK_DEV_DIR/libvosk.so" ]; then
echo "Setting up Vosk library for development..."
mkdir -p "$VOSK_DEV_DIR"
wget -q "https://github.com/alphacep/vosk-api/releases/download/v$VOSK_VERSION/vosk-linux-x86_64-$VOSK_VERSION.zip" -O "/tmp/vosk.zip"
unzip -q "/tmp/vosk.zip" -d "/tmp"
cp "/tmp/vosk-linux-x86_64-$VOSK_VERSION/libvosk.so" "$VOSK_DEV_DIR/"
rm -rf "/tmp/vosk.zip" "/tmp/vosk-linux-x86_64-$VOSK_VERSION"
echo "Vosk library installed to $VOSK_DEV_DIR"
fi
export RUSTFLAGS="-L $VOSK_DEV_DIR"
export LD_LIBRARY_PATH="$VOSK_DEV_DIR:$LD_LIBRARY_PATH"
echo "Run 'cargo run' to start jambi"
'';
};
# App for `nix run`
apps.default = {
type = "app";
program = "${self.packages.${system}.default}/bin/jambi";
};
# Formatter
formatter = pkgs.nixpkgs-fmt;
}
);
}