opencode-desktop: disable code signing on Darwin

electron-builder attempts to sign macOS binaries by calling
`security find-identity`. Inside the nix sandbox on public Darwin
builders (nix-community), process spawning is restricted, causing
a spawn EPERM error.

Apply three layers of defense:

 1. CSC_IDENTITY_AUTO_DISCOVERY=false env var
 2. --config.mac.identity=null CLI flag
 3. Patch macCodeSign.js getValidIdentities to return [] immediately
    (catches any code path the other two miss)

PreBuild is used because postPatch runs before node_modules
is copied into the build tree (configurePhase). preBuild is
the earliest point where the file exists to be patched.
This commit is contained in:
superherointj
2026-05-16 12:38:47 -03:00
parent d8a466512a
commit d00e95bd5b
+20 -1
View File
@@ -54,6 +54,12 @@ stdenvNoCC.mkDerivation (finalAttrs: {
OPENCODE_CHANNEL = "prod";
MODELS_DEV_API_JSON = "${models-dev}/dist/_api.json";
OPENCODE_DISABLE_MODELS_FETCH = true;
}
# Disable code signing on macOS. Public build hosts don't have Apple Developer
# certificates, so electron-builder's `security find-identity` spawns produce
# EPERM inside the nix sandbox.
// lib.optionalAttrs stdenvNoCC.hostPlatform.isDarwin {
CSC_IDENTITY_AUTO_DISCOVERY = "false";
};
postPatch = ''
@@ -73,6 +79,18 @@ stdenvNoCC.mkDerivation (finalAttrs: {
runHook postConfigure
'';
preBuild = lib.optionalString stdenvNoCC.hostPlatform.isDarwin ''
# Patch electron-builder to skip code signing on macOS.
# The nix sandbox on public Darwin builders cannot spawn
# `security find-identity` trying gives spawn EPERM.
# We patch the compiled JS to make getValidIdentities a no-op.
for f in $(find node_modules -path "*/app-builder-lib/out/codeSign/macCodeSign.js" -type f 2>/dev/null); do
substituteInPlace "$f" \
--replace-fail "async function getValidIdentities" \
"async function getValidIdentities() { return []; }; async function getValidIdentities_DISABLED"
done
'';
buildPhase = ''
runHook preBuild
@@ -98,7 +116,8 @@ stdenvNoCC.mkDerivation (finalAttrs: {
--config=electron-builder.config.ts \
--config.electronDist="$HOME/.electron-dist" \
--config.electronVersion=${electron.version} \
--config.asarUnpack='**/*.node'
--config.asarUnpack='**/*.node' \
${lib.optionalString stdenvNoCC.hostPlatform.isDarwin "--config.mac.identity=null"}
cd ../..