From d034dd2cb172f115eac4df41d36da2ec720b7423 Mon Sep 17 00:00:00 2001 From: blokyk Date: Sat, 17 Oct 2026 21:51:35 +0200 Subject: [PATCH] dart.flutter_webrtc: init this migrates what was already done in the fluffychat derivation, and once commet-chat updates to 0.5.0 and thus to flutter_webrtc >= 1.5, (which is underway in #566626), it can also apply to it. i also threw together a small, hacky script for easily fetching new hashes of libwebrtc. --- pkgs/by-name/co/commet-chat/package.nix | 2 + pkgs/by-name/fl/fluffychat/package.nix | 86 +--------------- .../dart/package-source-builders/default.nix | 1 + .../flutter_webrtc/default.nix | 97 +++++++++++++++++++ .../flutter_webrtc/fetch-webrtc-version.sh | 64 ++++++++++++ .../flutter_webrtc/libwebrtc-info.json | 9 ++ 6 files changed, 174 insertions(+), 85 deletions(-) create mode 100644 pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/default.nix create mode 100755 pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/fetch-webrtc-version.sh create mode 100644 pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/libwebrtc-info.json diff --git a/pkgs/by-name/co/commet-chat/package.nix b/pkgs/by-name/co/commet-chat/package.nix index 9bf90ddf9f95..f0e2d3703846 100644 --- a/pkgs/by-name/co/commet-chat/package.nix +++ b/pkgs/by-name/co/commet-chat/package.nix @@ -88,6 +88,8 @@ flutter341.buildFlutterApplication (finalAttrs: { targetFlutterPlatform = "linux"; customSourceBuilders = { + # fixme: once commet-chat updates to flutter_webrtc >= 1.5 (in the next releases), + # this can be removed, tho you'll need to update the libwebrtc-info.json file flutter_webrtc = { version, src, ... }: stdenv.mkDerivation { diff --git a/pkgs/by-name/fl/fluffychat/package.nix b/pkgs/by-name/fl/fluffychat/package.nix index 27fa365d6a92..21eec12344de 100644 --- a/pkgs/by-name/fl/fluffychat/package.nix +++ b/pkgs/by-name/fl/fluffychat/package.nix @@ -2,12 +2,8 @@ lib, stdenv, fetchFromGitHub, - fetchzip, - imagemagick, - libgbm, - libdrm, flutter344, - pulseaudio, + imagemagick, webkitgtk_4_1, copyDesktopItems, makeDesktopItem, @@ -17,24 +13,7 @@ }: let - libwebrtcRpath = lib.makeLibraryPath [ - libgbm - libdrm - ]; pubspecLock = lib.importJSON ./pubspec.lock.json; - libwebrtc_version = "m144.7559.09"; - libwebrtc = - { - x86_64-linux = fetchzip { - url = "https://github.com/webrtc-sdk/libwebrtc/releases/download/libwebrtc.${libwebrtc_version}/libwebrtc-linux-x64-release.zip"; - sha256 = "sha256-uzS07voCGM1zs663UalYpb8pWiYpkrKMxKt/wB4rcB4="; - }; - aarch64-linux = fetchzip { - url = "https://github.com/webrtc-sdk/libwebrtc/releases/download/libwebrtc.${libwebrtc_version}/libwebrtc-linux-arm64-release.zip"; - sha256 = "sha256-nMMU/HrCN4zSB4vO1O4TfJRBtK87OX+zYbxZRq8Q4Us="; - }; - } - .${stdenv.hostPlatform.system}; in flutter344.buildFlutterApplication ( rec { @@ -74,9 +53,6 @@ flutter344.buildFlutterApplication ( webkitgtk_4_1 ]; - runtimeDependencies = [ pulseaudio ]; - - env.NIX_LDFLAGS = "-rpath-link ${libwebrtcRpath}"; env.CXXFLAGS = "-include cstdint"; desktopItems = [ @@ -95,64 +71,6 @@ flutter344.buildFlutterApplication ( }) ]; - customSourceBuilders = { - flutter_webrtc = - { version, src, ... }: - stdenv.mkDerivation { - pname = "flutter_webrtc"; - inherit version src; - inherit (src) passthru; - - postPatch = '' - # Since we directly supply the binary distribution of libwebrtc instead of letting the builder download it we need to check that we still provide the correct version. - # nixpkgs forbids import from derivation, so we cannot simply read the contents to fetch the correct version - if ! grep -q "binary_version = libwebrtc.${libwebrtc_version}" third_party/libwebrtc_version.ini; then - echo -en "\nWrong libwebrtc version is in use!\n\t'libwebrtc.${libwebrtc_version}' was supplied, but cannot be found in 'third_party/libwebrtc_version.ini'.\nflutter_webrtc expects the following version:\n\t" - grep "binary_version" third_party/libwebrtc_version.ini; echo - false # triggers the build failure - fi - substituteInPlace third_party/CMakeLists.txt \ - --replace-fail "\''${LIBWEBRTC_THIRD_PARTY_DIR}/downloads/\''${LIBWEBRTC_ASSET}.zip" ${libwebrtc} - ln -s ${libwebrtc} third_party/libwebrtc - ''; - - installPhase = '' - runHook preInstall - - mkdir $out - cp -r ./* $out/ - - runHook postInstall - ''; - }; - } - // lib.optionalAttrs (stdenv.hostPlatform.system == "aarch64-linux") { - native_toolchain_cmake = - { version, src, ... }: - stdenv.mkDerivation { - pname = "native_toolchain_cmake"; - inherit version src; - inherit (src) passthru; - - postPatch = '' - substituteInPlace cmake/aarch64-linux-gnu.toolchain.cmake \ - --replace-fail "aarch64-linux-gnu-gcc" "gcc" - - substituteInPlace cmake/aarch64-linux-gnu.toolchain.cmake \ - --replace-fail "aarch64-linux-gnu-g++" "g++" - ''; - - installPhase = '' - runHook preInstall - - mkdir $out - cp -r ./* $out/ - - runHook postInstall - ''; - }; - }; - postPatch = '' substituteInPlace linux/CMakeLists.txt \ --replace-fail \ @@ -165,8 +83,6 @@ flutter344.buildFlutterApplication ( mkdir -p $ICO/hicolor/scalable/apps cp $src/assets/logo/vector/logo_standalone.svg $ICO/hicolor/scalable/apps/fluffychat.png - - patchelf --add-rpath ${libwebrtcRpath} $out/app/fluffychat-linux/lib/libwebrtc.so ''; } // lib.optionalAttrs (targetFlutterPlatform == "web") { diff --git a/pkgs/development/compilers/dart/package-source-builders/default.nix b/pkgs/development/compilers/dart/package-source-builders/default.nix index f4a11ffaf32a..44e83d9a4017 100644 --- a/pkgs/development/compilers/dart/package-source-builders/default.nix +++ b/pkgs/development/compilers/dart/package-source-builders/default.nix @@ -6,6 +6,7 @@ flutter_secure_storage_linux = callPackage ./flutter-secure-storage-linux { }; flutter_vodozemac = callPackage ./flutter_vodozemac { }; flutter_volume_controller = callPackage ./flutter_volume_controller { }; + flutter_webrtc = callPackage ./flutter_webrtc { }; fvp = callPackage ./fvp { }; handy_window = callPackage ./handy-window { }; hotkey_manager_linux = callPackage ./hotkey_manager_linux { }; diff --git a/pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/default.nix b/pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/default.nix new file mode 100644 index 000000000000..1ece43519684 --- /dev/null +++ b/pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/default.nix @@ -0,0 +1,97 @@ +{ + applyPatches, + fetchzip, + lib, + libdrm, + libgbm, + pulseaudio, + stdenvNoCC, +}: +{ version, src, ... }: +let + # if nixpkgs allowed IFD, we could just read the necessary libwebrtc directly + # from flutter-webrtc's sources, but unfortunately we can't... so we manually + # record that info (libwebrtc version but also hashes of each) into one JSON file + libwebrtc-info = lib.importJSON ./libwebrtc-info.json; + + # note: we can't use pkgs.livekit-libwebrtc because it might not be + # the version wanted by this flutter_webrtc version, so we + # instead have to download the vendor-compiled versions. sucks :( + libwebrtc = + let + info = + libwebrtc-info.${version} or (throw '' + Unsupported version of pub package 'flutter_webrtc': ${version} + + Please add the corresponding libwebrtc version and hashes to: + pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/libwebrtc-info.json + + To do it semi-automatically, you can use the adjacent 'fetch-webrtc-version.sh' script. + You can use like this, to fetch the new version's info and then update the libwebrtc-info file: + jq -s add ./libwebrtc-info.json <(./fetch-webrtc-version.sh '${version}') | sponge ./libwebrtc-info.json + ''); + + # note: if you add a new platform here, you'll need to add it to the list in fetch-webrtc-version + # (and also re-gen the JSON file to support it) ((and update meta.platforms)) + arch = + { + x86_64-linux = "linux-x64"; + aarch64-linux = "linux-arm64"; + } + .${stdenvNoCC.hostPlatform.system} or (throw '' + Package 'flutter_webrtc' is not supported on ${stdenvNoCC.hostPlatform} platforms. + ''); + + url = "https://github.com/webrtc-sdk/libwebrtc/releases/download/${info.version}/libwebrtc-${arch}-release.zip"; + hash = info.hashes.${arch}; + in + applyPatches { + pname = "libwebrtc"; + inherit version; + + src = fetchzip { + inherit version url hash; + meta = { + platforms = lib.intersectLists lib.platforms.linux (lib.platforms.x86_64 ++ lib.platforms.aarch64); + sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; + }; + }; + + postPatch = '' + patchelf lib/libwebrtc.so --add-rpath ${ + lib.makeLibraryPath [ + libdrm + libgbm + ] + } + ''; + }; +in + +stdenvNoCC.mkDerivation (finalAttrs: { + pname = "flutter_webrtc"; + inherit version src; + + passthru = src.passthru // { + inherit libwebrtc; + }; + + propagatedBuildInputs = [ pulseaudio.dev ]; + + postPatch = '' + substituteInPlace third_party/CMakeLists.txt \ + --replace-fail "\''${LIBWEBRTC_THIRD_PARTY_DIR}/downloads/\''${LIBWEBRTC_ASSET}.zip" ${finalAttrs.passthru.libwebrtc} + ln -s ${finalAttrs.passthru.libwebrtc} third_party/libwebrtc + ''; + + installPhase = '' + runHook preInstall + + cp -r ./ -T "$out/" + + runHook postInstall + ''; + + # we only patch the linux cmake (and currently libwebrtc is only vendored for linux anyway) + meta.platforms = lib.platforms.linux; +}) diff --git a/pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/fetch-webrtc-version.sh b/pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/fetch-webrtc-version.sh new file mode 100755 index 000000000000..15c1792434f8 --- /dev/null +++ b/pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/fetch-webrtc-version.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p yq-go curl + +set +e + +if ! [[ -v 1 ]] || [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]]; then + echo "usage: fetch-webrtc-version.sh " + echo ' ~-------~' + echo ' this should be the *flutter_webrtc* version' + exit 1 +fi + +main() { + # remove the 'v' from the version string if it's there, so v1.5.0 -> 1.5.0 but 1.6.2 -> 1.6.2 + local flutter_webrtc_version="${1#v}" + + local webrtc_ver + webrtc_ver="$(get_libwebrtc_version "$flutter_webrtc_version")" + + echo "flutter_webrtc v$flutter_webrtc_version uses $webrtc_ver" >&2 + + cat < +get_all_libwebrtc_hashes() { + local version="$1" + + cat < +get_libwebrtc_version() { + local version="$1" + local url="https://raw.githubusercontent.com/flutter-webrtc/flutter-webrtc/refs/tags/v${version}/third_party/libwebrtc_version.ini" + + curl -L "$url" | yq --input-format ini '.libwebrtc.binary_version' +} + +# args: +get_libwebrtc_hash() { + local platform="$1" + local version="$2" + local url="https://github.com/webrtc-sdk/libwebrtc/releases/download/${version}/libwebrtc-${platform}-release.zip" + + local hash + hash=$(nix-prefetch-url --unpack --name "$(basename "$url")" "$url") + + nix-hash --to-base64 --type sha256 "$hash" +} + +main "$@" diff --git a/pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/libwebrtc-info.json b/pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/libwebrtc-info.json new file mode 100644 index 000000000000..11cb0876eee1 --- /dev/null +++ b/pkgs/development/compilers/dart/package-source-builders/flutter_webrtc/libwebrtc-info.json @@ -0,0 +1,9 @@ +{ + "1.5.2": { + "version": "libwebrtc.m144.7559.09", + "hashes": { + "linux-x64": "sha256-uzS07voCGM1zs663UalYpb8pWiYpkrKMxKt/wB4rcB4=", + "linux-arm64": "sha256-nMMU/HrCN4zSB4vO1O4TfJRBtK87OX+zYbxZRq8Q4Us=" + } + } +}