From cb7144e21d446e401aeeebcb29241226f27f1ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ribeiro?= Date: Thu, 18 Apr 2024 19:13:18 +0100 Subject: [PATCH 1/3] feishin: fix darwin builds Addresses the comment https://github.com/NixOS/nixpkgs/pull/303638#issuecomment-2052463043 following #303638. --- pkgs/applications/audio/feishin/default.nix | 110 ++++++++++++-------- 1 file changed, 69 insertions(+), 41 deletions(-) diff --git a/pkgs/applications/audio/feishin/default.nix b/pkgs/applications/audio/feishin/default.nix index 5168d084af72..84bfc59362f2 100644 --- a/pkgs/applications/audio/feishin/default.nix +++ b/pkgs/applications/audio/feishin/default.nix @@ -1,8 +1,10 @@ { lib, + stdenv, buildNpmPackage, fetchFromGitHub, electron_27, + darwin, copyDesktopItems, makeDesktopItem, ... @@ -21,8 +23,7 @@ let electron = electron_27; in buildNpmPackage { - pname = "feishin"; - inherit version; + inherit pname version; inherit src; npmDepsHash = "sha256-+pr9fWg/9kxkYMmthtqhjgF6MOomSQxVCO5V8tHHRdE="; @@ -32,17 +33,25 @@ buildNpmPackage { env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1"; - nativeBuildInputs = [ copyDesktopItems ]; + nativeBuildInputs = + lib.optionals (stdenv.isLinux) [ copyDesktopItems ] + ++ lib.optionals stdenv.isDarwin [ darwin.autoSignDarwinBinariesHook ]; - postPatch = '' - # release/app dependencies are installed on preConfigure - substituteInPlace package.json \ - --replace-fail "electron-builder install-app-deps &&" "" + postPatch = + '' + # release/app dependencies are installed on preConfigure + substituteInPlace package.json \ + --replace-fail "electron-builder install-app-deps &&" "" - # https://github.com/electron/electron/issues/31121 - substituteInPlace src/main/main.ts \ - --replace-fail "process.resourcesPath" "'$out/share/feishin/resources'" - ''; + # Don't check for updates. + substituteInPlace src/main/main.ts \ + --replace-fail "autoUpdater.checkForUpdatesAndNotify();" "" + '' + + lib.optionalString stdenv.isLinux '' + # https://github.com/electron/electron/issues/31121 + substituteInPlace src/main/main.ts \ + --replace-fail "process.resourcesPath" "'$out/share/feishin/resources'" + ''; preConfigure = let @@ -67,40 +76,59 @@ buildNpmPackage { done ''; - postBuild = '' - npm exec electron-builder -- \ - --dir \ - -c.electronDist=${electron}/libexec/electron \ - -c.electronVersion=${electron.version} \ - -c.npmRebuild=false - ''; + postBuild = + lib.optionalString stdenv.isDarwin '' + # electron-builder appears to build directly on top of Electron.app, by overwriting the files in the bundle. + cp -r ${electron}/Applications/Electron.app ./ + find ./Electron.app -name 'Info.plist' | xargs -d '\n' chmod +rw - installPhase = '' - runHook preInstall + # Disable code signing during build on macOS. + # https://github.com/electron-userland/electron-builder/blob/fa6fc16/docs/code-signing.md#how-to-disable-code-signing-during-the-build-process-on-macos + export CSC_IDENTITY_AUTO_DISCOVERY=false + sed -i "/afterSign/d" package.json + '' + + '' + npm exec electron-builder -- \ + --dir \ + -c.electronDist=${if stdenv.isDarwin then "./" else "${electron}/libexec/electron"} \ + -c.electronVersion=${electron.version} \ + -c.npmRebuild=false + ''; - mkdir -p $out/share/feishin - pushd release/build/*/ - cp -r locales resources{,.pak} $out/share/feishin - popd + installPhase = + '' + runHook preInstall + '' + + lib.optionalString stdenv.isDarwin '' + mkdir -p $out/{Applications,bin} + cp -r release/build/**/Feishin.app $out/Applications/ + makeWrapper $out/Applications/Feishin.app/Contents/MacOS/Feishin $out/bin/feishin + '' + + lib.optionalString stdenv.isLinux '' + mkdir -p $out/share/feishin + pushd release/build/*/ + cp -r locales resources{,.pak} $out/share/feishin + popd - # Code relies on checking app.isPackaged, which returns false if the executable is electron. - # Set ELECTRON_FORCE_IS_PACKAGED=1. - # https://github.com/electron/electron/issues/35153#issuecomment-1202718531 - makeWrapper ${lib.getExe electron} $out/bin/feishin \ - --add-flags $out/share/feishin/resources/app.asar \ - --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \ - --set ELECTRON_FORCE_IS_PACKAGED=1 \ - --inherit-argv0 + # Code relies on checking app.isPackaged, which returns false if the executable is electron. + # Set ELECTRON_FORCE_IS_PACKAGED=1. + # https://github.com/electron/electron/issues/35153#issuecomment-1202718531 + makeWrapper ${lib.getExe electron} $out/bin/feishin \ + --add-flags $out/share/feishin/resources/app.asar \ + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \ + --set ELECTRON_FORCE_IS_PACKAGED=1 \ + --inherit-argv0 - for size in 32 64 128 256 512 1024; do - mkdir -p $out/share/icons/hicolor/"$size"x"$size"/apps - ln -s \ - $out/share/feishin/resources/assets/icons/"$size"x"$size".png \ - $out/share/icons/hicolor/"$size"x"$size"/apps/${pname}.png - done - - runHook postInstall - ''; + for size in 32 64 128 256 512 1024; do + mkdir -p $out/share/icons/hicolor/"$size"x"$size"/apps + ln -s \ + $out/share/feishin/resources/assets/icons/"$size"x"$size".png \ + $out/share/icons/hicolor/"$size"x"$size"/apps/${pname}.png + done + '' + + '' + runHook postInstall + ''; desktopItems = [ (makeDesktopItem { From a3fc61858c7e58e9a62e61d433ee89d5528f938e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ribeiro?= Date: Thu, 18 Apr 2024 19:45:47 +0100 Subject: [PATCH 2/3] maintainers: add jlbribeiro --- maintainers/maintainer-list.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 84abf029c658..388efdd225f2 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -9479,6 +9479,12 @@ fingerprint = "B768 6CD7 451A 650D 9C54 4204 6710 CF0C 1CBD 7762"; }]; }; + jlbribeiro = { + email = "nix@jlbribeiro.com"; + github = "jlbribeiro"; + githubId = 1015816; + name = "José Ribeiro"; + }; jleightcap = { email = "jack@leightcap.com"; github = "jleightcap"; From 5124a8dbc45e61ca35a95601bd2a588a7ca66954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ribeiro?= Date: Thu, 18 Apr 2024 19:47:08 +0100 Subject: [PATCH 3/3] feishin: add jlbribeiro as maintainer Follows #303638 and feishin darwin builds' fix. --- pkgs/applications/audio/feishin/default.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/audio/feishin/default.nix b/pkgs/applications/audio/feishin/default.nix index 84bfc59362f2..e0e35bae6df0 100644 --- a/pkgs/applications/audio/feishin/default.nix +++ b/pkgs/applications/audio/feishin/default.nix @@ -153,6 +153,9 @@ buildNpmPackage { license = licenses.gpl3Plus; platforms = platforms.unix; mainProgram = "feishin"; - maintainers = with maintainers; [ onny ]; + maintainers = with maintainers; [ + onny + jlbribeiro + ]; }; }