From cb502de3091960fba04783a108ff1c28d613efc9 Mon Sep 17 00:00:00 2001 From: Azteczek <243776410+Azteczek@users.noreply.github.com> Date: Mon, 18 May 2026 16:23:10 +0200 Subject: [PATCH] feat: add flake.nix for dockerless setup (#9851) * Add flake.nix Signed-off-by: Azteczek <243776410+Azteczek@users.noreply.github.com> * Add flake.lock Signed-off-by: Azteczek <243776410+Azteczek@users.noreply.github.com> --------- Signed-off-by: Azteczek <243776410+Azteczek@users.noreply.github.com> --- flake.lock | 40 +++++++++++++++++++++++++++++++++++ flake.nix | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..d67f05416 --- /dev/null +++ b/flake.lock @@ -0,0 +1,40 @@ +{ + "nodes": { + "inference-defaults": { + "flake": false, + "locked": { + "narHash": "sha256-ygWIkY2xiUEWqAZQM4/0vBz8vWd/RKX5VBj7EHovU14=", + "type": "file", + "url": "https://raw.githubusercontent.com/unslothai/unsloth/main/studio/backend/assets/configs/inference_defaults.json" + }, + "original": { + "type": "file", + "url": "https://raw.githubusercontent.com/unslothai/unsloth/main/studio/backend/assets/configs/inference_defaults.json" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1777578337, + "narHash": "sha256-Ad49moKWeXtKBJNy2ebiTQUEgdLyvGmTeykAQ9xM+Z4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "15f4ee454b1dce334612fa6843b3e05cf546efab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "inference-defaults": "inference-defaults", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..f2f7ad08e --- /dev/null +++ b/flake.nix @@ -0,0 +1,61 @@ +# Made by Azteczek +{ + description = "LocalAI flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inference-defaults = { + url = "https://raw.githubusercontent.com/unslothai/unsloth/main/studio/backend/assets/configs/inference_defaults.json"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, inference-defaults }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.${system}.default = pkgs.buildGoModule { + pname = "localai"; + version = "custom"; + + src = ./sources; + proxyVendor = true; + vendorHash = "sha256-MdadwbUc2pwfpC9ScsiIfjGIcAOgcwSm6rt/KNlTIuA="; + + nativeBuildInputs = with pkgs; [ + pkg-config cmake gcc protobuf go-protobuf protoc-gen-go protoc-gen-go-grpc + ]; + + env = { + CGO_ENABLED = "0"; + }; + + preBuild = '' + + PROTO_SOURCE_DIR=$(find . -name "*.proto" -printf "%h" -quit) + mkdir -p pkg/grpc/proto + ${pkgs.protobuf}/bin/protoc \ + -I=$PROTO_SOURCE_DIR \ + -I. \ + --go_out=pkg/grpc/proto --go_opt=paths=source_relative \ + --go-grpc_out=pkg/grpc/proto --go-grpc_opt=paths=source_relative \ + $PROTO_SOURCE_DIR/*.proto + + go mod edit -replace github.com/mudler/LocalAI/pkg/grpc/proto=./pkg/grpc/proto + + mkdir -p core/config/gen_inference_defaults + cp ${inference-defaults} core/config/gen_inference_defaults/inference_defaults.json + sed -i '/go:generate/d' core/config/inference_defaults.go || true + + ''; + + subPackages = [ "cmd/local-ai" ]; + doCheck = false; + + postInstall = '' + [ -f $out/bin/local-ai ] && mv $out/bin/local-ai $out/bin/localai + ''; + }; + }; +}