diff --git a/docs/nixos.md b/docs/nixos.md index 7a8e3a882..5b771a4c2 100644 --- a/docs/nixos.md +++ b/docs/nixos.md @@ -86,7 +86,7 @@ In your `flake.nix`, add it to your `inputs`, making sure to use `follows` to av inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - audiocpp.url = "github:fedeizzo/audio.cpp"; + audiocpp.url = "github:0xShug0/audio.cpp"; audiocpp.inputs.nixpkgs.follows = "nixpkgs"; }; diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..fdfbda464 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1784497964, + "narHash": "sha256-vlHUuqAcbcH2RKmHbPiuQzbv1pnzzavXnI62RD0bqCU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "241313f4e8e508cb9b13278c2b0fa25b9ca27163", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index ac500ec84..a63b528d3 100644 --- a/flake.nix +++ b/flake.nix @@ -9,25 +9,37 @@ let supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - nixpkgsFor = forAllSystems (system: import nixpkgs { + pkgs = forAllSystems (system: import nixpkgs { + inherit system; + }); + pkgsCuda = forAllSystems (system: import nixpkgs { inherit system; - config.allowUnfree = true; config.cudaSupport = true; + config.allowUnfreePredicate = p: + builtins.all ( + license: + license.free + || builtins.elem license.shortName [ + "CUDA EULA" + "cuDNN EULA" + "cuSPARSELt EULA" + ] + ) (p.meta.licenses or (nixpkgs.lib.toList (p.meta.license or []))); }); in { packages = forAllSystems (system: let - pkgs = nixpkgsFor.${system}; - # Python environment for model_manager.py - myPython = pkgs.python3.withPackages (ps: with ps; [ - torch - safetensors - pyyaml - ]); - # A function to build audio.cpp with any set of features - mkAudioCpp = { cudaSupport ? false, vulkanSupport ? false, metalSupport ? pkgs.stdenv.isDarwin }: + mkAudioCpp = { pkgs, cudaSupport ? false, vulkanSupport ? false, metalSupport ? pkgs.stdenv.isDarwin }: + let + # Python environment for model_manager.py + myPython = pkgs.python3.withPackages (ps: with ps; [ + (if cudaSupport then ps.torchWithCuda else if vulkanSupport then ps.torchWithVulkan else ps.torch) + ps.safetensors + ps.pyyaml + ]); + in pkgs.stdenv.mkDerivation { pname = "audio.cpp"; version = self.shortRev or self.dirtyShortRev or "dirty"; @@ -38,11 +50,9 @@ cmake ninja pkg-config - makeWrapper ] ++ pkgs.lib.optional cudaSupport pkgs.cudaPackages.cuda_nvcc; buildInputs = with pkgs; [ - libunwind myPython ] ++ pkgs.lib.optionals vulkanSupport [ vulkan-headers @@ -53,10 +63,7 @@ ] ++ pkgs.lib.optionals cudaSupport [ pkgs.cudaPackages.cudatoolkit ] ++ pkgs.lib.optionals metalSupport [ - darwin.apple_sdk.frameworks.Metal - darwin.apple_sdk.frameworks.Foundation - darwin.apple_sdk.frameworks.MetalPerformanceShaders - darwin.apple_sdk.frameworks.Accelerate + pkgs.apple-sdk_14 ]; cmakeFlags = [ @@ -72,8 +79,8 @@ mkdir -p $out/bin - # Find and copy the built C++ executables - find . -type f -executable \( -name "audiocpp_cli" -o -name "audiocpp_server" -o -name "audiocpp_gguf" \) -exec cp {} $out/bin/ \; + # Copy the built C++ executables directly from the bin directory + cp bin/audiocpp_cli bin/audiocpp_server bin/audiocpp_gguf $out/bin/ # Install the python model manager script cp $src/tools/model_manager.py $out/bin/audiocpp_model_manager @@ -96,24 +103,27 @@ in { # Expose specific backend variants - cpu = mkAudioCpp { cudaSupport = false; vulkanSupport = false; metalSupport = false; }; - vulkan = mkAudioCpp { vulkanSupport = true; cudaSupport = false; metalSupport = false; }; - cuda = mkAudioCpp { cudaSupport = true; vulkanSupport = false; metalSupport = false; }; - metal = mkAudioCpp { metalSupport = true; cudaSupport = false; vulkanSupport = false; }; - + cpu = mkAudioCpp { pkgs = pkgs.${system}; cudaSupport = false; vulkanSupport = false; metalSupport = false; }; + vulkan = mkAudioCpp { pkgs = pkgs.${system}; vulkanSupport = true; cudaSupport = false; metalSupport = false; }; + } // pkgs.${system}.lib.optionalAttrs pkgs.${system}.stdenv.isLinux { + cuda = mkAudioCpp { pkgs = pkgsCuda.${system}; cudaSupport = true; vulkanSupport = false; metalSupport = false; }; + } // pkgs.${system}.lib.optionalAttrs pkgs.${system}.stdenv.isDarwin { + metal = mkAudioCpp { pkgs = pkgs.${system}; metalSupport = true; cudaSupport = false; vulkanSupport = false; }; + } // { # Automatically select best default for the current platform - default = if pkgs.stdenv.isDarwin then self.packages.${system}.metal else self.packages.${system}.vulkan; + default = if pkgs.${system}.stdenv.isDarwin then self.packages.${system}.metal else self.packages.${system}.vulkan; } ); devShells = forAllSystems (system: - let - pkgs = nixpkgsFor.${system}; - in { - default = pkgs.mkShell { + default = pkgs.${system}.mkShell { inputsFrom = [ self.packages.${system}.default ]; }; + } // pkgs.${system}.lib.optionalAttrs pkgs.${system}.stdenv.isLinux { + cuda = pkgsCuda.${system}.mkShell { + inputsFrom = [ self.packages.${system}.cuda ]; + }; } ); };