Unverified Commit ee546cfe authored by Rhys Davies's avatar Rhys Davies
Browse files

microsoft-edge: Remove beta and dev versions

parent f6bdbd16
Loading
Loading
Loading
Loading
+0 −197
Original line number Diff line number Diff line
{ channel, version, revision, hash }:

{ stdenv
, fetchurl
, lib
, makeWrapper

, binutils-unwrapped
, xz
, gnutar
, file

, glibc
, glib
, nss
, nspr
, atk
, at-spi2-atk
, xorg
, cups
, dbus
, expat
, libdrm
, libxkbcommon
, pipewire
, gtk3
, pango
, cairo
, gdk-pixbuf
, mesa
, alsa-lib
, at-spi2-core
, libuuid
, systemd
, wayland
, libGL

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

let

  baseName = "microsoft-edge";

  shortName = if channel == "stable"
              then "msedge"
              else "msedge-" + channel;

  longName = if channel == "stable"
             then baseName
             else baseName + "-" + channel;

  iconSuffix = lib.optionalString (channel != "stable") "_${channel}";

  desktopSuffix = lib.optionalString (channel != "stable") "-${channel}";
in

stdenv.mkDerivation rec {
  pname="${baseName}-${channel}";
  inherit version;

  src = fetchurl {
    url = "https://packages.microsoft.com/repos/edge/pool/main/m/${baseName}-${channel}/${baseName}-${channel}_${version}-${revision}_amd64.deb";
    inherit hash;
  };

  nativeBuildInputs = [
    makeWrapper
  ];

  unpackCmd = "${binutils-unwrapped}/bin/ar p $src data.tar.xz | ${xz}/bin/xz -dc | ${gnutar}/bin/tar -xf -";
  sourceRoot = ".";

  dontPatch = true;
  dontConfigure = true;
  dontPatchELF = true;

  buildPhase = let
    libPath = {
      msedge = lib.makeLibraryPath [
        glibc glib nss nspr atk at-spi2-atk xorg.libX11
        xorg.libxcb cups.lib dbus.lib expat libdrm
        xorg.libXcomposite xorg.libXdamage xorg.libXext
        xorg.libXfixes xorg.libXrandr libxkbcommon
        pipewire gtk3 pango cairo gdk-pixbuf mesa
        alsa-lib at-spi2-core xorg.libxshmfence systemd wayland
      ];
      naclHelper = lib.makeLibraryPath [
        glib nspr atk libdrm xorg.libxcb mesa xorg.libX11
        xorg.libXext dbus.lib libxkbcommon
      ];
      libwidevinecdm = lib.makeLibraryPath [
        glib nss nspr
      ];
      libGLESv2 = lib.makeLibraryPath [
        xorg.libX11 xorg.libXext xorg.libxcb wayland libGL
      ];
      liboneauth = lib.makeLibraryPath [
        libuuid xorg.libX11
      ];
    };
  in ''
    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath "${libPath.msedge}" \
      opt/microsoft/${shortName}/msedge

    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      opt/microsoft/${shortName}/msedge-sandbox

    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      opt/microsoft/${shortName}/msedge_crashpad_handler

    patchelf \
      --set-rpath "${libPath.libwidevinecdm}" \
      opt/microsoft/${shortName}/WidevineCdm/_platform_specific/linux_x64/libwidevinecdm.so

    patchelf \
      --set-rpath "${libPath.libGLESv2}" \
      opt/microsoft/${shortName}/libGLESv2.so

    patchelf \
      --set-rpath "${libPath.liboneauth}" \
      opt/microsoft/${shortName}/liboneauth.so
  '' + lib.optionalString (lib.versionOlder version "121") ''
    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath "${libPath.naclHelper}" \
      opt/microsoft/${shortName}/nacl_helper
  '';

  installPhase = ''
    mkdir -p $out
    cp -R opt usr/bin usr/share $out

    ${if channel == "stable"
      then "ln -sf $out/bin/${longName} $out/bin/${baseName}-${channel}"
      else "ln -sf $out/opt/microsoft/${shortName}/${baseName}-${channel} $out/opt/microsoft/${shortName}/${baseName}"}

    ln -sf $out/opt/microsoft/${shortName}/${longName} $out/bin/${longName}

    rm -rf $out/share/doc
    rm -rf $out/opt/microsoft/${shortName}/cron

    for icon in '16' '24' '32' '48' '64' '128' '256'
    do
      ${ "icon_source=$out/opt/microsoft/${shortName}/product_logo_\${icon}${iconSuffix}.png" }
      ${ "icon_target=$out/share/icons/hicolor/\${icon}x\${icon}/apps" }
      mkdir -p $icon_target
      cp $icon_source $icon_target/microsoft-edge${desktopSuffix}.png
    done

    substituteInPlace $out/share/applications/${longName}.desktop \
      --replace /usr/bin/${baseName}-${channel} $out/bin/${longName}

    substituteInPlace $out/share/gnome-control-center/default-apps/${longName}.xml \
      --replace /opt/microsoft/${shortName} $out/opt/microsoft/${shortName}

    substituteInPlace $out/share/menu/${longName}.menu \
      --replace /opt/microsoft/${shortName} $out/opt/microsoft/${shortName}

    substituteInPlace $out/opt/microsoft/${shortName}/xdg-mime \
      --replace "\''${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" "\''${XDG_DATA_DIRS:-/run/current-system/sw/share}" \
      --replace "xdg_system_dirs=/usr/local/share/:/usr/share/" "xdg_system_dirs=/run/current-system/sw/share/" \
      --replace /usr/bin/file ${file}/bin/file

    substituteInPlace $out/opt/microsoft/${shortName}/default-app-block \
      --replace /opt/microsoft/${shortName} $out/opt/microsoft/${shortName}

    substituteInPlace $out/opt/microsoft/${shortName}/xdg-settings \
      --replace "\''${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" "\''${XDG_DATA_DIRS:-/run/current-system/sw/share}" \
      --replace "\''${XDG_CONFIG_DIRS:-/etc/xdg}" "\''${XDG_CONFIG_DIRS:-/run/current-system/sw/etc/xdg}"
  '';

  postFixup = ''
    wrapProgram "$out/bin/${longName}" \
      --prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.pname}-${gtk3.version}" \
      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
      --add-flags ${lib.escapeShellArg commandLineArgs}
  '';

  # We only want automatic updates for stable, beta and dev will get updated by the same script
  # and are only used for testing.
  passthru = lib.optionalAttrs (channel == "stable") { updateScript = ./update.py; };

  meta = with lib; {
    homepage = "https://www.microsoft.com/en-us/edge";
    description = "Web browser from Microsoft";
    license = licenses.unfree;
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    platforms = [ "x86_64-linux" ];
    maintainers = with maintainers; [ zanculmarktum kuwii rhysmdnz ];
  };
}
+194 −17
Original line number Diff line number Diff line
{
  beta = import ./browser.nix {
    channel = "beta";
    version = "130.0.2849.5";
    revision = "1";
    hash = "sha256-chvB84+zu6/xgRHyUk33aicc44QJLxxdOOu0ngqmsFM=";
  };
  dev = import ./browser.nix {
    channel = "dev";
    version = "130.0.2849.1";
    revision = "1";
    hash = "sha256-JObqtaaUR6J4rZ90WWw7Ku5Ntl/QBWHo23T7Ohu5p1s=";
  };
  stable = import ./browser.nix {
{ stdenv
, fetchurl
, lib
, makeWrapper

, binutils-unwrapped
, xz
, gnutar
, file

, glibc
, glib
, nss
, nspr
, atk
, at-spi2-atk
, xorg
, cups
, dbus
, expat
, libdrm
, libxkbcommon
, pipewire
, gtk3
, pango
, cairo
, gdk-pixbuf
, mesa
, alsa-lib
, at-spi2-core
, libuuid
, systemd
, wayland
, libGL

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

let

  baseName = "microsoft-edge";

  channel = "stable";

  shortName = if channel == "stable"
              then "msedge"
              else "msedge-" + channel;

  longName = if channel == "stable"
             then baseName
             else baseName + "-" + channel;

  iconSuffix = lib.optionalString (channel != "stable") "_${channel}";

  desktopSuffix = lib.optionalString (channel != "stable") "-${channel}";
in

stdenv.mkDerivation rec {
  pname="${baseName}-${channel}";
  version = "129.0.2792.65";
    revision = "1";

  src = fetchurl {
    url = "https://packages.microsoft.com/repos/edge/pool/main/m/${baseName}-${channel}/${baseName}-${channel}_${version}-1_amd64.deb";
    hash = "sha256-xuCtHptE2CG4aiY7gu2sWW3Km4qfB0E/L/PBACIaKOc=";
  };

  nativeBuildInputs = [
    makeWrapper
  ];

  unpackCmd = "${binutils-unwrapped}/bin/ar p $src data.tar.xz | ${xz}/bin/xz -dc | ${gnutar}/bin/tar -xf -";
  sourceRoot = ".";

  dontPatch = true;
  dontConfigure = true;
  dontPatchELF = true;

  buildPhase = let
    libPath = {
      msedge = lib.makeLibraryPath [
        glibc glib nss nspr atk at-spi2-atk xorg.libX11
        xorg.libxcb cups.lib dbus.lib expat libdrm
        xorg.libXcomposite xorg.libXdamage xorg.libXext
        xorg.libXfixes xorg.libXrandr libxkbcommon
        pipewire gtk3 pango cairo gdk-pixbuf mesa
        alsa-lib at-spi2-core xorg.libxshmfence systemd wayland
      ];
      naclHelper = lib.makeLibraryPath [
        glib nspr atk libdrm xorg.libxcb mesa xorg.libX11
        xorg.libXext dbus.lib libxkbcommon
      ];
      libwidevinecdm = lib.makeLibraryPath [
        glib nss nspr
      ];
      libGLESv2 = lib.makeLibraryPath [
        xorg.libX11 xorg.libXext xorg.libxcb wayland libGL
      ];
      liboneauth = lib.makeLibraryPath [
        libuuid xorg.libX11
      ];
    };
  in ''
    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath "${libPath.msedge}" \
      opt/microsoft/${shortName}/msedge

    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      opt/microsoft/${shortName}/msedge-sandbox

    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      opt/microsoft/${shortName}/msedge_crashpad_handler

    patchelf \
      --set-rpath "${libPath.libwidevinecdm}" \
      opt/microsoft/${shortName}/WidevineCdm/_platform_specific/linux_x64/libwidevinecdm.so

    patchelf \
      --set-rpath "${libPath.libGLESv2}" \
      opt/microsoft/${shortName}/libGLESv2.so

    patchelf \
      --set-rpath "${libPath.liboneauth}" \
      opt/microsoft/${shortName}/liboneauth.so
  '' + lib.optionalString (lib.versionOlder version "121") ''
    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath "${libPath.naclHelper}" \
      opt/microsoft/${shortName}/nacl_helper
  '';

  installPhase = ''
    mkdir -p $out
    cp -R opt usr/bin usr/share $out

    ${if channel == "stable"
      then "ln -sf $out/bin/${longName} $out/bin/${baseName}-${channel}"
      else "ln -sf $out/opt/microsoft/${shortName}/${baseName}-${channel} $out/opt/microsoft/${shortName}/${baseName}"}

    ln -sf $out/opt/microsoft/${shortName}/${longName} $out/bin/${longName}

    rm -rf $out/share/doc
    rm -rf $out/opt/microsoft/${shortName}/cron

    for icon in '16' '24' '32' '48' '64' '128' '256'
    do
      ${ "icon_source=$out/opt/microsoft/${shortName}/product_logo_\${icon}${iconSuffix}.png" }
      ${ "icon_target=$out/share/icons/hicolor/\${icon}x\${icon}/apps" }
      mkdir -p $icon_target
      cp $icon_source $icon_target/microsoft-edge${desktopSuffix}.png
    done

    substituteInPlace $out/share/applications/${longName}.desktop \
      --replace /usr/bin/${baseName}-${channel} $out/bin/${longName}

    substituteInPlace $out/share/gnome-control-center/default-apps/${longName}.xml \
      --replace /opt/microsoft/${shortName} $out/opt/microsoft/${shortName}

    substituteInPlace $out/share/menu/${longName}.menu \
      --replace /opt/microsoft/${shortName} $out/opt/microsoft/${shortName}

    substituteInPlace $out/opt/microsoft/${shortName}/xdg-mime \
      --replace "\''${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" "\''${XDG_DATA_DIRS:-/run/current-system/sw/share}" \
      --replace "xdg_system_dirs=/usr/local/share/:/usr/share/" "xdg_system_dirs=/run/current-system/sw/share/" \
      --replace /usr/bin/file ${file}/bin/file

    substituteInPlace $out/opt/microsoft/${shortName}/default-app-block \
      --replace /opt/microsoft/${shortName} $out/opt/microsoft/${shortName}

    substituteInPlace $out/opt/microsoft/${shortName}/xdg-settings \
      --replace "\''${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" "\''${XDG_DATA_DIRS:-/run/current-system/sw/share}" \
      --replace "\''${XDG_CONFIG_DIRS:-/etc/xdg}" "\''${XDG_CONFIG_DIRS:-/run/current-system/sw/etc/xdg}"
  '';

  postFixup = ''
    wrapProgram "$out/bin/${longName}" \
      --prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.pname}-${gtk3.version}" \
      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
      --add-flags ${lib.escapeShellArg commandLineArgs}
  '';

  # We only want automatic updates for stable, beta and dev will get updated by the same script
  # and are only used for testing.
  passthru = lib.optionalAttrs (channel == "stable") { updateScript = ./update.py; };

  meta = with lib; {
    homepage = "https://www.microsoft.com/en-us/edge";
    description = "Web browser from Microsoft";
    license = licenses.unfree;
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    platforms = [ "x86_64-linux" ];
    maintainers = with maintainers; [ zanculmarktum kuwii rhysmdnz ];
  };
}
+5 −31
Original line number Diff line number Diff line
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3Packages.packaging python3Packages.debian
#! nix-shell -i python3 -p python3Packages.packaging python3Packages.debian common-updater-scripts

import base64
import textwrap
import os
from urllib import request

from collections import OrderedDict
@@ -22,7 +23,7 @@ def latest_packages(packages: bytes):
    latest_packages: OrderedDict[str, Packages] = {}
    for package in Packages.iter_paragraphs(packages, use_apt_pkg=False):
        name: str = package['Package']
        if not name.startswith('microsoft-edge-'):
        if not name.startswith('microsoft-edge-stable'):
            continue
        channel = name.replace('microsoft-edge-', '')
        if channel not in latest_packages:
@@ -34,37 +35,10 @@ def latest_packages(packages: bytes):
    return OrderedDict(sorted(latest_packages.items(), key=lambda x:x[0]))


def nix_expressions(latest: dict[str, Packages]):
    channel_strs: list[str] = []
    for channel, package in latest.items():
        print(f"Processing {channel} {package['Version']}")
        match = Version.re_valid_version.match(package['Version'])
        assert match is not None

        version = match.group('upstream_version')
        revision = match.group('debian_revision')
        sri = 'sha256-' + \
            base64.b64encode(bytes.fromhex(package['SHA256'])).decode('ascii')

        channel_str = textwrap.dedent(
            f'''\
            {channel} = import ./browser.nix {{
              channel = "{channel}";
              version = "{version}";
              revision = "{revision}";
              hash = "{sri}";
            }};'''
        )
        channel_strs.append(channel_str)
    return channel_strs


def write_expression():
    latest = latest_packages(packages())
    channel_strs = nix_expressions(latest)
    nix_expr = '{\n' + textwrap.indent('\n'.join(channel_strs), '  ') + '\n}\n'
    with open(PIN_PATH, 'w') as f:
        f.write(nix_expr)
    version = Version.re_valid_version.match(latest['stable']['Version']).group('upstream_version')
    os.system(f'update-source-version microsoft-edge "{version}"')


write_expression()
+1 −3
Original line number Diff line number Diff line
@@ -21993,9 +21993,7 @@ with pkgs;
  microsoft-gsl = callPackage ../development/libraries/microsoft-gsl { };
  microsoft-edge = callPackage (import ../applications/networking/browsers/microsoft-edge).stable { };
  microsoft-edge-beta = callPackage (import ../applications/networking/browsers/microsoft-edge).beta { };
  microsoft-edge-dev = callPackage (import ../applications/networking/browsers/microsoft-edge).dev { };
  microsoft-edge = callPackage ../applications/networking/browsers/microsoft-edge { };
  micronucleus = callPackage ../development/tools/misc/micronucleus { };