1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
{
lib,
stdenv,
buildNpmPackage,
fetchFromGitHub,
electron_31,
darwin,
copyDesktopItems,
makeDesktopItem,
...
}:
let
pname = "feishin";
version = "0.9.0";
src = fetchFromGitHub {
owner = "jeffvli";
repo = "feishin";
rev = "v${version}";
hash = "sha256-3gQ39GhYPme0kGAtM5DsG9RYwf23OAdkp3uVt7c1SQU=";
};
electron = electron_31;
in
buildNpmPackage {
inherit pname version;
inherit src;
npmDepsHash = "sha256-u+zbPB6u9EYVr9oHnLlKC0AyCLn4nq4TFVPSs2oWsbo=";
npmFlags = [ "--legacy-peer-deps" ];
makeCacheWritable = true;
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
nativeBuildInputs =
lib.optionals (stdenv.isLinux) [ copyDesktopItems ]
++ lib.optionals stdenv.isDarwin [ darwin.autoSignDarwinBinariesHook ];
postPatch =
''
# release/app dependencies are installed on preConfigure
substituteInPlace package.json \
--replace-fail "electron-builder install-app-deps &&" ""
# Don't check for updates.
substituteInPlace src/main/main.ts \
--replace-fail "autoUpdater.checkForUpdatesAndNotify();" ""
''
+ lib.optionalString stdenv.isLinux ''
# 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-3qUmXRiAloGgLAErR16+BGEUT0ZwHHhCxMDQRCENQB4=";
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 =
lib.optionalString stdenv.isDarwin ''
# electron-builder appears to build directly on top of Electron.app, by overwriting the files in the bundle.
cp -r ${electron.dist}/Electron.app ./
find ./Electron.app -name 'Info.plist' | xargs -d '\n' chmod +rw
# Disable code signing during build on macOS.
# https://github.com/electron-userland/electron-builder/blob/fa6fc16/docs/code-signing.md#how-to-disable-code-signing-during-the-build-process-on-macos
export CSC_IDENTITY_AUTO_DISCOVERY=false
sed -i "/afterSign/d" package.json
''
+ ''
npm exec electron-builder -- \
--dir \
-c.electronDist=${if stdenv.isDarwin then "./" else electron.dist} \
-c.electronVersion=${electron.version} \
-c.npmRebuild=false
'';
installPhase =
''
runHook preInstall
''
+ lib.optionalString stdenv.isDarwin ''
mkdir -p $out/{Applications,bin}
cp -r release/build/**/Feishin.app $out/Applications/
makeWrapper $out/Applications/Feishin.app/Contents/MacOS/Feishin $out/bin/feishin
''
+ lib.optionalString stdenv.isLinux ''
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/feishin.png
done
''
+ ''
runHook postInstall
'';
desktopItems = [
(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" ];
})
];
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; [ fromSource ];
license = licenses.gpl3Plus;
platforms = platforms.unix;
mainProgram = "feishin";
maintainers = with maintainers; [
onny
jlbribeiro
];
};
}
|