Skip to content

Commit

Permalink
freetube: build from source
Browse files Browse the repository at this point in the history
  • Loading branch information
pluiedev committed Dec 17, 2024
1 parent c4435d0 commit 13faeaf
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 33 deletions.
118 changes: 85 additions & 33 deletions pkgs/by-name/fr/freetube/package.nix
Original file line number Diff line number Diff line change
@@ -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; [
Expand All @@ -61,4 +113,4 @@ stdenv.mkDerivation rec {
inherit (electron.meta) platforms;
mainProgram = "freetube";
};
}
})
13 changes: 13 additions & 0 deletions pkgs/by-name/fr/freetube/patch-build-script.patch
Original file line number Diff line number Diff line change
@@ -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 [email protected]',
// asar: false,

0 comments on commit 13faeaf

Please sign in to comment.