diff --git a/pkgs/by-name/pl/plezy/package.nix b/pkgs/by-name/pl/plezy/package.nix index e687b66c28e8..f7cd8f1b1736 100644 --- a/pkgs/by-name/pl/plezy/package.nix +++ b/pkgs/by-name/pl/plezy/package.nix @@ -1,9 +1,10 @@ { lib, + stdenv, + stdenvNoCC, flutter338, fetchFromGitHub, fetchurl, - yq-go, pkg-config, libsecret, jsoncpp, @@ -17,25 +18,12 @@ makeDesktopItem, copyDesktopItems, imagemagick, - _experimental-update-script-combinators, - nix-update-script, + _7zz, + makeBinaryWrapper, runCommand, - dart, }: let - simdutf = fetchurl { - url = "https://github.com/simdutf/simdutf/releases/download/v6.4.2/singleheader.zip"; - hash = "sha256-n+TW9RVySlXI3oj+5EY+CJChq+ImfNoTxLXSRdWAOeY="; - }; - - zlib-root = runCommand "zlib-root" { } '' - mkdir $out - ln -s ${zlib.dev}/include $out/include - ln -s ${zlib}/lib $out/lib - ''; -in -flutter338.buildFlutterApplication rec { pname = "plezy"; version = "1.30.0"; @@ -46,93 +34,17 @@ flutter338.buildFlutterApplication rec { hash = "sha256-9bB9L9f2s0i2xF4JIe4vlEpt/bmF1gf3gxcoHdCrYqc="; }; - pubspecLock = lib.importJSON ./pubspec.lock.json; - - gitHashes = lib.importJSON ./git-hashes.json; - - nativeBuildInputs = [ - pkg-config - copyDesktopItems - imagemagick - ]; - - buildInputs = [ - libsecret - jsoncpp - mpv-unwrapped - libass - keybinder3 - ffmpeg - zlib - libevdev - jdk - ]; - - env = { - ZLIB_ROOT = zlib-root; - JAVA_HOME = "${jdk}/lib/openjdk"; + simdutf = fetchurl { + url = "https://github.com/simdutf/simdutf/releases/download/v6.4.2/singleheader.zip"; + hash = "sha256-n+TW9RVySlXI3oj+5EY+CJChq+ImfNoTxLXSRdWAOeY="; }; - postPatch = '' - substituteInPlace linux/CMakeLists.txt \ - --replace-fail "URL https://github.com/simdutf/simdutf/releases/download/v6.4.2/singleheader.zip" \ - "URL file://${simdutf}" + zlib-root = runCommand "zlib-root" { } '' + mkdir $out + ln -s ${zlib.dev}/include $out/include + ln -s ${zlib}/lib $out/lib ''; - desktopItems = [ - (makeDesktopItem { - name = "plezy"; - exec = "plezy"; - icon = "plezy"; - desktopName = "Plezy"; - comment = "Modern cross-platform Plex client built with Flutter"; - categories = [ - "AudioVideo" - "Video" - "Player" - ]; - }) - ]; - - postInstall = '' - install -Dm644 assets/plezy.png $out/share/icons/hicolor/128x128/apps/plezy.png - for size in 16 24 32 48 64 256 512; do - mkdir -p $out/share/icons/hicolor/''${size}x''${size}/apps - convert assets/plezy.png -resize ''${size}x''${size} $out/share/icons/hicolor/''${size}x''${size}/apps/plezy.png - done - ''; - - passthru = { - pubspecSource = - runCommand "pubspec.lock.json" - { - inherit src; - nativeBuildInputs = [ yq-go ]; - } - '' - yq eval --output-format=json --prettyPrint $src/pubspec.lock > "$out" - ''; - updateScript = _experimental-update-script-combinators.sequence [ - (nix-update-script { }) - ( - (_experimental-update-script-combinators.copyAttrOutputToFile "plezy.pubspecSource" ./pubspec.lock.json) - // { - supportedFeatures = [ ]; - } - ) - { - command = [ - dart.fetchGitHashesScript - "--input" - ./pubspec.lock.json - "--output" - ./git-hashes.json - ]; - supportedFeatures = [ ]; - } - ]; - }; - meta = { description = "Modern cross-platform Plex client built with Flutter"; homepage = "https://github.com/edde746/plezy"; @@ -142,6 +54,107 @@ flutter338.buildFlutterApplication rec { mio miniharinn ]; - platforms = lib.platforms.linux; + platforms = lib.platforms.linux ++ [ + "x86_64-darwin" + "aarch64-darwin" + ]; + sourceProvenance = lib.optionals stdenv.hostPlatform.isDarwin ( + with lib.sourceTypes; [ binaryNativeCode ] + ); }; -} + + linux = flutter338.buildFlutterApplication rec { + inherit pname version src; + + pubspecLock = lib.importJSON ./pubspec.lock.json; + + gitHashes = lib.importJSON ./git-hashes.json; + + nativeBuildInputs = [ + pkg-config + copyDesktopItems + imagemagick + ]; + + buildInputs = [ + libsecret + jsoncpp + mpv-unwrapped + libass + keybinder3 + ffmpeg + zlib + libevdev + jdk + ]; + + env = { + ZLIB_ROOT = zlib-root; + JAVA_HOME = "${jdk}/lib/openjdk"; + }; + + postPatch = '' + substituteInPlace linux/CMakeLists.txt \ + --replace-fail "URL https://github.com/simdutf/simdutf/releases/download/v6.4.2/singleheader.zip" \ + "URL file://${simdutf}" + ''; + + desktopItems = [ + (makeDesktopItem { + name = "plezy"; + exec = "plezy"; + icon = "plezy"; + desktopName = "Plezy"; + comment = meta.description; + categories = [ + "AudioVideo" + "Video" + "Player" + ]; + }) + ]; + + postInstall = '' + install -Dm644 assets/plezy.png $out/share/icons/hicolor/128x128/apps/plezy.png + for size in 16 24 32 48 64 256 512; do + mkdir -p $out/share/icons/hicolor/''${size}x''${size}/apps + convert assets/plezy.png -resize ''${size}x''${size} $out/share/icons/hicolor/''${size}x''${size}/apps/plezy.png + done + ''; + + passthru.updateScript = ./update.sh; + + inherit meta; + }; + + darwin = stdenvNoCC.mkDerivation { + inherit pname version; + + passthru.updateScript = ./update.sh; + + src = fetchurl { + url = "https://github.com/edde746/plezy/releases/download/${version}/plezy-macos.dmg"; + hash = "sha256-a3LvwWZvLPD7yKKbC+oYXSgoHXUS+mOojzfDyW7/QOE="; + }; + + nativeBuildInputs = [ + _7zz + makeBinaryWrapper + ]; + + sourceRoot = "Plezy.app"; + + installPhase = '' + runHook preInstall + + mkdir -p $out/Applications/Plezy.app + cp -r . $out/Applications/Plezy.app + makeBinaryWrapper $out/Applications/Plezy.app/Contents/MacOS/Plezy $out/bin/plezy + + runHook postInstall + ''; + + inherit meta; + }; +in +if stdenv.hostPlatform.isDarwin then darwin else linux diff --git a/pkgs/by-name/pl/plezy/update.sh b/pkgs/by-name/pl/plezy/update.sh new file mode 100755 index 000000000000..6befc9c04271 --- /dev/null +++ b/pkgs/by-name/pl/plezy/update.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env nix-shell +#! nix-shell -I nixpkgs=./. -i bash -p curl gnused jq nix nix-prefetch-git python3 yq-go + +set -eou pipefail + +ROOT="$(dirname "$(readlink -f "$0")")" + +latestVersion=$(curl --fail --silent https://api.github.com/repos/edde746/plezy/releases/latest | jq --raw-output .tag_name) + +currentVersion=$(nix-instantiate --eval -E "with import ./. {}; plezy.version" | tr -d '"') + +if [[ "$currentVersion" == "$latestVersion" ]]; then + echo "plezy is up-to-date: $currentVersion" + exit 0 +fi + +echo "updating plezy: $currentVersion -> $latestVersion" + +sed -i "s/version = \".*\"/version = \"${latestVersion}\"/" "$ROOT/package.nix" + +GIT_SRC_URL="https://github.com/edde746/plezy/archive/refs/tags/${latestVersion}.tar.gz" +GIT_SRC_SHA=$(nix --extra-experimental-features nix-command hash to-sri --type sha256 "$(nix-prefetch-url --unpack "$GIT_SRC_URL")") +sed -i "/fetchFromGitHub/,/hash/{s|hash = \".*\"|hash = \"${GIT_SRC_SHA}\"|}" "$ROOT/package.nix" + +DMG_URL="https://github.com/edde746/plezy/releases/download/${latestVersion}/plezy-macos.dmg" +DMG_SHA=$(nix --extra-experimental-features nix-command hash to-sri --type sha256 "$(nix-prefetch-url "$DMG_URL")") +sed -i "/plezy-macos.dmg/,/hash/{s|hash = \".*\"|hash = \"${DMG_SHA}\"|}" "$ROOT/package.nix" + +curl --fail --silent "https://raw.githubusercontent.com/edde746/plezy/${latestVersion}/pubspec.lock" \ + | yq eval --output-format=json --prettyPrint > "$ROOT/pubspec.lock.json" + +python3 "$(dirname "$(readlink -f "$0")")/../../../development/compilers/dart/fetch-git-hashes.py" \ + --input "$ROOT/pubspec.lock.json" \ + --output "$ROOT/git-hashes.json"