From c81d4943873bfead21cf370a3aa67bcd9236d36d Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Fri, 7 Oct 2022 18:35:34 -0400 Subject: [PATCH] "Create custom package for jellyfin-media-player" --- flake.lock | 40 ++++++- flake.nix | 7 +- home/seanomik/default.nix | 2 +- modules/default.nix | 1 + modules/flatpak/default.nix | 21 ++++ modules/pkgs/jellyfin-media-player-git.nix | 50 +++++++++ modules/pkgs/jellyfin-media-player.nix | 118 ++++++++++----------- scripts/pull_git.py | 7 ++ scripts/{update_git.py => push_git.py} | 19 ++-- 9 files changed, 191 insertions(+), 74 deletions(-) create mode 100755 modules/flatpak/default.nix create mode 100644 modules/pkgs/jellyfin-media-player-git.nix mode change 100755 => 100644 modules/pkgs/jellyfin-media-player.nix create mode 100644 scripts/pull_git.py rename scripts/{update_git.py => push_git.py} (95%) diff --git a/flake.lock b/flake.lock index 0b4f607..4167334 100755 --- a/flake.lock +++ b/flake.lock @@ -55,6 +55,25 @@ "type": "github" } }, + "flatpak": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1662408312, + "narHash": "sha256-H1kmMTmXLud5duk6O+wR0zWU7TPh37y1uDB7SAfpW/w=", + "owner": "yawnt", + "repo": "declarative-nix-flatpak", + "rev": "a82b3b135f79b78c379c4f1b0c52957cd7ccf50c", + "type": "github" + }, + "original": { + "owner": "yawnt", + "ref": "main", + "repo": "declarative-nix-flatpak", + "type": "github" + } + }, "git-crypt-agessh": { "inputs": { "nixpkgs": [ @@ -130,6 +149,20 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1664904529, + "narHash": "sha256-mGlB/SQR4E9jb7fOOxCTJlwL6Mk1Dpyvi4UrOXL6C18=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b7a47253e0c8cb04c0a3f8ed3149e90229e62884", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1658912196, "narHash": "sha256-GTP5XCLPU2Hg2bQC5dVqSBF9ef5C/J6pD4qM09Ba4Gk=", @@ -145,7 +178,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { "lastModified": 1658119717, "narHash": "sha256-4upOZIQQ7Bc4CprqnHsKnqYfw+arJeAuU+QcpjYBXW0=", @@ -165,7 +198,7 @@ "inputs": { "flake-compat": "flake-compat", "libnbtplusplus": "libnbtplusplus", - "nixpkgs": "nixpkgs_3", + "nixpkgs": "nixpkgs_4", "tomlplusplus": "tomlplusplus" }, "locked": { @@ -186,9 +219,10 @@ "inputs": { "agenix": "agenix", "fenix": "fenix", + "flatpak": "flatpak", "git-crypt-agessh": "git-crypt-agessh", "home-manager": "home-manager", - "nixpkgs": "nixpkgs_2", + "nixpkgs": "nixpkgs_3", "polymc": "polymc", "unstable": "unstable" } diff --git a/flake.nix b/flake.nix index 513f1f1..febbf8d 100755 --- a/flake.nix +++ b/flake.nix @@ -18,11 +18,13 @@ git-crypt-agessh.inputs.nixpkgs.follows = "nixpkgs"; # idk if this is needed polymc.url = "github:PolyMC/PolyMC"; + + flatpak.url = "github:yawnt/declarative-nix-flatpak/main"; }; # nixpkgs.overlays = [ inputs.polymc.overlay ]; - outputs = inputs@{ nixpkgs, unstable, home-manager, agenix, git-crypt-agessh, polymc, ... }: + outputs = inputs@{ nixpkgs, unstable, home-manager, agenix, flatpak, git-crypt-agessh, polymc, ... }: let system = "x86_64-linux"; @@ -51,6 +53,9 @@ inherit (pkgs.stdenv.targetPlatform) system; config.allowUnfree = true; }; +# _module.args.flatpak = import inputs.flatpak { +# inherit (pkgs.stdenv.targetPlatform) system; +# }; }; in [ { diff --git a/home/seanomik/default.nix b/home/seanomik/default.nix index bcabb2e..6fad4fc 100755 --- a/home/seanomik/default.nix +++ b/home/seanomik/default.nix @@ -67,7 +67,7 @@ slack google-chrome (callPackage ../../modules/pkgs/upwork.nix { inherit runCommandLocal; }) - (callPackage ../../modules/pkgs/jellyfin-media-player.nix { inherit runCommandLocal; }) + (libsForQt5.callPackage ../../modules/pkgs/jellyfin-media-player.nix { }) jetbrains.idea-community renderdoc ]; diff --git a/modules/default.nix b/modules/default.nix index d2df8b9..a4b27a1 100755 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,5 +3,6 @@ imports = [ ./audio ./cli-tools.nix + ./flatpak ]; } diff --git a/modules/flatpak/default.nix b/modules/flatpak/default.nix new file mode 100755 index 0000000..289d3fb --- /dev/null +++ b/modules/flatpak/default.nix @@ -0,0 +1,21 @@ +{pkgs, flatpak, ... }: +let + runtime = flatpak.lib.flatpak.fetchRuntimeFromFlatHub { + name = "org.freedesktop.Platform"; + branch = "21.08"; + commit = "c7252386179c4c1ecf5d93bdaec6ca82852dddfdae7112b5c3177f7424c4a928"; + sha256 = "sha256-wuFiB2+x+Mj6F9idkrknvD9Su6bWr5QVhgcB8/4uBQc="; + }; + jmp = flatpak.lib.flatpak.fetchAppFromFlatHub { + name = "com.github.iwalton3.jellyfin-media-player"; + commit = "f26193386f3552bc7d6849078ef073d1ca94629d"; + sha256 = "sha256-yxnsiou/ujd9fdP4D7J7i00uNGm0TjHgrIp0TTwUq3o="; + inherit runtime; + }; +in { + services.flatpak.enable = true; + + environment.systemPackages = [ + flatpak.lib.flatpak.wrapFlatpakLauncher "com.github.iwalton3.jellyfin-media-player" jmp runtime + ]; +} diff --git a/modules/pkgs/jellyfin-media-player-git.nix b/modules/pkgs/jellyfin-media-player-git.nix new file mode 100644 index 0000000..f2c56bb --- /dev/null +++ b/modules/pkgs/jellyfin-media-player-git.nix @@ -0,0 +1,50 @@ +{ lib +, pkgs +, stdenv +, fetchFromGitHub +, cmake +, python +, unzip +, qtbase +, wrapQtAppsHook +}: + +let + stdenv = pkgs.clangStdenv; + + distZip = builtins.fetchurl { + url = "https://github.com/iwalton3/jellyfin-web-jmp/releases/download/jwc-10.8.1/dist.zip"; + sha256 = "sha256:1mn0l89li1cv3jmazrdbdhjldbm0daphv18193jd24vhwxd4sx9z"; + }; + +in stdenv.mkDerivation rec { + version = "v1.7.1"; + pname = "jellyfin-media-player"; + + src = fetchFromGitHub { + owner = "jellyfin"; + repo = pname; + rev = version; + sha256 = "sha256-piMqI4qxcNUSNC+0JE2KZ/cvlNgtxUOnSfrcWnBVzC0="; + }; + + nativeBuildInputs = [ cmake wrapQtAppsHook unzip ]; + + buildInputs = [ qtbase python pkgs.SDL2 pkgs.zlib-ng pkgs.fribidi pkgs.gnutls pkgs.libsForQt5.qt5.qtwebengine + pkgs.libsForQt5.qt5.qtquickcontrols pkgs.libsForQt5.qt5.qtx11extras pkgs.libsForQt5.qt5.qtwebchannel + pkgs.libcec pkgs.mpv ]; + + configurePhase = '' + unzip -q ${pkgs.lib.strings.escapeShellArg distZip} + + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$out + ''; + + meta = with lib; { + description = "Jellyfin Desktop Client based on Plex Media Player."; + homepage = "https://github.com/jellyfin/jellyfin-media-player"; + license = licenses.gpl2; + platforms = platforms.unix; + maintainers = with maintainers; [ seanomik ]; + }; +} diff --git a/modules/pkgs/jellyfin-media-player.nix b/modules/pkgs/jellyfin-media-player.nix old mode 100755 new mode 100644 index 29868b2..16dd1b2 --- a/modules/pkgs/jellyfin-media-player.nix +++ b/modules/pkgs/jellyfin-media-player.nix @@ -1,80 +1,78 @@ -{ lib, stdenv, fetchurl, dpkg, wrapGAppsHook, autoPatchelfHook -, alsa-lib, atk, at-spi2-atk, at-spi2-core, cairo, cups, dbus, expat, fontconfig, freetype -, gdk-pixbuf, glib, gtk3, libcxx, libdrm, libnotify, libpulseaudio, libuuid, libX11, libxcb -, libXcomposite, libXcursor, libXdamage, libXext, libXfixes, libXi, libXrandr, libXrender -, libXScrnSaver, libXtst, mesa, nspr, nss, openssl, pango, systemd, writeText, runCommandLocal, wget }: +{ lib +, pkgs +, stdenv +, fetchurl + +# Packaging tools +, dpkg +, wrapQtAppsHook + +# Dependencies +, qtbase +, qt5 +, xorg +, mesa +, SDL2 +, zlib-ng +, fribidi +, gnutls +, libcec +, mpv +}: stdenv.mkDerivation rec { - pname = "jellyfin-media-player"; version = "1.7.1"; + hotfix = "-1"; + pname = "jellyfin-media-player"; - src = runCommandLocal "${pname}_${version}_amd64-jammy.deb" - rec { - outputHashMode = "recursive"; - outputHashAlgo = "sha256"; - outputHash = "sha256-g2RldDAvgEpyKz+umxcaAjWfGGH9DZ56UndsIraudFg="; + src = fetchurl { + url = "https://github.com/jellyfin/jellyfin-media-player/releases/download/v${version}/jellyfin-media-player_${version}${hotfix}_amd64-jammy.deb"; + sha256 = "sha256-9z3L0c+2LDPMx82biJq/Mhsb8rt6Lr+4F/jWzT5v0R4="; + }; - nativeBuildInputs = [ wget ]; + sourceRoot = "."; + unpackCmd = "dpkg-deb -x $src ."; - impureEnvVars = lib.fetchers.proxyImpureEnvVars; - } '' - # Figure out certificates - wget --no-check-certificate \ - -U "Mozilla/5.0 (X11; Linux x86_64; rv:103.0)" \ - https://github.com/jellyfin/jellyfin-media-player/releases/download/v1.7.1/jellyfin-media-player_1.7.1-1_amd64-jammy.deb \ - -O $out - ''; - - nativeBuildInputs = [ - dpkg - wrapGAppsHook - autoPatchelfHook - ]; - - buildInputs = [ - libcxx systemd libpulseaudio - stdenv.cc.cc alsa-lib atk at-spi2-atk at-spi2-core cairo cups - dbus expat fontconfig freetype gdk-pixbuf glib gtk3 libdrm libnotify - libuuid libX11 libxcb libXcomposite libXcursor libXdamage libXext libXfixes - libXi libXrandr libXrender libXScrnSaver libXtst mesa nspr nss pango systemd - ]; - - libPath = lib.makeLibraryPath buildInputs; - - dontWrapGApps = true; - dontBuild = true; dontConfigure = true; + dontBuild = true; - unpackPhase = '' -# curl -i -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0" -O https://upwork-usw2-desktopapp.upwork.com/binaries/v5_6_10_13_3c485d1dd2af4f61/upwork_5.6.10.13_amd64.deb - echo $out - echo $src - dpkg-deb -x "$src" ./ - ''; + nativeBuildInputs = [ wrapQtAppsHook dpkg ]; + + buildInputs = [ qtbase qt5.qtwebengine ]; installPhase = '' - runHook preInstall - mv usr $out -# mv share $out + # Copy everything in usr to $out + cp -r usr/ $out/ - # Now it requires lib{ssl,crypto}.so.1.0.0. Fix based on Spotify pkg. - # https://github.com/NixOS/nixpkgs/blob/efea022d6fe0da84aa6613d4ddeafb80de713457/pkgs/applications/audio/spotify/default.nix#L129 -# mkdir -p $out/lib/upwork -# ln -s ${lib.getLib openssl}/lib/libssl.so $out/lib/upwork/libssl.so.1.0.0 -# ln -s ${lib.getLib openssl}/lib/libcrypto.so $out/lib/upwork/libcrypto.so.1.0.0 + # Link the web-client next to the bin file. + # Without this, the qt5-webengine(?) wont load since it can't find .html files + ln -s $out/share/jellyfinmediaplayer/web-client $out/bin/web-client + ''; - sed -e "s|/opt/jellyfin-media-player|$out/bin|g" -i $out/share/applications/com.github.iwalton3.jellyfin-media-player.desktop - makeWrapper $out/bin/jellyfinmediaplayer \ - $out/bin/jellyfinmediaplayer \ - --prefix LD_LIBRARY_PATH : ${libPath} - runHook postInstall + preFixup = let + libPath = lib.makeLibraryPath [ + qtbase + qt5.qtwebengine qt5.qtquickcontrols qt5.qtx11extras qt5.qtwebchannel qt5.qtdeclarative + xorg.libX11 # libX11.so.6 + xorg.libXrandr # libXrandr.so.2 + SDL2 # libSDL2-2.0.so.0 + libcec # libcec.so.6 + mpv # libmpv.so.1 + + stdenv.cc.cc.lib # libstdc++.so.6 + ]; + in '' + patchelf \ + --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ + --set-rpath "${libPath}" \ + $out/bin/jellyfinmediaplayer ''; meta = with lib; { - description = "Jellyfin Desktop Client based on Plex Media Player"; + description = "Jellyfin Desktop Client based on Plex Media Player."; homepage = "https://github.com/jellyfin/jellyfin-media-player"; sourceProvenance = with sourceTypes; [ binaryNativeCode ]; - license = licenses.gpl2Only; + license = licenses.gpl2; platforms = [ "x86_64-linux" ]; maintainers = with maintainers; [ seanomik ]; }; diff --git a/scripts/pull_git.py b/scripts/pull_git.py new file mode 100644 index 0000000..adc8c2f --- /dev/null +++ b/scripts/pull_git.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +from git import Repo +import shutil +import os + +GIT_REPO_URL = "git@git.seanomik.net:SeanOMik/nixos-dotfiles.git" \ No newline at end of file diff --git a/scripts/update_git.py b/scripts/push_git.py similarity index 95% rename from scripts/update_git.py rename to scripts/push_git.py index c52cd49..66cb042 100644 --- a/scripts/update_git.py +++ b/scripts/push_git.py @@ -12,17 +12,18 @@ GIT_REPO_URL = "git@git.seanomik.net:SeanOMik/nixos-dotfiles.git" def get_yes_no_answer(question: str, error_msg: str = "ERROR: Malformed input!"): ans = "" - while ans != "y" or ans != "n": + while True: print(f"{question} (y,n): ", end="") - ans = input() + ans = input().lower().strip() - if ans != "y" or ans != "n": - print(error_msg) - - if ans == "y": - return True - elif ans == "n": - return False + print(f"Input: \"{ans}\""); + + if ans == "y": + return True + elif ans == "n": + return False + + print(error_msg) ## Clears the working directory def remove_working_dir():