about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosé Ribeiro <work@jlbribeiro.com>2024-04-12 14:23:14 +0100
committerYureka <yuka@yuka.dev>2024-04-12 18:45:19 +0200
commit528149bf41a14963e13741ad8d89b4f5cf9c5434 (patch)
tree9fe1657715e99704d1f26beb1d25c2d1c5e1d68b
parent838623c9aca39aeb8947cdbf93040c67b4065a53 (diff)
feishin: build from source
Addresses #296939 (build from source).
Continues the work started by @dotlambda in #288210.

Co-authored-by: Robert Schütz <nix@dotlambda.de>
-rw-r--r--pkgs/applications/audio/feishin/darwin.nix41
-rw-r--r--pkgs/applications/audio/feishin/default.nix137
-rw-r--r--pkgs/applications/audio/feishin/linux.nix71
3 files changed, 120 insertions, 129 deletions
diff --git a/pkgs/applications/audio/feishin/darwin.nix b/pkgs/applications/audio/feishin/darwin.nix
deleted file mode 100644
index 5da2fa6ee0256..0000000000000
--- a/pkgs/applications/audio/feishin/darwin.nix
+++ /dev/null
@@ -1,41 +0,0 @@
-{ stdenv
-, lib
-, meta
-, fetchurl
-, unzip
-, mpv
-, electron_24
-, makeDesktopItem
-, makeWrapper
-, pname
-, appname
-, version
-}:
-
-stdenv.mkDerivation {
-  inherit pname version meta;
-
-  src = fetchurl {
-    url = "https://github.com/jeffvli/feishin/releases/download/v${version}/${appname}-${version}-mac-x64.zip";
-    hash = "sha256-sJg3hYOiELm+edw2JTFt6cPFdbDj6mLcLngeqEPaPgs=";
-  };
-
-  nativeBuildInputs = [ makeWrapper unzip ];
-
-  # Installs mpv as a requirement
-  propagatedBuildInputs = [ mpv ];
-
-  installPhase = ''
-    runHook preInstall
-    mkdir -p $out/{Applications/${appname}.app,bin}
-    cp -R . $out/Applications/${appname}.app
-    makeWrapper $out/Applications/${appname}.app/Contents/MacOS/${appname} $out/bin/${pname}
-    runHook postInstall
-  '';
-
-  shellHook = ''
-    set -x
-    export LD_LIBRARY_PATH=${mpv}/lib
-    set +x
-  '';
-}
diff --git a/pkgs/applications/audio/feishin/default.nix b/pkgs/applications/audio/feishin/default.nix
index c89d5163c2a6d..6cbd30244b52a 100644
--- a/pkgs/applications/audio/feishin/default.nix
+++ b/pkgs/applications/audio/feishin/default.nix
@@ -1,27 +1,130 @@
-{ lib
-, stdenv
-, callPackage
-, ...
-}@args:
-
+{
+  lib,
+  buildNpmPackage,
+  fetchFromGitHub,
+  electron_25,
+  copyDesktopItems,
+  makeDesktopItem,
+  ...
+}:
 let
-  extraArgs = removeAttrs args [ "callPackage" ];
-
   pname = "feishin";
   version = "0.5.1";
