pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / by-name / fe / feishin / package.nix
blobdb26c0d6105a285f9b3b7550584e69a11e1ba3ea
2   lib,
3   stdenv,
4   buildNpmPackage,
5   fetchFromGitHub,
6   electron_31,
7   darwin,
8   copyDesktopItems,
9   makeDesktopItem,
10   ...
12 let
13   pname = "feishin";
14   version = "0.11.1";
16   src = fetchFromGitHub {
17     owner = "jeffvli";
18     repo = "feishin";
19     rev = "v${version}";
20     hash = "sha256-fHaNluLes25P/mSTSYFt97pC6uKYuBI/3PUHc84zoWg=";
21   };
23   electron = electron_31;
25 buildNpmPackage {
26   inherit pname version;
28   inherit src;
29   npmDepsHash = "sha256-8xFB47PJpa+3U+Xy+DEdWoW3/f+naFKtLQsDDVgUccA=";
31   npmFlags = [ "--legacy-peer-deps" ];
32   makeCacheWritable = true;
34   env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
36   nativeBuildInputs =
37     lib.optionals (stdenv.hostPlatform.isLinux) [ copyDesktopItems ]
38     ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.autoSignDarwinBinariesHook ];
40   postPatch =
41     ''
42       # release/app dependencies are installed on preConfigure
43       substituteInPlace package.json \
44         --replace-fail "electron-builder install-app-deps &&" ""
46       # Don't check for updates.
47       substituteInPlace src/main/main.ts \
48         --replace-fail "autoUpdater.checkForUpdatesAndNotify();" ""
49     ''
50     + lib.optionalString stdenv.hostPlatform.isLinux ''
51       # https://github.com/electron/electron/issues/31121
52       substituteInPlace src/main/main.ts \
53         --replace-fail "process.resourcesPath" "'$out/share/feishin/resources'"
54     '';
56   preConfigure =
57     let
58       releaseAppDeps = buildNpmPackage {
59         pname = "${pname}-release-app";
60         inherit version;
62         src = "${src}/release/app";
63         npmDepsHash = "sha256-gufOUBfHTDkIqRTdPqXuuk1ZT0y80y/GyI7ssvHnBYo=";
65         npmFlags = [ "--ignore-scripts" ];
66         dontNpmBuild = true;
68         env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
69       };
70       releaseNodeModules = "${releaseAppDeps}/lib/node_modules/feishin/node_modules";
71     in
72     ''
73       for release_module_path in "${releaseNodeModules}"/*; do
74         rm -rf node_modules/"$(basename "$release_module_path")"
75         ln -s "$release_module_path" node_modules/
76       done
77     '';
79   postBuild =
80     lib.optionalString stdenv.hostPlatform.isDarwin ''
81       # electron-builder appears to build directly on top of Electron.app, by overwriting the files in the bundle.
82       cp -r ${electron.dist}/Electron.app ./
83       find ./Electron.app -name 'Info.plist' | xargs -d '\n' chmod +rw
85       # Disable code signing during build on macOS.
86       # https://github.com/electron-userland/electron-builder/blob/fa6fc16/docs/code-signing.md#how-to-disable-code-signing-during-the-build-process-on-macos
87       export CSC_IDENTITY_AUTO_DISCOVERY=false
88       sed -i "/afterSign/d" package.json
89     ''
90     + ''
91       npm exec electron-builder -- \
92         --dir \
93         -c.electronDist=${if stdenv.hostPlatform.isDarwin then "./" else electron.dist} \
94         -c.electronVersion=${electron.version} \
95         -c.npmRebuild=false
96     '';
98   installPhase =
99     ''
100       runHook preInstall
101     ''
102     + lib.optionalString stdenv.hostPlatform.isDarwin ''
103       mkdir -p $out/{Applications,bin}
104       cp -r release/build/**/Feishin.app $out/Applications/
105       makeWrapper $out/Applications/Feishin.app/Contents/MacOS/Feishin $out/bin/feishin
106     ''
107     + lib.optionalString stdenv.hostPlatform.isLinux ''
108       mkdir -p $out/share/feishin
109       pushd release/build/*/
110       cp -r locales resources{,.pak} $out/share/feishin
111       popd
113       # Code relies on checking app.isPackaged, which returns false if the executable is electron.
114       # Set ELECTRON_FORCE_IS_PACKAGED=1.
115       # https://github.com/electron/electron/issues/35153#issuecomment-1202718531
116       makeWrapper ${lib.getExe electron} $out/bin/feishin \
117         --add-flags $out/share/feishin/resources/app.asar \
118         --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
119         --set ELECTRON_FORCE_IS_PACKAGED=1 \
120         --inherit-argv0
122       for size in 32 64 128 256 512 1024; do
123         mkdir -p $out/share/icons/hicolor/"$size"x"$size"/apps
124         ln -s \
125           $out/share/feishin/resources/assets/icons/"$size"x"$size".png \
126           $out/share/icons/hicolor/"$size"x"$size"/apps/feishin.png
127       done
128     ''
129     + ''
130       runHook postInstall
131     '';
133   desktopItems = [
134     (makeDesktopItem {
135       name = "feishin";
136       desktopName = "Feishin";
137       comment = "Full-featured Subsonic/Jellyfin compatible desktop music player";
138       icon = "feishin";
139       exec = "feishin %u";
140       categories = [
141         "Audio"
142         "AudioVideo"
143       ];
144       mimeTypes = [ "x-scheme-handler/feishin" ];
145     })
146   ];
148   meta = with lib; {
149     description = "Full-featured Subsonic/Jellyfin compatible desktop music player";
150     homepage = "https://github.com/jeffvli/feishin";
151     changelog = "https://github.com/jeffvli/feishin/releases/tag/v${version}";
152     sourceProvenance = with sourceTypes; [ fromSource ];
153     license = licenses.gpl3Plus;
154     platforms = platforms.unix;
155     mainProgram = "feishin";
156     maintainers = with maintainers; [
157       onny
158       jlbribeiro
159     ];
160   };