diff --git a/pkgs/by-name/ne/nextcloud-talk-desktop/package.nix b/pkgs/by-name/ne/nextcloud-talk-desktop/package.nix index c17cbca9ef66b..410f2ed33554a 100644 --- a/pkgs/by-name/ne/nextcloud-talk-desktop/package.nix +++ b/pkgs/by-name/ne/nextcloud-talk-desktop/package.nix @@ -20,98 +20,157 @@ libGL, libglvnd, systemd, - nix-update-script, + patchelf, + undmg, + makeWrapper, }: - -stdenv.mkDerivation (finalAttrs: { +let pname = "nextcloud-talk-desktop"; - version = "2.0.3"; - - # Building from source would require building also building Server and Talk components - # See https://github.com/nextcloud/talk-desktop?tab=readme-ov-file#%EF%B8%8F-prerequisites - src = fetchzip { - url = "https://github.com/nextcloud-releases/talk-desktop/releases/download/v${finalAttrs.version}/Nextcloud.Talk-linux-x64.zip"; - hash = "sha256-QKbg5vHLuxLpngrHom/odWw9RK43jhZsEg7Df5c7db0="; - stripRoot = false; + version = "2.0.4"; # Ensure both hashes (Linux and Darwin) are updated! + + hashes = { + linux = "sha256-Nky3ws1UV0F4qjbBog53BjXkZ/ttTER/32NlB2ONJaE="; + darwin = "sha256-N/v1842rheqrjG4pAwrSDYNWhQDgWinTiZPusD1dvaM="; }; - icon = fetchurl { - url = "https://raw.githubusercontent.com/nextcloud/talk-desktop/refs/tags/v1.0.0/img/icons/icon.png"; - hash = "sha256-DteSSuxIs0ukIJrvUO/3Mrh5F2GG5UAVvGRZUuZonkg="; + # Only x86_64-linux is supported with Darwin support being universal + sources = { + # Building from source would require building also building Server and Talk components + # See https://github.com/nextcloud/talk-desktop?tab=readme-ov-file#%EF%B8%8F-prerequisites + linux = fetchzip { + url = "https://github.com/nextcloud-releases/talk-desktop/releases/download/v${version}/Nextcloud.Talk-linux-x64.zip"; + hash = hashes.linux; + stripRoot = false; + }; + darwin = fetchurl { + url = "https://github.com/nextcloud-releases/talk-desktop/releases/download/v${version}/Nextcloud.Talk-macos-universal.dmg"; + hash = hashes.darwin; + }; }; - nativeBuildInputs = [ - autoPatchelfHook - copyDesktopItems - ]; - - buildInputs = [ - nss - cairo - alsa-lib - at-spi2-core - pango - libdrm - libxkbcommon - gtk3 - vivaldi-ffmpeg-codecs - libgbm - libGL - libglvnd - ] - ++ (with xorg; [ - libX11 - libXcomposite - libXdamage - libXrandr - libXfixes - libXcursor - ]); - - # Required to launch the application and proceed past the zygote_linux fork() process - # Fixes `Zygote could not fork` - runtimeDependencies = [ systemd ]; - - desktopItems = [ - (makeDesktopItem { - type = "Application"; - name = "nextcloud-talk-desktop"; - desktopName = "Nextcloud Talk"; - comment = finalAttrs.meta.description; - exec = finalAttrs.meta.mainProgram; - icon = "nextcloud-talk-desktop"; - categories = [ "Chat" ]; - }) - ]; - - preInstall = '' - mkdir -p $out/bin - mkdir -p $out/opt - - cp -r $src/* $out/opt/ - ''; - - installPhase = '' - runHook preInstall - - # Link the application in $out/bin away from contents of `preInstall` - ln -s "$out/opt/Nextcloud Talk-linux-x64/Nextcloud Talk" $out/bin/nextcloud-talk-desktop - mkdir -p $out/share/icons/hicolor/512x512/apps - cp $icon $out/share/icons/hicolor/512x512/apps/nextcloud-talk-desktop.png - - runHook postInstall - ''; - - passthru.updateScript = nix-update-script { }; + passthru = { + inherit hashes; # needed by updateScript + updateScript = ./update.py; + }; meta = { description = "Nextcloud Talk Desktop Client"; homepage = "https://github.com/nextcloud/talk-desktop"; - changelog = "https://github.com/nextcloud/talk-desktop/blob/${finalAttrs.version}/CHANGELOG.md"; + changelog = "https://github.com/nextcloud/talk-desktop/blob/${version}/CHANGELOG.md"; license = lib.licenses.agpl3Only; maintainers = with lib.maintainers; [ kashw2 ]; - mainProgram = "nextcloud-talk-desktop"; sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; - platforms = [ "x86_64-linux" ]; + mainProgram = "nextcloud-talk-desktop"; }; -}) + + linux = stdenv.mkDerivation (finalAttrs: { + inherit pname version passthru; + + src = sources.linux; + + icon = fetchurl { + url = "https://raw.githubusercontent.com/nextcloud/talk-desktop/refs/tags/v${version}/img/icons/icon.png"; + hash = "sha256-DteSSuxIs0ukIJrvUO/3Mrh5F2GG5UAVvGRZUuZonkg="; + }; + + nativeBuildInputs = [ + autoPatchelfHook + copyDesktopItems + ]; + + buildInputs = [ + nss + cairo + alsa-lib + at-spi2-core + pango + libdrm + libxkbcommon + gtk3 + vivaldi-ffmpeg-codecs + libgbm + libGL + libglvnd + ] + ++ (with xorg; [ + libX11 + libXcomposite + libXdamage + libXrandr + libXfixes + libXcursor + ]); + + # Required to launch the application and proceed past the zygote_linux fork() process + # Fixes `Zygote could not fork` + runtimeDependencies = [ systemd ]; + + desktopItems = [ + (makeDesktopItem { + type = "Application"; + name = "nextcloud-talk-desktop"; + desktopName = "Nextcloud Talk"; + comment = finalAttrs.meta.description; + exec = finalAttrs.meta.mainProgram; + icon = "nextcloud-talk-desktop"; + categories = [ "Chat" ]; + }) + ]; + + preInstall = '' + mkdir -p $out/bin + mkdir -p $out/opt + + cp -r $src/* $out/opt/ + ''; + + installPhase = '' + runHook preInstall + + # Link the application in $out/bin away from contents of `preInstall` + ln -s "$out/opt/Nextcloud Talk-linux-x64/Nextcloud Talk" $out/bin/nextcloud-talk-desktop + mkdir -p $out/share/icons/hicolor/512x512/apps + cp $icon $out/share/icons/hicolor/512x512/apps/nextcloud-talk-desktop.png + + runHook postInstall + ''; + + postFixup = '' + ${lib.getExe patchelf} --add-needed libGL.so.1 --add-needed libEGL.so.1 \ + "$out/opt/Nextcloud Talk-linux-x64/Nextcloud Talk" + ''; + + meta = meta // { + platforms = lib.intersectLists lib.platforms.linux lib.platforms.x86_64; + }; + }); + + darwin = stdenv.mkDerivation (finalAttrs: { + inherit pname version passthru; + + src = sources.darwin; + + nativeBuildInputs = [ + undmg + makeWrapper + ]; + + sourceRoot = "."; + + installPhase = '' + runHook preInstall + + mkdir -p $out/{Applications,bin} + mv Nextcloud\ Talk.app/Contents $out/Applications/ + + makeWrapper $out/Applications/Contents/MacOS/Nextcloud\ Talk $out/bin/nextcloud-talk-desktop + + runHook postInstall + ''; + + meta = meta // { + platforms = lib.platforms.darwin; + }; + }); +in +if stdenv.hostPlatform.isDarwin then darwin else linux diff --git a/pkgs/by-name/ne/nextcloud-talk-desktop/update.py b/pkgs/by-name/ne/nextcloud-talk-desktop/update.py new file mode 100755 index 0000000000000..21027bfc551db --- /dev/null +++ b/pkgs/by-name/ne/nextcloud-talk-desktop/update.py @@ -0,0 +1,39 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i python3 -p python3 bash nix-update jq + +import subprocess +from os.path import join, dirname + +# This will set the version correctly, +# and will also set the hash for x86_64-linux. +subprocess.run(["nix-update", "nextcloud-talk-desktop"]) + +# Now get the hash for Darwin. +# (It's the same for both Darwin platforms, and we don't support aarch64-linux). +newVer = subprocess.run( + ["nix-instantiate", "--eval", "--raw", "-A", "nextcloud-talk-desktop.version"], capture_output=True, encoding="locale" +).stdout + +darwinUrl = ( + f"https://github.com/nextcloud-releases/talk-desktop/releases/download/v{newVer}/Nextcloud.Talk-macos-universal.dmg" +) + +oldDarwinHash = subprocess.run( + ["nix-instantiate", "--eval", "--raw", "-A", f"nextcloud-talk-desktop.passthru.hashes.darwin"], + capture_output=True, + encoding="locale", +).stdout + +newDarwinHash = subprocess.run( + ["bash", "-c", f"nix store prefetch-file {darwinUrl} --json | jq -r '.hash'"], + capture_output=True, + encoding="locale", +).stdout.strip() # Has a newline + +with open(join(dirname(__file__), "package.nix"), "r") as f: + txt = f.read() + +txt = txt.replace(oldDarwinHash, newDarwinHash) + +with open(join(dirname(__file__), "package.nix"), "w") as f: + f.write(txt)