ollamaPackages.mkOllamaModel: sanity checks during development that you actually specify all the needed blobs

This commit is contained in:
2024-12-05 22:11:33 +00:00
parent ec1d573ddb
commit c3c212b6dd

View File

@@ -92,26 +92,46 @@ stdenv.mkDerivation {
echo "manifest:"
cat manifest
printBlob() {
mismatchedBlobs=()
checkBlob() {
local blobType="$1"
local expectedBlobHash="$2"
local blobHash=$(cat manifest | jq ".layers.[] | select(.mediaType == \"application/vnd.ollama.image.$blobType\") | .digest[7:]")
if [ -n "$blobHash" ]; then
printf " %sBlob = %s;\n" "$blobType" "$blobHash"
fi
if [ "''${blobHash//\"/}" != "$expectedBlobHash" ]; then
mismatchedBlobs+=("$blobType")
fi
}
echo "blobs:"
printBlob model
printBlob params
printBlob system
printBlob ensureDoesntFailForNonExistentBlob
checkBlob model "$modelBlob"
checkBlob params "$paramsBlob"
checkBlob system "$systemBlob"
checkBlob ensureDoesntFailForNonExistentBlob
if [ -n "$mismatchedBlobs" ]; then
echo "mismatched blobs:"
for b in "''${mismatchedBlobs[@]}"; do
echo "- $b"
done
false
fi
runHook postCheck
'';
doCheck = true;
env.blobDir = "share/ollama/models/blobs";
env.manifestDir = "share/ollama/models/manifests/registry.ollama.ai/library/${modelName}";
env.variant = variant;
env = {
blobDir = "share/ollama/models/blobs";
manifestDir = "share/ollama/models/manifests/registry.ollama.ai/library/${modelName}";
inherit variant modelBlob paramsBlob systemBlob;
};
meta = {
homepage = "https://ollama.com/library/${modelName}";
};
}