generated from nix-community/nur-packages-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
145 lines (121 loc) · 3.98 KB
/
default.nix
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
/*
based on
https://codeberg.org/wolfangaukang/nix-agordoj/src/branch/vdhcoapp-2.0.0/pkgs/vdhcoapp
via
https://github.com/NixOS/nixpkgs/issues/112046#issuecomment-1917622236
by default, errors are not logged. fix:
WEH_NATIVE_LOGFILE=/dev/stderr ./result/bin/vdhcoapp
*/
{ lib
, stdenvNoCC
, fetchFromGitHub
, npmlock2nix
, toml2json
, ffmpeg
, nodejs
, callPackage
}:
let
filepicker = callPackage ./filepicker.nix { };
stdenv = stdenvNoCC;
in
stdenv.mkDerivation rec {
pname = "vdhcoapp";
version = "2.0.19";
src =
#if true then ./src/vdhcoapp else
fetchFromGitHub {
owner = "aclap-dev";
repo = "vdhcoapp";
/*
rev = "v${version}";
hash = "sha256-8xeZvqpRq71aShVogiwlVD3gQoPGseNOmz5E3KbsZxU=";
*/
# https://github.com/aclap-dev/vdhcoapp/pull/218
# generate config files on build time
rev = "548f6ec2366713a4b3aa733a7164e668b9818c96";
hash = "sha256-JstwbDlWiMxylxngjaChEgtpbkWobTkIywQERVTdqkw=";
};
node_modules = npmlock2nix.node_modules {
packageJson = ./package.json;
packageLockJson = ./package-lock.json;
# FIXME this requires custom node interpreter for main.js
#symlinkNodeModules = true;
# force rebuild
#preBuild = '': # asdf'';
};
nativeBuildInputs = [
toml2json
];
buildPhase = ''
toml2json --pretty config.toml >app/src/config.json
# use system ffmpeg
# https://github.com/aclap-dev/vdhcoapp/issues/49
# disable "open"
substituteInPlace app/src/converter.js \
--replace \
'const ffmpeg = findExecutableFullPath("ffmpeg", exec_dir);' \
'const ffmpeg = "${ffmpeg}/bin/ffmpeg";' \
--replace \
'const ffprobe = findExecutableFullPath("ffprobe", exec_dir);' \
'const ffprobe = "${ffmpeg}/bin/ffprobe";' \
--replace \
'const filepicker = findExecutableFullPath("filepicker", exec_dir);' \
'const filepicker = "${filepicker}/bin/filepicker";' \
--replace \
"import open from 'open';" \
"function open() {}" \
# path:
# originally, vdhcoapp is compiled into a single executable
# whose path is process.execPath
# but here, process.execPath is the node interpreter
substituteInPlace app/src/native-autoinstall.js \
--replace \
"path: process.execPath," \
"path: '$out/bin/vdhcoapp'," \
--replace \
"require('config.json')" \
"require('./config.json')" \
substituteInPlace app/src/main.js \
--replace \
"require('config.json')" \
"require('./config.json')" \
# add shebang line
if [ "$(head -c2 app/src/main.js)" != "#!" ]; then
sed -i '1 i\#!${nodejs}/bin/node\n' app/src/main.js
fi
chmod +x app/src/main.js
ln -s ${node_modules}/node_modules app/
# generate config files on build time
# enable the original install function in native-autoinstall.js
export VDHCOAPP_INSTALL_ON_BUILDTIME=1
${if !stdenv.hostPlatform.isLinux then "" else ''
echo generating config files for linux
export HOME=$PWD/app/config/linux
grep '^only_if_dir_exists = "~/\.' config.toml | cut -d'"' -f2 |
while read d; do mkdir -p "$HOME/''${d:2}"; done
./app/src/main.js install
# fix https://github.com/aclap-dev/vdhcoapp/issues/195
ln -srT app/config/linux/.mozilla app/config/linux/.librewolf
''}
${if !stdenv.hostPlatform.isDarwin then "" else ''
echo generating config files for darwin
export HOME=$PWD/app/config/darwin
grep '^only_if_dir_exists = "~/Library/' config.toml | cut -d'"' -f2 |
while read d; do mkdir -p "$HOME/''${d:2}"; done
./app/src/main.js install
''}
'';
installPhase = ''
mkdir -p $out/opt
cp -r app $out/opt/vdhcoapp
mkdir -p $out/bin
ln -sr $out/opt/vdhcoapp/src/main.js $out/bin/vdhcoapp
'';
meta = with lib; {
description = "Companion app for Video DownloadHelper";
homepage = "https://github.com/aclap-dev/vdhcoapp";
license = licenses.gpl2;
maintainers = [];
};
}