diff --git a/pkgs/by-name/fr/freetube/package.nix b/pkgs/by-name/fr/freetube/package.nix index e5d1edc62e973..bacfc19854aea 100644 --- a/pkgs/by-name/fr/freetube/package.nix +++ b/pkgs/by-name/fr/freetube/package.nix @@ -1,55 +1,107 @@ { - stdenv, lib, - fetchurl, - appimageTools, - makeWrapper, + stdenvNoCC, + fetchFromGitHub, + fetchYarnDeps, + replaceVars, + makeDesktopItem, + + nodejs, + yarnConfigHook, + yarnBuildHook, + makeShellWrapper, + copyDesktopItems, electron, + nixosTests, }: - -stdenv.mkDerivation rec { +let + description = "Open Source YouTube app for privacy"; +in +stdenvNoCC.mkDerivation (finalAttrs: { pname = "freetube"; version = "0.22.1"; - src = fetchurl { - url = "https://github.com/FreeTubeApp/FreeTube/releases/download/v${version}-beta/freetube_${version}_amd64.AppImage"; - hash = "sha256-HbU5yRSP5Gk473ZoQL3HD2Bph/U/sq1Dd0eFpxyKc9s="; + src = fetchFromGitHub { + owner = "FreeTubeApp"; + repo = "FreeTube"; + tag = "v${finalAttrs.version}-beta"; + hash = "sha256-FND4jYnNeqsyCXkVB+DKr8hu720+XEjOZJ/iRZGI3y8="; }; - passthru.tests = nixosTests.freetube; + # Darwin requires writable Electron dist + postUnpack = + if stdenvNoCC.hostPlatform.isDarwin then + '' + cp -r ${electron.dist} electron-dist + chmod -R u+w electron-dist + '' + else + '' + ln -s ${electron.dist} electron-dist + ''; - appimageContents = appimageTools.extractType2 { inherit pname version src; }; + patches = [ + (replaceVars ./patch-build-script.patch { + electron-version = electron.version; + }) + ]; - dontUnpack = true; - dontConfigure = true; - dontBuild = true; - - nativeBuildInputs = [ makeWrapper ]; + yarnOfflineCache = fetchYarnDeps { + yarnLock = "${finalAttrs.src}/yarn.lock"; + hash = "sha256-cvRnPxRy3oawZUu97qYu+IgbXLYej/kykrCDJ4qLvIg="; + }; - installPhase = '' - runHook preInstall + nativeBuildInputs = [ + nodejs + yarnConfigHook + yarnBuildHook + makeShellWrapper + copyDesktopItems + ]; - mkdir -p $out/bin $out/share/${pname} $out/share/applications $out/share/icons/hicolor/scalable/apps + installPhase = + '' + runHook preInstall + '' + + lib.optionalString stdenvNoCC.hostPlatform.isLinux '' + mkdir -p $out/share/freetube + cp -r build/*-unpacked/{locales,resources{,.pak}} -t $out/share/freetube - cp -a ${appimageContents}/{locales,resources} $out/share/${pname} - cp -a ${appimageContents}/freetube.desktop $out/share/applications/${pname}.desktop - cp -a ${appimageContents}/usr/share/icons/hicolor/scalable/freetube.svg $out/share/icons/hicolor/scalable/apps + makeWrapper ${lib.getExe electron} $out/bin/freetube \ + --add-flags "$out/share/freetube/resources/app.asar" \ + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" - substituteInPlace $out/share/applications/${pname}.desktop \ - --replace 'Exec=AppRun' 'Exec=${pname}' + install -D _icons/icon.svg $out/share/icons/hicolor/scalable/apps/freetube.svg + '' + + lib.optionalString stdenvNoCC.hostPlatform.isDarwin '' + mkdir -p $out/Applications + cp -r build/mac*/FreeTube.app $out/Applications + ln -s "$out/Applications/FreeTube.app/Contents/MacOS/FreeTube" $out/bin/freetube + '' + + '' + runHook postInstall + ''; - runHook postInstall - ''; + desktopItems = [ + (makeDesktopItem { + name = "freetube"; + desktopName = "FreeTube"; + comment = description; + exec = "freetube %U"; + terminal = false; + type = "Application"; + icon = "freetube"; + startupWMClass = "FreeTube"; + mimeTypes = [ "x-scheme-handler/freetube" ]; + categories = [ "Network" ]; + }) + ]; - postFixup = '' - makeWrapper ${electron}/bin/electron $out/bin/${pname} \ - --add-flags $out/share/${pname}/resources/app.asar \ - --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime=true}}" - ''; + passthru.tests = nixosTests.freetube; meta = { - description = "Open Source YouTube app for privacy"; + inherit description; homepage = "https://freetubeapp.io/"; license = lib.licenses.agpl3Only; maintainers = with lib.maintainers; [ @@ -61,4 +113,4 @@ stdenv.mkDerivation rec { inherit (electron.meta) platforms; mainProgram = "freetube"; }; -} +}) diff --git a/pkgs/by-name/fr/freetube/patch-build-script.patch b/pkgs/by-name/fr/freetube/patch-build-script.patch new file mode 100644 index 0000000000000..c543391605dd1 --- /dev/null +++ b/pkgs/by-name/fr/freetube/patch-build-script.patch @@ -0,0 +1,13 @@ +diff --git a/_scripts/ebuilder.config.js b/_scripts/ebuilder.config.js +index 5b79d961..9f5945d2 100644 +--- a/_scripts/ebuilder.config.js ++++ b/_scripts/ebuilder.config.js +@@ -1,6 +1,8 @@ + const { name, productName } = require('../package.json') + + const config = { ++ electronVersion: "@electron-version@", ++ electronDist: "electron-dist", + appId: `io.freetubeapp.${name}`, + copyright: 'Copyleft © 2020-2024 freetubeapp@protonmail.com', + // asar: false,