Unverified Commit a1ce4e69 authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

tetrio-desktop: add darwin support (#493450)

parents 31db9cdf 511cf4bb
Loading
Loading
Loading
Loading
+66 −26
Original line number Diff line number Diff line
@@ -2,29 +2,66 @@
  stdenv,
  lib,
  fetchzip,
  fetchurl,
  dpkg,
  makeWrapper,
  addDriverRunpath,
  electron,
  _7zz,
  withTetrioPlus ? false,
  tetrio-plus,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "tetrio-desktop";
let
  inherit (stdenv.hostPlatform) isDarwin system;

  version = "10";

  src = fetchzip {
    url = "https://tetr.io/about/desktop/builds/${finalAttrs.version}/TETR.IO%20Setup.deb";
  srcs = {
    x86_64-linux = fetchzip {
      url = "https://tetr.io/about/desktop/builds/${version}/TETR.IO%20Setup.deb";
      hash = "sha256-2FtFCajNEj7O8DGangDecs2yeKbufYLx1aZb3ShnYvw=";
      nativeBuildInputs = [ dpkg ];
    };
    aarch64-darwin = fetchurl {
      url = "https://tetr.io/about/desktop/builds/${version}/TETR.IO%20Setup%20arm64.dmg";
      hash = "sha256-PbK9XEynpii35p6DQYiPbaRM4guPazWd5N4Dr2O4H24=";
    };
    x86_64-darwin = fetchurl {
      url = "https://tetr.io/about/desktop/builds/${version}/TETR.IO%20Setup%20x86.dmg";
      hash = "sha256-I4Mj6YY7KwpLk2tZ02EdqUxnxSW/3vCM4J7YFzCLEuM=";
    };
  };
in
stdenv.mkDerivation {
  pname = "tetrio-desktop";
  inherit version;

  nativeBuildInputs = [
    makeWrapper
  ];
  src = srcs.${system} or (throw "Unsupported system: ${system}");

  nativeBuildInputs = lib.optionals (!isDarwin) [ makeWrapper ] ++ lib.optionals isDarwin [ _7zz ];

  sourceRoot = lib.optionalString isDarwin "TETR.IO.app";

  unpackPhase = lib.optionalString isDarwin ''
    7zz x $src
  '';

  installPhase =
    if isDarwin then
      ''
        runHook preInstall

        mkdir -p "$out/Applications/TETR.IO.app"
        cp -R . "$out/Applications/TETR.IO.app"

        ${lib.optionalString withTetrioPlus ''
          cp ${tetrio-plus} "$out/Applications/TETR.IO.app/Contents/Resources/app.asar"
        ''}

        runHook postInstall
      ''
    else
      let
        asarPath = if withTetrioPlus then tetrio-plus else "opt/TETR.IO/resources/app.asar";
      in
@@ -43,7 +80,7 @@ stdenv.mkDerivation (finalAttrs: {
        runHook postInstall
      '';

  postFixup = ''
  postFixup = lib.optionalString (!isDarwin) ''
    makeShellWrapper '${lib.getExe electron}' $out/bin/tetrio \
      --prefix LD_LIBRARY_PATH : ${addDriverRunpath.driverLink}/lib \
      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
@@ -61,8 +98,11 @@ stdenv.mkDerivation (finalAttrs: {
      Play multiplayer games against friends and foes all over the world, or claim a spot on the leaderboards - the stacker future is yours!
    '';
    mainProgram = "tetrio";
    maintainers = with lib.maintainers; [ huantian ];
    platforms = [ "x86_64-linux" ];
    maintainers = with lib.maintainers; [
      huantian
      anish
    ];
    platforms = [ "x86_64-linux" ] ++ lib.platforms.darwin;
    sourceProvenance = [ lib.sourceTypes.binaryBytecode ];
  };
})
}