Unverified Commit 4f10285e authored by Weijia Wang's avatar Weijia Wang Committed by GitHub
Browse files

brave: darwin support, add darwin maintainer (#352880)

parents dffbf170 c00f0731
Loading
Loading
Loading
Loading
+75 −48
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@
  xorg,
  zlib,

  # Darwin dependencies
  unzip,
  makeWrapper,

  # command line arguments which are always set e.g "--disable-gpu"
  commandLineArgs ? "",

@@ -76,7 +80,6 @@
  version,
  hash,
  url,
  platform,
}:

let
@@ -161,16 +164,21 @@ stdenv.mkDerivation {
  dontConfigure = true;
  dontBuild = true;
  dontPatchELF = true;
  doInstallCheck = true;
  doInstallCheck = stdenv.hostPlatform.isLinux;

  nativeBuildInputs = [
  nativeBuildInputs =
    lib.optionals stdenv.hostPlatform.isLinux [
      dpkg
      # override doesn't preserve splicing https://github.com/NixOS/nixpkgs/issues/132651
      # Has to use `makeShellWrapper` from `buildPackages` even though `makeShellWrapper` from the inputs is spliced because `propagatedBuildInputs` would pick the wrong one because of a different offset.
      (buildPackages.wrapGAppsHook3.override { makeWrapper = buildPackages.makeShellWrapper; })
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin [
      unzip
      makeWrapper
    ];

  buildInputs = [
  buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
    # needed for GSETTINGS_SCHEMAS_PATH
    glib
    gsettings-desktop-schemas
@@ -181,9 +189,14 @@ stdenv.mkDerivation {
    adwaita-icon-theme
  ];

  unpackPhase = "dpkg-deb --fsys-tarfile $src | tar -x --no-same-permissions --no-same-owner";
  unpackPhase =
    if stdenv.hostPlatform.isLinux then
      "dpkg-deb --fsys-tarfile $src | tar -x --no-same-permissions --no-same-owner"
    else
      "unzip $src";

  installPhase = ''
  installPhase =
    lib.optionalString stdenv.hostPlatform.isLinux ''
      runHook preInstall

      mkdir -p $out $out/bin
@@ -228,10 +241,21 @@ stdenv.mkDerivation {
      ln -sf ${xdg-utils}/bin/xdg-settings $out/opt/brave.com/brave/xdg-settings
      ln -sf ${xdg-utils}/bin/xdg-mime $out/opt/brave.com/brave/xdg-mime

      runHook postInstall
    ''
    + lib.optionalString stdenv.hostPlatform.isDarwin ''
      runHook preInstall

      mkdir -p $out/{Applications,bin}

      cp -r "Brave Browser.app" $out/Applications/

      makeWrapper "$out/Applications/Brave Browser.app/Contents/MacOS/Brave Browser" $out/bin/brave

      runHook postInstall
    '';

  preFixup = ''
  preFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
    # Add command line args to wrapGApp.
    gappsWrapperArgs+=(
      --prefix LD_LIBRARY_PATH : ${rpath}
@@ -286,10 +310,13 @@ stdenv.mkDerivation {
      jefflabonte
      nasirhm
      buckley310
      matteopacini
    ];
    platforms = [
      "aarch64-linux"
      "x86_64-linux"
      "aarch64-darwin"
      "x86_64-darwin"
    ];
    mainProgram = "brave";
  };
+8 −1
Original line number Diff line number Diff line
@@ -14,6 +14,14 @@ let
      url = "https://github.com/brave/brave-browser/releases/download/v${version}/brave-browser_${version}_amd64.deb";
      hash = "sha256-fJczTAra+j8+veicz4lIyKSNJyxJK4q9gpZoAyQwkxQ=";
    };
    aarch64-darwin = {
      url = "https://github.com/brave/brave-browser/releases/download/v${version}/brave-v${version}-darwin-arm64.zip";
      hash = "sha256-kDiZ6NKQ+v1jBEUexItKTCKFsbnOtSzPmGEVWI5JoXI=";
    };
    x86_64-darwin = {
      url = "https://github.com/brave/brave-browser/releases/download/v${version}/brave-v${version}-darwin-x64.zip";
      hash = "sha256-/yl4k/XvmL7oBW1XU4wVNHfa07Z+XMHYTkkufhDCXUc=";
    };
  };

  archive =
@@ -27,6 +35,5 @@ callPackage ./make-brave.nix (removeAttrs args [ "callPackage" ]) (
  archive
  // {
    inherit pname version;
    platform = stdenv.system;
  }
)
+12 −9
Original line number Diff line number Diff line
@@ -5,15 +5,10 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

latestVersion="$(curl --fail -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} "https://api.github.com/repos/brave/brave-browser/releases/latest" | jq -r '.tag_name' | sed 's/^v//')"

hashAarch64="$(nix hash to-sri --type sha256 \
    $(curl -sL https://brave-browser-apt-release.s3.brave.com/dists/stable/main/binary-arm64/Packages \
    | sed -r -n 's/^SHA256: (.*)/\1/p' | head -n1)
)"

hashAmd64="$(nix hash to-sri --type sha256 \
    $(curl -sL https://brave-browser-apt-release.s3.brave.com/dists/stable/main/binary-amd64/Packages \
    | sed -r -n 's/^SHA256: (.*)/\1/p' | head -n1)
)"
hashAarch64="$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url --type sha256 "https://github.com/brave/brave-browser/releases/download/v${latestVersion}/brave-browser_${latestVersion}_arm64.deb")")"
hashAmd64="$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url --type sha256 "https://github.com/brave/brave-browser/releases/download/v${latestVersion}/brave-browser_${latestVersion}_amd64.deb")")"
hashAarch64Darwin="$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url --type sha256 "https://github.com/brave/brave-browser/releases/download/v${latestVersion}/brave-v${latestVersion}-darwin-arm64.zip")")"
hashAmd64Darwin="$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url --type sha256 "https://github.com/brave/brave-browser/releases/download/v${latestVersion}/brave-v${latestVersion}-darwin-x64.zip")")"

cat > $SCRIPT_DIR/package.nix << EOF
# Expression generated by update.sh; do not edit it by hand!
@@ -32,6 +27,14 @@ let
      url = "https://github.com/brave/brave-browser/releases/download/v\${version}/brave-browser_\${version}_amd64.deb";
      hash = "${hashAmd64}";
    };
    aarch64-darwin = {
      url = "https://github.com/brave/brave-browser/releases/download/v\${version}/brave-v\${version}-darwin-arm64.zip";
      hash = "${hashAarch64Darwin}";
    };
    x86_64-darwin = {
      url = "https://github.com/brave/brave-browser/releases/download/v\${version}/brave-v\${version}-darwin-x64.zip";
      hash = "${hashAmd64Darwin}";
    };
  };

  archive =