fix(nix flake): ensure nix flake builds successfully (#10399)

* Use inference defaults in repo src rather than fetching

there are inference_defaults.json already in the repo so we can use
those, they are regularly updated with github actions, and we avoid hash
mismatch errors in the flake this way

Signed-off-by: Souheab <souheab@protonmail.com>

* Update vendor hash

Signed-off-by: Souheab <souheab@protonmail.com>

* Create react-ui derivation as it is required for go build

Signed-off-by: Souheab <souheab@protonmail.com>

* Add FHS env wrapper to make #!/bin/bash scripts work

Signed-off-by: Souheab <souheab@protonmail.com>

* use pkgs.importNpmLock to deal with npm dependencies instead of using npmDepsHash

Signed-off-by: Souheab <souheab@protonmail.com>

---------

Signed-off-by: Souheab <souheab@protonmail.com>
This commit is contained in:
Souheab
2026-06-19 11:15:18 -04:00
committed by GitHub
parent 78d682224a
commit 59c7ad5153
2 changed files with 38 additions and 23 deletions

13
flake.lock generated
View File

@@ -1,17 +1,5 @@
{
"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,
@@ -30,7 +18,6 @@
},
"root": {
"inputs": {
"inference-defaults": "inference-defaults",
"nixpkgs": "nixpkgs"
}
}

View File

@@ -4,24 +4,36 @@
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 }:
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
packages.${system}.default = pkgs.buildGoModule {
reactUi = pkgs.buildNpmPackage {
pname = "localai-react-ui";
version = "custom";
src = ./core/http/react-ui;
npmDeps = pkgs.importNpmLock {
npmRoot = ./core/http/react-ui;
};
npmConfigHook = pkgs.importNpmLock.npmConfigHook;
npmBuildScript = "build";
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r dist $out/
runHook postInstall
'';
};
localai-unwrapped = pkgs.buildGoModule {
pname = "localai";
version = "custom";
src = ./.;
proxyVendor = true;
vendorHash = "sha256-6f3adjGsoFXlUtXjBDHP4Mv9jKCOK3aeUXprm0EAVO8=";
vendorHash = "sha256-z3lxQS8mXFuJzvYamejwapwVEmLpeAoiO3ksUKb4I3Q=";
nativeBuildInputs = with pkgs; [
pkg-config cmake gcc protobuf go-protobuf protoc-gen-go protoc-gen-go-grpc
@@ -44,8 +56,9 @@
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
mkdir -p core/http/react-ui
cp -r ${reactUi}/dist core/http/react-ui/dist
sed -i '/go:generate/d' core/config/inference_defaults.go || true
'';
@@ -57,6 +70,21 @@
[ -f $out/bin/local-ai ] && mv $out/bin/local-ai $out/bin/localai
'';
};
in {
packages.${system} = {
localai-unwrapped = localai-unwrapped;
default = pkgs.buildFHSEnv {
name = "localai";
targetPkgs = pkgs: with pkgs; [
localai-unwrapped
bash
coreutils
gnugrep
];
runScript = "${localai-unwrapped}/bin/localai";
};
};
devShells.${system}.default = pkgs.mkShell {
packages = with pkgs; [