about summary refs log tree commit diff
path: root/pkgs/applications/networking/instant-messengers/teams
diff options
context:
space:
mode:
authortricktron <tgagnaux@gmail.com>2022-02-02 17:58:34 +0100
committerGitHub <noreply@github.com>2022-02-02 11:58:34 -0500
commite8c6422be6da49976b3e988a6005c726c1267838 (patch)
tree46f00f710745a395afdcc7f3d8e23bde5a556cea /pkgs/applications/networking/instant-messengers/teams
parent2e2a63a0a1858797e633ff53248724c933aef357 (diff)
teams: add darwin support (#157006)
Diffstat (limited to 'pkgs/applications/networking/instant-messengers/teams')
-rw-r--r--pkgs/applications/networking/instant-messengers/teams/default.nix195
1 files changed, 118 insertions, 77 deletions
diff --git a/pkgs/applications/networking/instant-messengers/teams/default.nix b/pkgs/applications/networking/instant-messengers/teams/default.nix
index 52935267cf2e1..84310498eee40 100644
--- a/pkgs/applications/networking/instant-messengers/teams/default.nix
+++ b/pkgs/applications/networking/instant-messengers/teams/default.nix
@@ -14,109 +14,150 @@
 , xdg-utils
 , systemd
 , nodePackages
-, enableRectOverlay ? false }:
+, xar
+, cpio
+, makeWrapper
+, enableRectOverlay ? false
+}:
 
