diff --git a/pkgs/by-name/lm/lmstudio/darwin.nix b/pkgs/by-name/lm/lmstudio/darwin.nix index f18a880feabe..2c8b21418e68 100644 --- a/pkgs/by-name/lm/lmstudio/darwin.nix +++ b/pkgs/by-name/lm/lmstudio/darwin.nix @@ -2,6 +2,7 @@ stdenv, fetchurl, undmg, + darwin, meta, pname, version, @@ -16,7 +17,10 @@ stdenv.mkDerivation { inherit url hash; }; - nativeBuildInputs = [ undmg ]; + nativeBuildInputs = [ + undmg + darwin.sigtool + ]; sourceRoot = "."; @@ -24,6 +28,19 @@ stdenv.mkDerivation { runHook preInstall mkdir -p $out/Applications cp -r *.app $out/Applications + + # Bypass the /Applications path check in the main index.js + # LM Studio verifies the app is running from /Applications and shows an + # error dialog + refuses to auto-update if not. Replace the '/Applications' + # string literal with '/' so that any absolute path (e.g. /nix/store/...) + # passes the startsWith check. This works across obfuscated versions because + # the literal string '/Applications' is stable even when variable names change. + local indexJs="$out/Applications/LM Studio.app/Contents/Resources/app/.webpack/main/index.js" + substituteInPlace "$indexJs" --replace-quiet "'/Applications'" "'/'" + + # Re-sign the app bundle after patching, otherwise macOS reports it as damaged + codesign --force --deep --sign - "$out/Applications/LM Studio.app" + runHook postInstall ''; diff --git a/pkgs/by-name/lm/lmstudio/package.nix b/pkgs/by-name/lm/lmstudio/package.nix index 5ece8f0b4355..eeed9c1ac5fa 100644 --- a/pkgs/by-name/lm/lmstudio/package.nix +++ b/pkgs/by-name/lm/lmstudio/package.nix @@ -23,7 +23,6 @@ let "aarch64-darwin" ]; sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; - broken = stdenv.hostPlatform.isDarwin; # Upstream issue: https://github.com/lmstudio-ai/lmstudio-bug-tracker/issues/347 }; in if stdenv.hostPlatform.isDarwin then