2019-12-11 12:38:30 +00:00
{ lib
, stdenv
, fetchurl
, autoPatchelfHook
, wrapGAppsHook
, dpkg
, atomEnv
, libuuid
2021-06-01 20:08:20 +01:00
, libappindicator-gtk3
2019-12-11 12:38:30 +00:00
, pulseaudio
, at-spi2-atk
, coreutils
, gawk
2021-02-01 08:05:09 +00:00
, xdg-utils
2021-06-08 20:57:13 +01:00
, systemd
2021-06-26 15:31:30 +01:00
, nodePackages
2022-02-02 16:58:34 +00:00
, xar
, cpio
, makeWrapper
, enableRectOverlay ? false
} :
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
let
2019-12-11 12:38:30 +00:00
pname = " t e a m s " ;
2021-10-13 21:21:41 +01:00
version = " 1 . 4 . 0 0 . 2 6 4 5 3 " ;
2022-02-02 16:58:34 +00:00
meta = with lib ; {
description = " M i c r o s o f t T e a m s " ;
homepage = " h t t p s : / / t e a m s . m i c r o s o f t . c o m " ;
downloadPage = " h t t p s : / / t e a m s . m i c r o s o f t . c o m / d o w n l o a d s " ;
license = licenses . unfree ;
maintainers = with maintainers ; [ liff tricktron ] ;
platforms = [ " x 8 6 _ 6 4 - l i n u x " " x 8 6 _ 6 4 - d a r w i n " " a a r c h 6 4 - d a r w i n " ] ;
2019-12-11 12:38:30 +00:00
} ;
2022-02-02 16:58:34 +00:00
linux = stdenv . mkDerivation rec {
inherit pname version meta ;
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
src = fetchurl {
url = " h t t p s : / / p a c k a g e s . m i c r o s o f t . c o m / r e p o s / m s - t e a m s / p o o l / m a i n / t / t e a m s / t e a m s _ ${ version } _ a m d 6 4 . d e b " ;
sha256 = " 0 n d q k 8 9 3 l 1 7 m 4 2 h f 5 f i i v 6 m k a 0 v 7 v 8 r 5 4 k b l v b 6 7 j s x a j d v v a 5 g f " ;
} ;
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
nativeBuildInputs = [ dpkg autoPatchelfHook wrapGAppsHook nodePackages . asar ] ;
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
unpackCmd = " d p k g - x $ c u r S r c . " ;
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
buildInputs = atomEnv . packages ++ [
libuuid
at-spi2-atk
] ;
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
runtimeDependencies = [
( lib . getLib systemd )
pulseaudio
libappindicator-gtk3
] ;
2021-06-26 15:31:30 +01:00
2022-02-02 16:58:34 +00:00
preFixup = ''
gappsWrapperArgs + = ( - - prefix PATH : " ${ coreutils } / b i n : ${ gawk } / b i n " )
gappsWrapperArgs + = ( - - add-flags - - disable-namespace-sandbox )
gappsWrapperArgs + = ( - - add-flags - - disable-setuid-sandbox )
'' ;
2021-06-26 15:31:30 +01:00
2022-02-02 16:58:34 +00:00
buildPhase = ''
runHook preBuild
2021-06-26 15:31:30 +01:00
2022-02-02 16:58:34 +00:00
asar extract share/teams/resources/app.asar " $ T M P / w o r k "
substituteInPlace $ TMP/work/main.bundle.js \
- - replace " / u s r / s h a r e / p i x m a p s / " " $ o u t / s h a r e / p i x m a p s " \
- - replace " / u s r / b i n / x d g - m i m e " " ${ xdg-utils } / b i n / x d g - m i m e " \
- - replace " E x e c = / u s r / b i n / " " E x e c = " # Remove usage of absolute path in autostart.
asar pack - - unpack = ' { * . node , * . ftz , rect-overlay } ' " $ T M P / w o r k " share/teams/resources/app.asar
2021-06-26 15:31:30 +01:00
2022-02-02 16:58:34 +00:00
runHook postBuild
'' ;
2021-03-11 19:28:47 +00:00
2022-02-02 16:58:34 +00:00
preferLocalBuild = true ;
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
installPhase = ''
runHook preInstall
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
mkdir - p $ out / { opt , bin }
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
mv share/teams $ out/opt /
mv share $ out/share
2020-10-28 08:39:08 +00:00
2022-02-02 16:58:34 +00:00
substituteInPlace $ out/share/applications/teams.desktop \
- - replace /usr/bin / " "
2021-03-11 19:28:47 +00:00
2022-02-02 16:58:34 +00:00
ln - s $ out/opt/teams/teams $ out/bin /
2019-12-11 12:38:30 +00:00
2022-02-02 16:58:34 +00:00
$ { 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
'' }
2020-04-17 17:23:31 +01:00
2022-02-02 16:58:34 +00:00
runHook postInstall
'' ;
2020-04-17 17:23:31 +01:00
2022-02-02 16:58:34 +00:00
dontAutoPatchelf = true ;
2020-04-17 17:23:31 +01:00
2022-02-02 16:58:34 +00:00
# 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 " $ o u t "
2020-04-17 17:23:31 +01:00
2022-02-02 16:58:34 +00:00
runtime_rpath = " ${ lib . makeLibraryPath runtimeDependencies } "
2021-03-17 10:42:31 +00:00
2022-02-02 16:58:34 +00:00
for mod in $ ( find " $ o u t / o p t / t e a m s " - name ' * . node' ) ; do
mod_rpath = " $ ( p a t c h e l f - - p r i n t - r p a t h " $ mod " ) "
2020-04-17 17:23:31 +01:00
2022-02-02 16:58:34 +00:00
echo " A d d i n g r u n t i m e d e p e n d e n c i e s t o R P A T H o f N o d e m o d u l e $ m o d "
patchelf - - set-rpath " $ r u n t i m e _ r p a t h : $ m o d _ r p a t h " " $ m o d "
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 " $ o u t / b i n / t e a m s " - - replace ' . teams-wrapped " - - d i s a b l e - n a m e s p a c e - s a n d b o x - - d i s a b l e - s e t u i d - s a n d b o x " $ @ " ' ' . t e a m s - w r a p p e d " " $ @ " - - disable-namespace-sandbox - - disable-setuid-sandbox'
'' ;
} ;
appName = " T e a m s . a p p " ;
darwin = stdenv . mkDerivation {
inherit pname version meta ;
src = fetchurl {
url = " h t t p s : / / s t a t i c s . t e a m s . c d n . o f f i c e . n e t / p r o d u c t i o n - o s x / ${ version } / T e a m s _ o s x . p k g " ;
sha256 = " 1 m g 6 a 3 b 3 9 5 4 w 4 x y 5 r l c r w x c z y m y g l 6 1 d v 2 r x q p 4 5 s j c s h 3 h p 3 9 q 0 " ;
} ;
buildInputs = [ xar cpio makeWrapper ] ;
unpackPhase = ''
xar - xf $ src
zcat < Teams_osx_app.pkg/Payload | cpio - i
'' ;
sourceRoot = " M i c r o s o f t \ T e a m s . a p p " ;
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
'' ;
2019-12-11 12:38:30 +00:00
} ;
2022-02-02 16:58:34 +00:00
in
if stdenv . isDarwin
then darwin
else linux