-stdenv.mkDerivation rec {
+let
   pname = "teams";
   version = "1.4.00.26453";
-
-  src = fetchurl {
-    url = "https://packages.microsoft.com/repos/ms-teams/pool/main/t/teams/teams_${version}_amd64.deb";
-    sha256 = "0ndqk893l17m42hf5fiiv6mka0v7v8r54kblvb67jsxajdvva5gf";
+  meta = with lib; {
+    description = "Microsoft Teams";
+    homepage = "https://teams.microsoft.com";
+    downloadPage = "https://teams.microsoft.com/downloads";
+    license = licenses.unfree;
+    maintainers = with maintainers; [ liff tricktron ];
+    platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
   };
 
-  nativeBuildInputs = [ dpkg autoPatchelfHook wrapGAppsHook nodePackages.asar ];
+  linux = stdenv.mkDerivation rec {
+    inherit pname version meta;
 
-  unpackCmd = "dpkg -x $curSrc .";
+    src = fetchurl {
+      url = "https://packages.microsoft.com/repos/ms-teams/pool/main/t/teams/teams_${version}_amd64.deb";
+      sha256 = "0ndqk893l17m42hf5fiiv6mka0v7v8r54kblvb67jsxajdvva5gf";
+    };
 
-  buildInputs = atomEnv.packages ++ [
-    libuuid
-    at-spi2-atk
-  ];
+    nativeBuildInputs = [ dpkg autoPatchelfHook wrapGAppsHook nodePackages.asar ];
 
-  runtimeDependencies = [
-    (lib.getLib systemd)
-    pulseaudio
-    libappindicator-gtk3
-  ];
+    unpackCmd = "dpkg -x $curSrc .";
 
-  preFixup = ''
-    gappsWrapperArgs+=(--prefix PATH : "${coreutils}/bin:${gawk}/bin")
-    gappsWrapperArgs+=(--add-flags --disable-namespace-sandbox)
-    gappsWrapperArgs+=(--add-flags --disable-setuid-sandbox)
-  '';
+    buildInputs = atomEnv.packages ++ [
+      libuuid
+      at-spi2-atk
+    ];
 
+    runtimeDependencies = [
+      (lib.getLib systemd)
+      pulseaudio
+      libappindicator-gtk3
+    ];
 
-  buildPhase = ''
-    runHook preBuild
+    preFixup = ''
+      gappsWrapperArgs+=(--prefix PATH : "${coreutils}/bin:${gawk}/bin")
+      gappsWrapperArgs+=(--add-flags --disable-namespace-sandbox)
+      gappsWrapperArgs+=(--add-flags --disable-setuid-sandbox)
+    '';
 
-    asar extract share/teams/resources/app.asar "$TMP/work"
-    substituteInPlace $TMP/work/main.bundle.js \
-        --replace "/usr/share/pixmaps/" "$out/share/pixmaps" \
-        --replace "/usr/bin/xdg-mime" "${xdg-utils}/bin/xdg-mime" \
-        --replace "Exec=/usr/bin/" "Exec=" # Remove usage of absolute path in autostart.
-    asar pack --unpack='{*.node,*.ftz,rect-overlay}' "$TMP/work" share/teams/resources/app.asar
 
-    runHook postBuild
-  '';
+    buildPhase = ''
+      runHook preBuild
 
-  preferLocalBuild = true;
+      asar extract share/teams/resources/app.asar "$TMP/work"
+      substituteInPlace $TMP/work/main.bundle.js \
+          --replace "/usr/share/pixmaps/" "$out/share/pixmaps" \
+          --replace "/usr/bin/xdg-mime" "${xdg-utils}/bin/xdg-mime" \
+          --replace "Exec=/usr/bin/" "Exec=" # Remove usage of absolute path in autostart.
+      asar pack --unpack='{*.node,*.ftz,rect-overlay}' "$TMP/work" share/teams/resources/app.asar
 
-  installPhase = ''
-    runHook preInstall
+      runHook postBuild
+    '';
 
-    mkdir -p $out/{opt,bin}
+    preferLocalBuild = true;
 
-    mv share/teams $out/opt/
-    mv share $out/share
+    installPhase = ''
+      runHook preInstall
 
-    substituteInPlace $out/share/applications/teams.desktop \
-      --replace /usr/bin/ ""
+      mkdir -p $out/{opt,bin}
 
-    ln -s $out/opt/teams/teams $out/bin/
+      mv share/teams $out/opt/
+      mv share $out/share
 
-    ${lib.optionalString (!enableRectOverlay) ''
-    # Work-around screen sharing bug
-    # https://docs.microsoft.com/en-us/answers/questions/42095/sharing-screen-not-working-anymore-bug.html
-    rm $out/opt/teams/resources/app.asar.unpacked/node_modules/slimcore/bin/rect-overlay
-    ''}
+      substituteInPlace $out/share/applications/teams.desktop \
+        --replace /usr/bin/ ""
 
-    runHook postInstall
-  '';
+      ln -s $out/opt/teams/teams $out/bin/
 
-  dontAutoPatchelf = true;
+      ${lib.optionalString (!enableRectOverlay) ''
+      # Work-around screen sharing bug
+      # https://docs.microsoft.com/en-us/answers/questions/42095/sharing-screen-not-working-anymore-bug.html
+      rm $out/opt/teams/resources/app.asar.unpacked/node_modules/slimcore/bin/rect-overlay
+      ''}
 
-  # Includes runtimeDependencies in the RPATH of the included Node modules
-  # so that dynamic loading works. We cannot use directly runtimeDependencies
-  # here, since the libraries from runtimeDependencies are not propagated
-  # to the dynamically loadable node modules because of a condition in
-  # autoPatchElfHook since *.node modules have Type: DYN (Shared object file)
-  # instead of EXEC or INTERP it expects.
-  # Fixes: https://github.com/NixOS/nixpkgs/issues/85449
-  postFixup = ''
-    autoPatchelf "$out"
+      runHook postInstall
+    '';
 
-    runtime_rpath="${lib.makeLibraryPath runtimeDependencies}"
+    dontAutoPatchelf = true;
 
-    for mod in $(find "$out/opt/teams" -name '*.node'); do
-      mod_rpath="$(patchelf --print-rpath "$mod")"
+    # Includes runtimeDependencies in the RPATH of the included Node modules
+    # so that dynamic loading works. We cannot use directly runtimeDependencies
+    # here, since the libraries from runtimeDependencies are not propagated
+    # to the dynamically loadable node modules because of a condition in
+    # autoPatchElfHook since *.node modules have Type: DYN (Shared object file)
+    # instead of EXEC or INTERP it expects.
+    # Fixes: https://github.com/NixOS/nixpkgs/issues/85449
+    postFixup = ''
+      autoPatchelf "$out"
 
-      echo "Adding runtime dependencies to RPATH of Node module $mod"
-      patchelf --set-rpath "$runtime_rpath:$mod_rpath" "$mod"
-    done;
+      runtime_rpath="${lib.makeLibraryPath runtimeDependencies}"
 
-    # fix for https://docs.microsoft.com/en-us/answers/questions/298724/open-teams-meeting-link-on-linux-doens39t-work.html?childToView=309406#comment-309406
-    # while we create the wrapper ourselves, gappsWrapperArgs leads to the same issue
-    # another option would be to introduce gappsWrapperAppendedArgs, to allow control of positioning
-    substituteInPlace "$out/bin/teams" --replace '.teams-wrapped"  --disable-namespace-sandbox --disable-setuid-sandbox "$@"' '.teams-wrapped" "$@" --disable-namespace-sandbox --disable-setuid-sandbox'
-  '';
+      for mod in $(find "$out/opt/teams" -name '*.node'); do
+        mod_rpath="$(patchelf --print-rpath "$mod")"
 
-  meta = with lib; {
-    description = "Microsoft Teams";
-    homepage = "https://teams.microsoft.com";
-    downloadPage = "https://teams.microsoft.com/downloads";
-    license = licenses.unfree;
-    maintainers = [ maintainers.liff ];
-    platforms = [ "x86_64-linux" ];
+        echo "Adding runtime dependencies to RPATH of Node module $mod"
+        patchelf --set-rpath "$runtime_rpath:$mod_rpath" "$mod"
+      done;
+
+      # fix for https://docs.microsoft.com/en-us/answers/questions/298724/open-teams-meeting-link-on-linux-doens39t-work.html?childToView=309406#comment-309406
+      # while we create the wrapper ourselves, gappsWrapperArgs leads to the same issue
+      # another option would be to introduce gappsWrapperAppendedArgs, to allow control of positioning
+      substituteInPlace "$out/bin/teams" --replace '.teams-wrapped"  --disable-namespace-sandbox --disable-setuid-sandbox "$@"' '.teams-wrapped" "$@" --disable-namespace-sandbox --disable-setuid-sandbox'
+    '';
+  };
+
+  appName = "Teams.app";
+
+  darwin = stdenv.mkDerivation {
+    inherit pname version meta;
+
+    src = fetchurl {
+      url = "https://statics.teams.cdn.office.net/production-osx/${version}/Teams_osx.pkg";
+      sha256 = "1mg6a3b3954w4xy5rlcrwxczymygl61dv2rxqp45sjcsh3hp39q0";
+    };
+
+    buildInputs = [ xar cpio makeWrapper ];
+
+    unpackPhase = ''
+      xar -xf $src
+      zcat < Teams_osx_app.pkg/Payload | cpio -i
+    '';
+
+    sourceRoot = "Microsoft\ Teams.app";
+    dontPatch = true;
+    dontConfigure = true;
+    dontBuild = true;
+
+    installPhase = ''
+      runHook preInstall
+      mkdir -p $out/{Applications/${appName},bin}
+      cp -R . $out/Applications/${appName}
+      makeWrapper $out/Applications/${appName}/Contents/MacOS/Teams $out/bin/teams
+      runHook postInstall
+    '';
   };
-}
+in
+if stdenv.isDarwin
+then darwin
+else linux