[Backport release-26.05] several: unify electron-builder logic (#524438)

This commit is contained in:
Toma 2026-06-09 23:48:57 +00:00 committed by GitHub
commit 63edff594f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 32 additions and 48 deletions

View file

@ -75,7 +75,6 @@ stdenv.mkDerivation (finalAttrs: {
runHook postConfigure
'';
# electron builds must be writable to support electron fuses
preBuild = ''
# Validate electron version matches upstream package.json
if [ "`jq -r '.devDependencies.electron' < package.json | cut -d. -f1 | tr -d '^'`" != "${lib.versions.major electron.version}" ]
@ -83,12 +82,8 @@ stdenv.mkDerivation (finalAttrs: {
echo "ERROR: electron version mismatch between package.json and nixpkgs"
exit 1
fi
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
cp -r ${electron.dist}/Electron.app .
chmod -R u+w Electron.app
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
# electron builds must be writable to support electron fuses
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
'';
@ -103,7 +98,7 @@ stdenv.mkDerivation (finalAttrs: {
# can't run it via bunx / npx since fixupPhase was skipped for node_modules
node node_modules/electron-builder/out/cli/cli.js \
--dir \
-c.electronDist=${if stdenv.hostPlatform.isDarwin then "." else "electron-dist"} \
-c.electronDist=electron-dist \
-c.electronVersion=${electron.version} \
-c.npmRebuild=false

View file

@ -73,20 +73,17 @@ buildNpmPackage {
ln -s ${dart-sass}/bin/dart-sass "$dir"/sass
'';
postBuild =
lib.optionalString stdenv.hostPlatform.isDarwin ''
# electron-builder appears to build directly on top of Electron.app, by overwriting the files in the bundle.
cp -r ${electron.dist}/Electron.app ./
find ./Electron.app -name 'Info.plist' | xargs -d '\n' chmod +rw
''
+ ''
npm exec electron-builder -- \
--dir \
-c.electronDist=${if stdenv.hostPlatform.isDarwin then "./" else electron.dist} \
-c.electronVersion=${electron.version} \
-c.npmRebuild=false \
${lib.optionalString stdenv.hostPlatform.isDarwin "-c.mac.identity=null"}
'';
postBuild = ''
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
npm exec electron-builder -- \
--dir \
-c.electronDist=electron-dist \
-c.electronVersion=${electron.version} \
-c.npmRebuild=false \
${lib.optionalString stdenv.hostPlatform.isDarwin "-c.mac.identity=null"}
'';
installPhase = ''
runHook preInstall

View file

@ -64,19 +64,17 @@ stdenv.mkDerivation (finalAttrs: {
runHook postConfigure
'';
preBuild = lib.optionalString stdenv.hostPlatform.isLinux ''
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
'';
buildPhase = ''
runHook preBuild
bun run build -- --skipTypecheck
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
node node_modules/electron-builder/out/cli/cli.js \
--dir \
-c.electronDist="${if stdenv.hostPlatform.isLinux then "electron-dist" else electron.dist}" \
-c.electronDist=electron-dist \
-c.electronVersion="${electron.version}" \
-c.npmRebuild=false

View file

@ -47,18 +47,17 @@ stdenv.mkDerivation (finalAttrs: {
env.ELECTRON_SKIP_BINARY_DOWNLOAD = 1;
postBuild =
lib.optionalString stdenv.hostPlatform.isDarwin ''
cp -R ${electron.dist}/Electron.app Electron.app
chmod -R u+w Electron.app
''
+ ''
pnpm build
./node_modules/.bin/electron-builder \
--dir \
-c.electronDist=${if stdenv.hostPlatform.isDarwin then "." else electron.dist} \
-c.electronVersion=${electron.version}
'';
postBuild = ''
pnpm build
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
./node_modules/.bin/electron-builder \
--dir \
-c.electronDist=electron-dist \
-c.electronVersion=${electron.version}
'';
desktopItems = [
(makeDesktopItem {

View file

@ -87,7 +87,6 @@ stdenv.mkDerivation (finalAttrs: {
ELECTRON_SKIP_BINARY_DOWNLOAD = 1;
};
# electron builds must be writable
preBuild = ''
# Validate electron version matches upstream package.json
if [ "`jq -r '.devDependencies.electron' < package.json | cut -d. -f1 | tr -d '^'`" != "${lib.versions.major electron.version}" ]
@ -95,12 +94,8 @@ stdenv.mkDerivation (finalAttrs: {
echo "ERROR: electron version mismatch between package.json and nixpkgs"
exit 1
fi
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
cp -r ${electron.dist}/Electron.app .
chmod -R u+w Electron.app
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
# electron builds must be writable
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
'';
@ -112,7 +107,7 @@ stdenv.mkDerivation (finalAttrs: {
pnpm exec electron-builder \
--dir \
-c.asarUnpack="**/*.node" \
-c.electronDist=${if stdenv.hostPlatform.isDarwin then "." else "electron-dist"} \
-c.electronDist=electron-dist \
-c.electronVersion=${electron.version} \
${lib.optionalString stdenv.hostPlatform.isDarwin "-c.mac.identity=null"} # disable code signing on macos, https://github.com/electron-userland/electron-builder/blob/77f977435c99247d5db395895618b150f5006e8f/docs/code-signing.md#how-to-disable-code-signing-during-the-build-process-on-macos