-  appname = "Feishin";
+
+  src = fetchFromGitHub {
+    owner = "jeffvli";
+    repo = pname;
+    rev = "v${version}";
+    hash = "sha256-7L1KufMiwqWgTvv7E1bDNL+epvNb5iLXI4Gee8w17qs=";
+  };
+
+  electron = electron_25;
+in
+buildNpmPackage {
+  pname = "feishin";
+  inherit version;
+
+  inherit src;
+  npmDepsHash = "sha256-TuNkVhNNOB23QnMXiGBWhDI0JXWnWdfI9MLvMq5xzJ8=";
+
+  npmFlags = [ "--legacy-peer-deps" ];
+  makeCacheWritable = true;
+
+  env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
+
+  nativeBuildInputs = [ copyDesktopItems ];
+
+  postPatch = ''
+    # release/app dependencies are installed on preConfigure
+    substituteInPlace package.json \
+      --replace-fail "electron-builder install-app-deps &&" ""
+
+    # https://github.com/electron/electron/issues/31121
+    substituteInPlace src/main/main.ts \
+      --replace-fail "process.resourcesPath" "'$out/share/feishin/resources'"
+  '';
+
+  preConfigure =
+    let
+      releaseAppDeps = buildNpmPackage {
+        pname = "${pname}-release-app";
+        inherit version;
+
+        src = "${src}/release/app";
+        npmDepsHash = "sha256-2tkds65buiT/p0fsuLk+vemvFYsmExanyJPiJOqlwP4=";
+
+        npmFlags = [ "--ignore-scripts" ];
+        dontNpmBuild = true;
+
+        env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
+      };
+      releaseNodeModules = "${releaseAppDeps}/lib/node_modules/feishin/node_modules";
+    in
+    ''
+      for release_module_path in "${releaseNodeModules}"/*; do
+        rm -rf node_modules/"$(basename "$release_module_path")"
+        ln -s "$release_module_path" node_modules/
+      done
+    '';
+
+  postBuild = ''
+    npm exec electron-builder -- \
+      --dir \
+      -c.electronDist=${electron}/libexec/electron \
+      -c.electronVersion=${electron.version} \
+      -c.npmRebuild=false
+  '';
+
+  installPhase = ''
+    runHook preInstall
+
+    mkdir -p $out/share/feishin
+    pushd release/build/*/
+    cp -r locales resources{,.pak} $out/share/feishin
+    popd
+
+    # Code relies on checking app.isPackaged, which returns false if the executable is electron.
+    # Set ELECTRON_FORCE_IS_PACKAGED=1.
+    # https://github.com/electron/electron/issues/35153#issuecomment-1202718531
+    makeWrapper ${lib.getExe electron} $out/bin/feishin \
+      --add-flags $out/share/feishin/resources/app.asar \
+      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
+      --set ELECTRON_FORCE_IS_PACKAGED=1 \
+      --inherit-argv0
+
+    for size in 32 64 128 256 512 1024; do
+      mkdir -p $out/share/icons/hicolor/"$size"x"$size"/apps
+      ln -s \
+        $out/share/feishin/resources/assets/icons/"$size"x"$size".png \
+        $out/share/icons/hicolor/"$size"x"$size"/apps/${pname}.png
+    done
+
+    runHook postInstall
+  '';
+
+  desktopItems = [
+    (makeDesktopItem {
+      name = "feishin";
+      desktopName = "Feishin";
+      comment = "Full-featured Subsonic/Jellyfin compatible desktop music player";
+      icon = pname;
+      exec = "feishin %u";
+      categories = [
+        "Audio"
+        "AudioVideo"
+      ];
+      mimeTypes = [ "x-scheme-handler/feishin" ];
+    })
+  ];
 
   meta = with lib; {
     description = "Full-featured Subsonic/Jellyfin compatible desktop music player";
     homepage = "https://github.com/jeffvli/feishin";
     changelog = "https://github.com/jeffvli/feishin/releases/tag/v${version}";
-    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
-    license = licenses.mit;
-    platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
+    sourceProvenance = with sourceTypes; [ fromSource ];
+    license = licenses.gpl3Plus;
+    platforms = platforms.unix;
+    mainProgram = "feishin";
     maintainers = with maintainers; [ onny ];
   };
-
-in
-if stdenv.isDarwin
-then callPackage ./darwin.nix (extraArgs // { inherit pname appname version meta; })
-else callPackage ./linux.nix (extraArgs // { inherit pname appname version meta; })
+}
diff --git a/pkgs/applications/audio/feishin/linux.nix b/pkgs/applications/audio/feishin/linux.nix
deleted file mode 100644
index d503492adfc9e..0000000000000
--- a/pkgs/applications/audio/feishin/linux.nix
+++ /dev/null
@@ -1,71 +0,0 @@
-{ stdenv
-, meta
-, lib
-, fetchurl
-, mpv
-, graphicsmagick
-, electron_24
-, makeDesktopItem
-, makeWrapper
-, pname
-, appname
-, version
-}:
-
-let
-  icon = fetchurl {
-    url =
-      "https://github.com/jeffvli/feishin/raw/development/assets/icons/1024x1024.png";
-    sha256 = "sha256-8Qigt1CNMa3SDVK2cdqWJuMSl19yfy6nPQfME4qA48I=";
-  };
-
-  desktopItem = makeDesktopItem {
-    name = "feishin";
-    desktopName = "Feishin";
-    comment = "Full-featured Subsonic/Jellyfin compatible desktop music player";
-    icon = "feishin";
-    exec = "feishin %u";
-    categories = [ "Audio" "AudioVideo" ];
-    mimeTypes = [ "x-scheme-handler/feishin" ];
-  };
-in
-
-stdenv.mkDerivation {
-  inherit pname version meta;
-
-  src = fetchurl {
-    url = "https://github.com/jeffvli/feishin/releases/download/v${version}/${appname}-${version}-linux-x64.tar.xz";
-    hash = "sha256-uYswGxSXz2YddoFs5F7f+ywqAr7qXqp6WryQ7ENSawQ=";
-  };
-
-
-  nativeBuildInputs = [ makeWrapper graphicsmagick ];
-
-  # Installs mpv as a requirement
-  propagatedBuildInputs = [ mpv ];
-
-  installPhase = ''
-    runHook preInstall
-
-    mkdir -p $out/bin
-    mkdir -p $out/share
-    cp -r resources $out/share/${pname}/
-    cp -r locales $out/share/${pname}/
-
-    makeWrapper ${electron_24}/bin/electron $out/bin/${pname} \
-      --add-flags $out/share/${pname}/app.asar
-    install -m 444 -D "${desktopItem}/share/applications/"* \
-      -t $out/share/applications/
-    for size in 16 24 32 48 64 128 256 512; do
-      mkdir -p $out/share/icons/hicolor/"$size"x"$size"/apps
-      gm convert -resize "$size"x"$size" ${icon} $out/share/icons/hicolor/"$size"x"$size"/apps/${appname}.png
-    done
-    runHook postInstall
-  '';
-
-  shellHook = ''
-    set -x
-    export LD_LIBRARY_PATH=${mpv}/lib
-    set +x
-  '';
-}