82 lines
2.3 KiB
Nix
82 lines
2.3 KiB
Nix
{
|
|
lib,
|
|
fetchurl,
|
|
appimageTools,
|
|
imagemagick,
|
|
}:
|
|
|
|
let
|
|
pname = "lmstudio";
|
|
version = "0.4.2-2";
|
|
|
|
url = "https://installers.lmstudio.ai/linux/x64/${version}/LM-Studio-${version}-x64.AppImage";
|
|
|
|
src = fetchurl {
|
|
inherit url;
|
|
hash = "sha256-JxGlqgsuLcW81mOIcntVFSHv19zSFouIChgz/egc+J0=";
|
|
};
|
|
|
|
contents = appimageTools.extractType2 { inherit pname version src; };
|
|
in
|
|
appimageTools.wrapType2 {
|
|
inherit pname version src;
|
|
|
|
nativeBuildInputs = [ imagemagick ];
|
|
|
|
extraInstallCommands = ''
|
|
set -euo pipefail
|
|
|
|
mkdir -p "$out/share/applications"
|
|
mkdir -p "$out/share/icons/hicolor/256x256/apps"
|
|
|
|
# ---- desktop: create fresh, never edit in place ----
|
|
desktopSrc="$(find "${contents}" -type f -name '*.desktop' | head -n1 || true)"
|
|
if [ -n "$desktopSrc" ]; then
|
|
tmp="$(mktemp)"
|
|
|
|
# Rewrite keys deterministically; keep everything else.
|
|
awk -v exec="${pname}" -v icon="${pname}" '
|
|
BEGIN{hasExec=0;hasTry=0;hasIcon=0}
|
|
/^Exec=/{print "Exec="exec; hasExec=1; next}
|
|
/^TryExec=/{print "TryExec="exec; hasTry=1; next}
|
|
/^Icon=/{print "Icon="icon; hasIcon=1; next}
|
|
{print}
|
|
END{
|
|
if(!hasExec) print "Exec="exec
|
|
if(!hasTry) print "TryExec="exec
|
|
if(!hasIcon) print "Icon="icon
|
|
}
|
|
' "$desktopSrc" > "$tmp"
|
|
|
|
rm -f "$out/share/applications/${pname}.desktop"
|
|
install -m444 "$tmp" "$out/share/applications/${pname}.desktop"
|
|
rm -f "$tmp"
|
|
fi
|
|
|
|
# ---- icon: pick one, convert to canonical name ----
|
|
icon=""
|
|
for cand in \
|
|
"${contents}/.DirIcon" \
|
|
"${contents}/AppIcon.png" \
|
|
"${contents}/usr/share/icons/hicolor/512x512/apps/"*.png \
|
|
"${contents}/usr/share/icons/hicolor/256x256/apps/"*.png \
|
|
; do
|
|
if [ -f "$cand" ]; then icon="$cand"; break; fi
|
|
done
|
|
if [ -z "$icon" ]; then
|
|
icon="$(find "${contents}" -type f -name '*.png' | head -n1 || true)"
|
|
fi
|
|
|
|
if [ -n "$icon" ]; then
|
|
magick "$icon" -resize 256x256 "$out/share/icons/hicolor/256x256/apps/${pname}.png"
|
|
fi
|
|
'';
|
|
|
|
meta = with lib; {
|
|
description = "LM Studio (AppImage)";
|
|
homepage = "https://lmstudio.ai/";
|
|
license = licenses.unfreeRedistributable;
|
|
platforms = [ "x86_64-linux" ];
|
|
mainProgram = pname;
|
|
};
|
|
}
|