diff --git a/.github/workflows/update_release.yaml b/.github/workflows/update_release.yaml new file mode 100644 index 0000000..8ddb708 --- /dev/null +++ b/.github/workflows/update_release.yaml @@ -0,0 +1,38 @@ + +name: Update Flake assets on Release + +on: + release: + types: [published] # Triggers when a release is fully published + +permissions: + contents: write # Required to push commits back to the repo + +jobs: + update-sources: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: true + + - name: Run update script + run: | + git checkout ${{github.ref_name}} + chmod +x ./update.sh + ./update.sh + + - name: Commit and push changes + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply" + + # Only commit if sources.json actually changed + if ! git diff --exit-code .; then + git add . + git commit -m "chore: update nix flake assets for ${{ github.event.release.tag_name }}" + git push origin ${{github.ref_name}} + else + echo "No changes detected in sources.json" + fi diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..62ec88a --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1778869304, + "narHash": "sha256-30sZNZoA1cqF5JNO9fVX+wgiQYjB7HJqqJ4ztCDeBZE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d233902339c02a9c334e7e593de68855ad26c4cb", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6b559ad --- /dev/null +++ b/flake.nix @@ -0,0 +1,72 @@ +{ + description = "llama.cpp CUDA binaries from ai-dock (Patched for NixOS)"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; # Required for CUDA + }; + release = builtins.fromJSON (builtins.readFile "${self}/latest_release.json"); + sha256 = builtins.convertHash { + hash = release.hash; + toHashFormat = "sri"; + hashAlgo = "sha256"; + }; + in + { + packages.default = + with release; + pkgs.stdenv.mkDerivation { + pname = "aidock_llama-cpp-cuda"; + inherit version; + src = pkgs.fetchurl { inherit url sha256; }; + nativeBuildInputs = with pkgs; [ autoPatchelfHook ]; + buildInputs = with pkgs; [ + stdenv.cc.cc.lib + cudaPackages.cudatoolkit + cudaPackages.nccl + linuxPackages.nvidia_x11 + ]; + + appendRunpaths = [ + "/run/opengl-driver/lib" + "${pkgs.linuxPackages.nvidia_x11}/lib" + "$out/lib" + ]; + + sourceRoot = "."; + + installPhase = '' + mkdir -p $out/bin $out/lib + find . -name "*.so*" -exec cp -vP {} $out/lib/ \; + find . -type f -executable \ + ! -name "*.so*" \ + ! -name "*.txt" \ + ! -name "*.md" \ + -exec cp -v {} $out/bin/ \; + [ "$(ls -A $out/bin)" ] || { echo "Error: No binaries found!"; exit 1; } + ''; + autoPatchelfIgnoreMissingDeps = false; + }; + devShells.default = pkgs.mkShell { + buildInputs = [ self.packages.${system}.default ]; + shellHook = '' + export LD_LIBRARY_PATH="/run/opengl-driver/lib:${pkgs.linuxPackages.nvidia_x11}/lib:$LD_LIBRARY_PATH" + ''; + }; + } + ); +} diff --git a/latest_release.json b/latest_release.json new file mode 100644 index 0000000..678ae71 --- /dev/null +++ b/latest_release.json @@ -0,0 +1,5 @@ +{ + "version": "b9190", + "hash": "sha256:988920b5fb99250861577bd38a5ee639ff051183ce22cab170001208ae8f481b", + "url": "https://github.com/ai-dock/llama.cpp-cuda/releases/download/b9190/llama.cpp-b9190-cuda-12.8.tar.gz" +} diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..2586699 --- /dev/null +++ b/update.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +curl -s https://api.github.com/repos/ai-dock/llama.cpp-cuda/releases/latest | jq '{version:(.tag_name),hash:(.assets[0].digest),url:(.assets[0].browser_download_url)}' > latest_release.json +nix flake update