Build Support: electron-forge based applications (e.g. protonmail-desktop source-build)

Hey, following up on this (protonmail-desktop: init at 1.0.1 by rsniezek · Pull Request #296127 · NixOS/nixpkgs · GitHub) I wanted to share my current status of packaging protonmail-desktop which uses electron-forge and from where I am atm. I would say if we fix it for this app it could have potential to easier support forge-based apps in general.

I’ve found out so far, that electron-forge uses electron-packager which needs an electron built/erase (not 100% certain) but only accept it as zip via “electron-zip-dir” not a path.

Without using the zip-way I get this error in the build as it tries to connect to github to download electron:

[STARTED] Preparing to package application
17:15:05.739 › Settings not found, using default settings
[SUCCESS] Preparing to package application
[STARTED] Running packaging hooks
[STARTED] Running generateAssets hook
[STARTED] Running generateAssets hook from forgeConfig
[SUCCESS] Running generateAssets hook from forgeConfig
[SUCCESS] Running generateAssets hook
[STARTED] Running prePackage hook
[STARTED] [plugin-webpack] Preparing webpack bundles
[STARTED] Preparing native dependencies for x64
[TITLE] Preparing native dependencies
[SUCCESS] Preparing native dependencies
[STARTED] Building webpack bundles
[SUCCESS] Building webpack bundles
[SUCCESS] [plugin-webpack] Preparing webpack bundles
[SUCCESS] Running prePackage hook
[SUCCESS] Running packaging hooks
[STARTED] Packaging application
[DATA] Determining targets...
[STARTED] Packaging for x64 on linux
[STARTED] Copying files
[FAILED] getaddrinfo EAI_AGAIN github.com
[FAILED] getaddrinfo EAI_AGAIN github.com
[FAILED] getaddrinfo EAI_AGAIN github.com

An unhandled rejection has occurred inside Forge:
RequestError: getaddrinfo EAI_AGAIN github.com
at ClientRequest.<anonymous> (/nix/store/wvjff0fkrip9c8scn806rbi4shivdk3j-proton-mail-modules-unstable-20240321/node_modules/got/dist/source/core/index.js:970:111)
    at Object.onceWrapper (node:events:633:26)
    at ClientRequest.emit (node:events:530:35)
    at ClientRequest.emit (node:domain:488:12)
    at ClientRequest.origin.emit (/nix/store/wvjff0fkrip9c8scn806rbi4shivdk3j-proton-mail-modules-unstable-20240321/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:518:28)
    at TLSSocket.emit (node:domain:488:12)
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If I create a zip from the electron-package sources trying to imitate a release:

proton-mail-unstable> [SUCCESS] Preparing to package application
proton-mail-unstable> [STARTED] Running packaging hooks
proton-mail-unstable> [STARTED] Running generateAssets hook
proton-mail-unstable> [STARTED] Running generateAssets hook from forgeConfig
proton-mail-unstable> [SUCCESS] Running generateAssets hook from forgeConfig
proton-mail-unstable> [SUCCESS] Running generateAssets hook
proton-mail-unstable> [STARTED] Running prePackage hook
proton-mail-unstable> [STARTED] [plugin-webpack] Preparing webpack bundles
proton-mail-unstable> [STARTED] Preparing native dependencies for x64
proton-mail-unstable> [TITLE] Preparing native dependencies
proton-mail-unstable> [SUCCESS] Preparing native dependencies
proton-mail-unstable> [STARTED] Building webpack bundles
proton-mail-unstable> [SUCCESS] Building webpack bundles
proton-mail-unstable> [SUCCESS] [plugin-webpack] Preparing webpack bundles
proton-mail-unstable> [SUCCESS] Running prePackage hook
proton-mail-unstable> [SUCCESS] Running packaging hooks
proton-mail-unstable> [STARTED] Packaging application
proton-mail-unstable> [DATA] Determining targets...
proton-mail-unstable> [STARTED] Packaging for x64 on linux
proton-mail-unstable> [STARTED] Copying files
proton-mail-unstable> [SUCCESS] Copying files
proton-mail-unstable> [STARTED] Preparing native dependencies
proton-mail-unstable>
proton-mail-unstable> An unhandled rejection has occurred inside Forge:
proton-mail-unstable> Error: EISDIR: illegal operation on a directory, read
proton-mail-unstable> error Command failed with exit code 1.
proton-mail-unstable> info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Current status in git: GitHub - SebTM/nixpkgs at protonmail_desktop-sourcebuild / Draft/Dev: protonmail-desktop - electron-forge based source-build by SebTM · Pull Request #297822 · NixOS/nixpkgs · GitHub

It might be possible to use GitHub - electron-userland/electron-builder: A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box to build but I wanted to try to resolve this in general as forge seems quite popular/growing and also it would require maintainers of forge-based packages to convert/translate the forge-config to maybe relevant builder-config in case of malfunction. But maybe I’m over-thinking/complicating thing, was mostly done when I had some spare time…

Complete and more verbose build output of the latest failure:

this derivation will be built:
  /nix/store/5dfj9iw0ik01smyskl2fjk4p23wd7n7d-proton-mail-1.0.1.drv
building '/nix/store/5dfj9iw0ik01smyskl2fjk4p23wd7n7d-proton-mail-1.0.1.drv'...
proton-mail> Running phase: unpackPhase
proton-mail> unpacking source archive /nix/store/bk9kp8pdj5728v46f9c6iylp9mlkph1n-protonmail-desktop-1.0.1
proton-mail> source root is protonmail-desktop-1.0.1
proton-mail> Running phase: patchPhase
proton-mail> Running phase: updateAutotoolsGnuConfigScriptsPhase
proton-mail> Running phase: configurePhase
proton-mail> Running phase: buildPhase
proton-mail> /build/protonmail-desktop-1.0.1/deps/proton-mail /build/protonmail-desktop-1.0.1
proton-mail> /build/protonmail-desktop-1.0.1
proton-mail> yarn run v1.22.22
proton-mail> $ electron-forge package -a x64 -p linux
proton-mail> ◼ Checking your system
proton-mail> ⠋ Checking your system
proton-mail> ❯ Checking your system
proton-mail> ❯ Checking your system
proton-mail>   ◼ Checking git exists
proton-mail> ❯ Checking your system
proton-mail>   ◼ Checking git exists
proton-mail>   ◼ Checking node version
proton-mail> ❯ Checking your system
proton-mail>   ◼ Checking git exists
proton-mail>   ◼ Checking node version
proton-mail>   ◼ Checking packageManager version
proton-mail> ❯ Checking your system
proton-mail>   ⠋ Checking git exists
proton-mail>   ◼ Checking node version
proton-mail>   ◼ Checking packageManager version
proton-mail> ❯ Checking your system
proton-mail>   ⠋ Checking git exists
proton-mail>   ⠋ Checking node version
proton-mail>   ◼ Checking packageManager version
proton-mail> ❯ Checking your system
proton-mail>   ⠋ Checking git exists
proton-mail>   ⠋ Checking node version
proton-mail>   ⠋ Checking packageManager version
proton-mail> ❯ Checking your system
proton-mail>   ⠋ Found git@2.43.2
proton-mail>   ⠋ Checking node version
proton-mail>   ⠋ Checking packageManager version
proton-mail> ❯ Checking your system
proton-mail>   ✔ Found git@2.43.2
proton-mail>   ⠋ Checking node version
proton-mail>   ⠋ Checking packageManager version
proton-mail> ❯ Checking your system
proton-mail>   ✔ Found git@2.43.2
proton-mail>   ⠋ Found node@20.11.1
proton-mail>   ⠋ Checking packageManager version
proton-mail> ❯ Checking your system
proton-mail>   ✔ Found git@2.43.2
proton-mail>   ✔ Found node@20.11.1
proton-mail>   ⠋ Checking packageManager version
proton-mail> ❯ Checking your system
proton-mail>   ✔ Found git@2.43.2
proton-mail>   ✔ Found node@20.11.1
proton-mail>   ⠙ Checking packageManager version
proton-mail> ❯ Checking your system
proton-mail>   ✔ Found git@2.43.2
proton-mail>   ✔ Found node@20.11.1
proton-mail>   ⠙ Found yarn@1.22.22
proton-mail> ❯ Checking your system
proton-mail>   ✔ Found git@2.43.2
proton-mail>   ✔ Found node@20.11.1
proton-mail>   ✔ Found yarn@1.22.22
proton-mail> ✔ Checking your system
proton-mail> ✔ Checking your system
proton-mail> [STARTED] Preparing to package application
proton-mail> 20:31:22.298 › Settings not found, using default settings
proton-mail> [SUCCESS] Preparing to package application
proton-mail> [STARTED] Running packaging hooks
proton-mail> [STARTED] Running generateAssets hook
proton-mail> [STARTED] Running generateAssets hook from forgeConfig
proton-mail> [SUCCESS] Running generateAssets hook from forgeConfig
proton-mail> [SUCCESS] Running generateAssets hook
proton-mail> [STARTED] Running prePackage hook
proton-mail> [STARTED] [plugin-webpack] Preparing webpack bundles
proton-mail> [STARTED] Preparing native dependencies for x64
proton-mail> [TITLE] Preparing native dependencies
proton-mail> [SUCCESS] Preparing native dependencies
proton-mail> [STARTED] Building webpack bundles
proton-mail> [SUCCESS] Building webpack bundles
proton-mail> [SUCCESS] [plugin-webpack] Preparing webpack bundles
proton-mail> [SUCCESS] Running prePackage hook
proton-mail> [SUCCESS] Running packaging hooks
proton-mail> [STARTED] Packaging application
proton-mail> [DATA] Determining targets...
proton-mail> [STARTED] Packaging for x64 on linux
proton-mail> [STARTED] Copying files
proton-mail> [SUCCESS] Copying files
proton-mail> [STARTED] Preparing native dependencies
proton-mail>
proton-mail> An unhandled rejection has occurred inside Forge:
proton-mail> Error: EISDIR: illegal operation on a directory, read
proton-mail> error Command failed with exit code 1.
proton-mail> info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error: builder for '/nix/store/5dfj9iw0ik01smyskl2fjk4p23wd7n7d-proton-mail-1.0.1.drv' failed with exit code 1;
       last 25 log lines:
       > [STARTED] Running generateAssets hook from forgeConfig
       > [SUCCESS] Running generateAssets hook from forgeConfig
       > [SUCCESS] Running generateAssets hook
       > [STARTED] Running prePackage hook
       > [STARTED] [plugin-webpack] Preparing webpack bundles
       > [STARTED] Preparing native dependencies for x64
       > [TITLE] Preparing native dependencies
       > [SUCCESS] Preparing native dependencies
       > [STARTED] Building webpack bundles
       > [SUCCESS] Building webpack bundles
       > [SUCCESS] [plugin-webpack] Preparing webpack bundles
       > [SUCCESS] Running prePackage hook
       > [SUCCESS] Running packaging hooks
       > [STARTED] Packaging application
       > [DATA] Determining targets...
       > [STARTED] Packaging for x64 on linux
       > [STARTED] Copying files
       > [SUCCESS] Copying files
       > [STARTED] Preparing native dependencies
       >
       > An unhandled rejection has occurred inside Forge:
       > Error: EISDIR: illegal operation on a directory, read
       >
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
       For full logs, run 'nix log /nix/store/5dfj9iw0ik01smyskl2fjk4p23wd7n7d-proton-mail-1.0.1.drv'.