Skip to content

Commit a28fa49

Browse files
authored
docs: point flake input to upstream repository and add flake.lock (#83)
* docs: point flake input to upstream repository * build(nix): address code review feedback on flake * build(nix): use specific torch variant depending on build flags * fix(nix): resolve undefined pkgs variable in flake evaluation * build(nix): remove internal allowUnfree to delegate permission to callers * build(nix): use allowUnfreePredicate for strict cuda license whitelisting * style(nix): rename nixpkgs instances to pkgs and pkgsCuda
2 parents 6d99340 + f512ab0 commit a28fa49

3 files changed

Lines changed: 67 additions & 30 deletions

File tree

docs/nixos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ In your `flake.nix`, add it to your `inputs`, making sure to use `follows` to av
8686
inputs = {
8787
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
8888
89-
audiocpp.url = "github:fedeizzo/audio.cpp";
89+
audiocpp.url = "github:0xShug0/audio.cpp";
9090
audiocpp.inputs.nixpkgs.follows = "nixpkgs";
9191
};
9292

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,37 @@
99
let
1010
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
1111
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
12-
nixpkgsFor = forAllSystems (system: import nixpkgs {
12+
pkgs = forAllSystems (system: import nixpkgs {
13+
inherit system;
14+
});
15+
pkgsCuda = forAllSystems (system: import nixpkgs {
1316
inherit system;
14-
config.allowUnfree = true;
1517
config.cudaSupport = true;
18+
config.allowUnfreePredicate = p:
19+
builtins.all (
20+
license:
21+
license.free
22+
|| builtins.elem license.shortName [
23+
"CUDA EULA"
24+
"cuDNN EULA"
25+
"cuSPARSELt EULA"
26+
]
27+
) (p.meta.licenses or (nixpkgs.lib.toList (p.meta.license or [])));
1628
});
1729
in
1830
{
1931
packages = forAllSystems (system:
2032
let
21-
pkgs = nixpkgsFor.${system};
22-
# Python environment for model_manager.py
23-
myPython = pkgs.python3.withPackages (ps: with ps; [
24-
torch
25-
safetensors
26-
pyyaml
27-
]);
28-
2933
# A function to build audio.cpp with any set of features
30-
mkAudioCpp = { cudaSupport ? false, vulkanSupport ? false, metalSupport ? pkgs.stdenv.isDarwin }:
34+
mkAudioCpp = { pkgs, cudaSupport ? false, vulkanSupport ? false, metalSupport ? pkgs.stdenv.isDarwin }:
35+
let
36+
# Python environment for model_manager.py
37+
myPython = pkgs.python3.withPackages (ps: with ps; [
38+
(if cudaSupport then ps.torchWithCuda else if vulkanSupport then ps.torchWithVulkan else ps.torch)
39+
ps.safetensors
40+
ps.pyyaml
41+
]);
42+
in
3143
pkgs.stdenv.mkDerivation {
3244
pname = "audio.cpp";
3345
version = self.shortRev or self.dirtyShortRev or "dirty";
@@ -38,11 +50,9 @@
3850
cmake
3951
ninja
4052
pkg-config
41-
makeWrapper
4253
] ++ pkgs.lib.optional cudaSupport pkgs.cudaPackages.cuda_nvcc;
4354

4455
buildInputs = with pkgs; [
45-
libunwind
4656
myPython
4757
] ++ pkgs.lib.optionals vulkanSupport [
4858
vulkan-headers
@@ -53,10 +63,7 @@
5363
] ++ pkgs.lib.optionals cudaSupport [
5464
pkgs.cudaPackages.cudatoolkit
5565
] ++ pkgs.lib.optionals metalSupport [
56-
darwin.apple_sdk.frameworks.Metal
57-
darwin.apple_sdk.frameworks.Foundation
58-
darwin.apple_sdk.frameworks.MetalPerformanceShaders
59-
darwin.apple_sdk.frameworks.Accelerate
66+
pkgs.apple-sdk_14
6067
];
6168

6269
cmakeFlags = [
@@ -72,8 +79,8 @@
7279
7380
mkdir -p $out/bin
7481
75-
# Find and copy the built C++ executables
76-
find . -type f -executable \( -name "audiocpp_cli" -o -name "audiocpp_server" -o -name "audiocpp_gguf" \) -exec cp {} $out/bin/ \;
82+
# Copy the built C++ executables directly from the bin directory
83+
cp bin/audiocpp_cli bin/audiocpp_server bin/audiocpp_gguf $out/bin/
7784
7885
# Install the python model manager script
7986
cp $src/tools/model_manager.py $out/bin/audiocpp_model_manager
@@ -96,24 +103,27 @@
96103
in
97104
{
98105
# Expose specific backend variants
99-
cpu = mkAudioCpp { cudaSupport = false; vulkanSupport = false; metalSupport = false; };
100-
vulkan = mkAudioCpp { vulkanSupport = true; cudaSupport = false; metalSupport = false; };
101-
cuda = mkAudioCpp { cudaSupport = true; vulkanSupport = false; metalSupport = false; };
102-
metal = mkAudioCpp { metalSupport = true; cudaSupport = false; vulkanSupport = false; };
103-
106+
cpu = mkAudioCpp { pkgs = pkgs.${system}; cudaSupport = false; vulkanSupport = false; metalSupport = false; };
107+
vulkan = mkAudioCpp { pkgs = pkgs.${system}; vulkanSupport = true; cudaSupport = false; metalSupport = false; };
108+
} // pkgs.${system}.lib.optionalAttrs pkgs.${system}.stdenv.isLinux {
109+
cuda = mkAudioCpp { pkgs = pkgsCuda.${system}; cudaSupport = true; vulkanSupport = false; metalSupport = false; };
110+
} // pkgs.${system}.lib.optionalAttrs pkgs.${system}.stdenv.isDarwin {
111+
metal = mkAudioCpp { pkgs = pkgs.${system}; metalSupport = true; cudaSupport = false; vulkanSupport = false; };
112+
} // {
104113
# Automatically select best default for the current platform
105-
default = if pkgs.stdenv.isDarwin then self.packages.${system}.metal else self.packages.${system}.vulkan;
114+
default = if pkgs.${system}.stdenv.isDarwin then self.packages.${system}.metal else self.packages.${system}.vulkan;
106115
}
107116
);
108117

109118
devShells = forAllSystems (system:
110-
let
111-
pkgs = nixpkgsFor.${system};
112-
in
113119
{
114-
default = pkgs.mkShell {
120+
default = pkgs.${system}.mkShell {
115121
inputsFrom = [ self.packages.${system}.default ];
116122
};
123+
} // pkgs.${system}.lib.optionalAttrs pkgs.${system}.stdenv.isLinux {
124+
cuda = pkgsCuda.${system}.mkShell {
125+
inputsFrom = [ self.packages.${system}.cuda ];
126+
};
117127
}
118128
);
119129
};

0 commit comments

Comments
 (0)