|
9 | 9 | let |
10 | 10 | supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; |
11 | 11 | 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 { |
13 | 16 | inherit system; |
14 | | - config.allowUnfree = true; |
15 | 17 | 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 []))); |
16 | 28 | }); |
17 | 29 | in |
18 | 30 | { |
19 | 31 | packages = forAllSystems (system: |
20 | 32 | 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 | | - |
29 | 33 | # 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 |
31 | 43 | pkgs.stdenv.mkDerivation { |
32 | 44 | pname = "audio.cpp"; |
33 | 45 | version = self.shortRev or self.dirtyShortRev or "dirty"; |
|
38 | 50 | cmake |
39 | 51 | ninja |
40 | 52 | pkg-config |
41 | | - makeWrapper |
42 | 53 | ] ++ pkgs.lib.optional cudaSupport pkgs.cudaPackages.cuda_nvcc; |
43 | 54 |
|
44 | 55 | buildInputs = with pkgs; [ |
45 | | - libunwind |
46 | 56 | myPython |
47 | 57 | ] ++ pkgs.lib.optionals vulkanSupport [ |
48 | 58 | vulkan-headers |
|
53 | 63 | ] ++ pkgs.lib.optionals cudaSupport [ |
54 | 64 | pkgs.cudaPackages.cudatoolkit |
55 | 65 | ] ++ 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 |
60 | 67 | ]; |
61 | 68 |
|
62 | 69 | cmakeFlags = [ |
|
72 | 79 |
|
73 | 80 | mkdir -p $out/bin |
74 | 81 | |
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/ |
77 | 84 |
|
78 | 85 | # Install the python model manager script |
79 | 86 | cp $src/tools/model_manager.py $out/bin/audiocpp_model_manager |
|
96 | 103 | in |
97 | 104 | { |
98 | 105 | # 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 | + } // { |
104 | 113 | # 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; |
106 | 115 | } |
107 | 116 | ); |
108 | 117 |
|
109 | 118 | devShells = forAllSystems (system: |
110 | | - let |
111 | | - pkgs = nixpkgsFor.${system}; |
112 | | - in |
113 | 119 | { |
114 | | - default = pkgs.mkShell { |
| 120 | + default = pkgs.${system}.mkShell { |
115 | 121 | inputsFrom = [ self.packages.${system}.default ]; |
116 | 122 | }; |
| 123 | + } // pkgs.${system}.lib.optionalAttrs pkgs.${system}.stdenv.isLinux { |
| 124 | + cuda = pkgsCuda.${system}.mkShell { |
| 125 | + inputsFrom = [ self.packages.${system}.cuda ]; |
| 126 | + }; |
117 | 127 | } |
118 | 128 | ); |
119 | 129 | }; |
|
0 commit comments