From 076474254a07f564601495498d10ff6f14038565 Mon Sep 17 00:00:00 2001 From: Mukul Agarwal Date: Sat, 27 Jun 2026 20:25:06 -0400 Subject: [PATCH] thorium-reader: add .app bundle on Darwin this makes it easier for those using thorium on macOS to use the application --- pkgs/by-name/th/thorium-reader/package.nix | 42 ++++++++++++++++------ 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/pkgs/by-name/th/thorium-reader/package.nix b/pkgs/by-name/th/thorium-reader/package.nix index 13ae3960b747..80bd319bd2b8 100644 --- a/pkgs/by-name/th/thorium-reader/package.nix +++ b/pkgs/by-name/th/thorium-reader/package.nix @@ -1,12 +1,15 @@ { lib, + stdenv, buildNpmPackage, fetchFromGitHub, nodejs_24, - makeWrapper, + makeShellWrapper, + makeBinaryWrapper, electron, copyDesktopItems, makeDesktopItem, + desktopToDarwinBundle, }: buildNpmPackage (finalAttrs: { @@ -24,23 +27,40 @@ buildNpmPackage (finalAttrs: { }; env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1"; + # makeBinaryWrapper is preferred on Darwin since the OS may confuse itself + # into thinking it needs Rosetta 2 if it encounters a non-MachO executable + # in a .app bundle + # Simultaneously, we need makeShellWrapper on linux platforms to pass + # electron-specific flags. nativeBuildInputs = [ - makeWrapper copyDesktopItems + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + makeShellWrapper + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + makeBinaryWrapper + desktopToDarwinBundle ]; - postInstall = '' - install -Dpm644 resources/icon.png $out/share/icons/thorium-reader.png + postInstall = + let + ozoneFlags = lib.optionalString stdenv.hostPlatform.isLinux ''--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}"''; + in + '' + install -Dpm644 resources/icon.png $out/share/icons/thorium-reader.png - cp -r dist/* $out/lib/node_modules/EDRLab.ThoriumReader/ + cp -r dist/* $out/lib/node_modules/EDRLab.ThoriumReader/ - makeWrapper '${lib.getExe electron}' "$out/bin/thorium-reader" \ - --add-flags $out/lib/node_modules/EDRLab.ThoriumReader \ - --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \ - --set-default ELECTRON_IS_DEV 0 \ - --inherit-argv0 - ''; + ${ + if stdenv.hostPlatform.isDarwin then "makeBinaryWrapper" else "makeWrapper" + } '${lib.getExe electron}' "$out/bin/thorium-reader" \ + --add-flags $out/lib/node_modules/EDRLab.ThoriumReader \ + ${ozoneFlags} \ + --set-default ELECTRON_IS_DEV 0 \ + --inherit-argv0 + ''; desktopItems = [ (makeDesktopItem {