From d00e95bd5b5c4d6d72c12c4908bf608ef8fa7e25 Mon Sep 17 00:00:00 2001 From: superherointj Date: Sat, 16 May 2026 12:38:47 -0300 Subject: [PATCH] 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. --- pkgs/by-name/op/opencode-desktop/package.nix | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/op/opencode-desktop/package.nix b/pkgs/by-name/op/opencode-desktop/package.nix index bfc0cf9c482c..8f2efe9ed76a 100644 --- a/pkgs/by-name/op/opencode-desktop/package.nix +++ b/pkgs/by-name/op/opencode-desktop/package.nix @@ -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 ../..