From 0576bbbc9ddd1b6cbb0dac4a428c94853c89a689 Mon Sep 17 00:00:00 2001 From: Ulysses Zhan Date: Wed, 16 Apr 2025 22:58:51 -0700 Subject: [PATCH] z-library-desktop: init at 3.1.0 --- pkgs/by-name/z-/z-library-desktop/Info.plist | 91 +++++++++++++++++++ pkgs/by-name/z-/z-library-desktop/package.nix | 88 ++++++++++++++++++ pkgs/by-name/z-/z-library-desktop/update.rb | 79 ++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 pkgs/by-name/z-/z-library-desktop/Info.plist create mode 100644 pkgs/by-name/z-/z-library-desktop/package.nix create mode 100755 pkgs/by-name/z-/z-library-desktop/update.rb diff --git a/pkgs/by-name/z-/z-library-desktop/Info.plist b/pkgs/by-name/z-/z-library-desktop/Info.plist new file mode 100644 index 000000000000..be7a0239b65e --- /dev/null +++ b/pkgs/by-name/z-/z-library-desktop/Info.plist @@ -0,0 +1,91 @@ + + + + + CFBundleDisplayName + Z-Library + CFBundleExecutable + Z-Library + CFBundleIconFile + icon.icns + CFBundleIdentifier + zlibrary + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Z-Library + CFBundlePackageType + APPL + CFBundleShortVersionString + @version@ + CFBundleVersion + @version@ + LSApplicationCategoryType + public.app-category.developer-tools + LSEnvironment + + MallocNanoZone + 0 + + LSMinimumSystemVersion + 10.13 + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + NSAllowsLocalNetworking + + NSExceptionDomains + + 127.0.0.1 + + NSIncludesSubdomains + + NSTemporaryExceptionAllowsInsecureHTTPLoads + + NSTemporaryExceptionAllowsInsecureHTTPSLoads + + NSTemporaryExceptionMinimumTLSVersion + 1.0 + NSTemporaryExceptionRequiresForwardSecrecy + + + localhost + + NSIncludesSubdomains + + NSTemporaryExceptionAllowsInsecureHTTPLoads + + NSTemporaryExceptionAllowsInsecureHTTPSLoads + + NSTemporaryExceptionMinimumTLSVersion + 1.0 + NSTemporaryExceptionRequiresForwardSecrecy + + + + + NSBluetoothAlwaysUsageDescription + This app needs access to Bluetooth + NSBluetoothPeripheralUsageDescription + This app needs access to Bluetooth + NSCameraUsageDescription + This app needs access to the camera + NSHighResolutionCapable + + NSHumanReadableCopyright + Copyright © 2024 Deniz Terzi + NSMainNibFile + MainMenu + NSMicrophoneUsageDescription + This app needs access to the microphone + NSPrincipalClass + AtomApplication + NSQuitAlwaysKeepsWindows + + NSRequiresAquaSystemAppearance + + NSSupportsAutomaticGraphicsSwitching + + + diff --git a/pkgs/by-name/z-/z-library-desktop/package.nix b/pkgs/by-name/z-/z-library-desktop/package.nix new file mode 100644 index 000000000000..7499a42865fe --- /dev/null +++ b/pkgs/by-name/z-/z-library-desktop/package.nix @@ -0,0 +1,88 @@ +{ + lib, + stdenv, + fetchurl, + fetchFromGitHub, + makeBinaryWrapper, + replaceVars, + dpkg, + asar, + electron, + darwin, + libsecret, + pkg-config, + buildNpmPackage, + removeReferencesTo, + xcbuild, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "z-library-desktop"; + version = "3.1.0"; + + src = fetchurl { + url = "https://web.archive.org/web/20260301212456/https://s3proxy-alp.cdn-zlib.sk/swfs_second_public_files/soft/desktop/Z-Library_3.1.0_amd64.deb"; + hash = "sha256-m1axR0HrqHfoz+1tvhCOr1xq0lVkHjxrrf2KnTA7ZVg="; + }; + + nativeBuildInputs = [ + dpkg + makeBinaryWrapper + asar + ] + ++ lib.optional stdenv.hostPlatform.isDarwin darwin.autoSignDarwinBinariesHook; + + buildPhase = '' + runHook preBuild + + pushd opt/Z-Library/resources + asar e app.asar app + rm app.asar + popd + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + phome=$out/opt/Z-Library + mkdir -p $phome/resources + cp -r opt/Z-Library/resources/app $phome/resources + + makeWrapper ${lib.getExe electron} $out/bin/Z-Library \ + --set-default ELECTRON_FORCE_IS_PACKAGED 1 \ + --add-flags $phome/resources/app \ + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \ + --inherit-argv0 + + cp -r usr/* $out + substituteInPlace $out/share/applications/Z-Library.desktop \ + --replace-fail "/opt/Z-Library/Z-Library" "Z-Library" + + runHook postInstall + ''; + + postInstall = lib.optionalString stdenv.hostPlatform.isDarwin '' + mkdir -p $out/Applications/Z-Library.app/Contents/{MacOS,Resources} + ln -s $out/bin/z-library $out/Applications/Z-Library.app/Contents/MacOS/Z-Library + ln -s $phome/resources/app/dist/icon.icns $out/Applications/Z-Library.app/Contents/Resources/icon.icns + install -Dm444 ${ + # Adapted from the dmg package from upstream. + # Note that the upstream distributed version for macOS is actually older than those for other systems, + # but here we packaged it for macOS using the deb package, so it has the same version as the Linux version. + replaceVars ./Info.plist { inherit (finalAttrs) version; } + } $out/Applications/Z-Library.app/Contents/Info.plist + ''; + + passthru.updateScript = ./update.rb; + + meta = { + homepage = "https://z-library.sk"; + description = "Client for the online library Z-Library"; + license = lib.licenses.unfree; # Maintainers on AUR emailed the dev to confirm: https://pastebin.com/ss4Nr8pW + platforms = lib.platforms.all; + maintainers = with lib.maintainers; [ ulysseszhan ]; + mainProgram = "Z-Library"; + }; +}) diff --git a/pkgs/by-name/z-/z-library-desktop/update.rb b/pkgs/by-name/z-/z-library-desktop/update.rb new file mode 100755 index 000000000000..6aad9b129d60 --- /dev/null +++ b/pkgs/by-name/z-/z-library-desktop/update.rb @@ -0,0 +1,79 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i ruby -p ruby ruby.gems.nokogiri + +require 'net/http' +require 'nokogiri' + +PACKAGE = 'z-library-desktop' + +def log(...) = $stderr.puts(...) +def finish(...) = log(...) || exit + +def archive url + log "Archiving #{url} on Wayback Machine..." + + req = Net::HTTP::Get.new URI "https://web.archive.org/save/#{url}" + res = Net::HTTP.start req.uri.host, req.uri.port, use_ssl: true do |http| + http.open_timeout = 30 + http.read_timeout = 300 # sometimes WM is very slow + http.request req + end + + location = res['Content-Location'] + return "https://web.archive.org#{location}" if location&.start_with? '/web/' + + redirect = res['Location'] + return redirect if redirect&.include? '/web/' + + res_url = res.uri.to_s + return res_url if res_url&.include? '/web/' +end + +def url_hash url + prefetch_hash = `nix-prefetch-url #{url}`.strip + `nix --extra-experimental-features nix-command hash convert --hash-algo sha256 #{prefetch_hash}`.strip +end + +def n(attribute) = `nix-instantiate --eval --strict --attr #{PACKAGE}.#{attribute}`.strip.undump + +nix_file = n('meta.position')[/(.*):\d+$/, 1] +current_version = n 'version' +current_hash = n 'src.drvAttrs.outputHash' +current_url = n 'src.drvAttrs.urls.0' +current_homepage = n 'meta.homepage' +nix = File.read nix_file + +wikipedia = Nokogiri::HTML Net::HTTP.get URI 'https://en.wikipedia.org/wiki/Z-Library' +url = wikipedia.at_css('.infobox th.infobox-label:contains("URL") + td.infobox-data a[href^="https://"]')&.[] 'href' +abort 'Could not find Z-Library URL on Wikipedia page.' unless url +abort "Could not update homepage #{current_homepage} -> #{url}" unless nix.sub! current_homepage, url +log "Z-Library URL: #{url}" + +page = Nokogiri::HTML Net::HTTP.get URI url +unless page.at_css 'head link[rel="stylesheet"][href*="zaccess.css"]' + page = Nokogiri::HTML Net::HTTP.get URI URI.join url, 'z-access' +end + +item = page.at_css '.za-download-link-title:has(> .za-download-link-title-name:contains("Linux"))' +abort 'Could not find Linux download link on Z-Library page.' unless item + +version = item.at_css('.za-download-link-title-version')&.text[/\d+\.\d+\.\d+/] +abort 'Could not find version number in Linux download link.' unless version +log "Version: #{version}" +finish 'Version is up to date.' if version == current_version +abort "Could not update version: #{current_version} -> #{version}" unless nix.sub! current_version, version + +download = item.at_css('a.za-download-href-link[href$=".deb"]')&.[] 'href' +abort 'Could not find download link for Linux version.' unless download +log "Download link: #{download}" + +archive_url = archive download +abort 'Could not archive download link.' unless archive_url +abort "Could not update URL: #{current_url} -> #{archive_url}" unless nix.sub! current_url, archive_url +log "Archived download link: #{archive_url}" + +hash = url_hash download +abort "Could not update hash: #{current_hash} -> #{hash}" unless nix.sub! current_hash, hash +log "Updated hash: #{hash}" + +File.write nix_file, nix