-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
293 lines (293 loc) · 11.6 KB
/
flake.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
{
inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05"; };
outputs = inputs@{ nixpkgs, ... }:
let
eachSystem = systems: f:
let
op = attrs: system:
let
ret = f system;
op = attrs: key:
let
appendSystem = key: system: ret: { ${system} = ret.${key}; };
in attrs // {
${key} = (attrs.${key} or { })
// (appendSystem key system ret);
};
in builtins.foldl' op attrs (builtins.attrNames ret);
in builtins.foldl' op { } systems;
defaultSystems = [ "x86_64-linux" "aarch64-darwin" ];
in eachSystem defaultSystems (system:
let
pkgs = import nixpkgs { inherit system; };
basename = "appname";
src = pkgs.nix-gitignore.gitignoreSource [ ".git" ] ./.;
package = (pkgs.lib.importJSON (src + "/package.json"));
nodeVersion =
builtins.elemAt (pkgs.lib.versions.splitVersion pkgs.nodejs.version)
0;
webappDrv = buildMode:
pkgs.mkYarnPackage rec {
name = package.name;
version = package.version;
src = pkgs.nix-gitignore.gitignoreSource [ ".git" ] ./.;
preConfigure = ''
substituteInPlace package.json --replace "webpack --config webpack.web.config.mjs" "yarn exec webpack-cli -- --mode=development --config webpack.web.config.mjs --env buildMode=${buildMode}"
'';
buildPhase = ''
yarn run build:webapp
'';
installPhase = "cp -r ./deps/${name}/release/renderer $out";
distPhase = "true";
};
webapp = webappDrv "webapp";
server = pkgs.mkYarnPackage rec {
name = basename + "-server";
version = "1.0.0";
src = ./src/server;
buildPhase = ''
mkdir -p deps/${name}/build
cp -r ${webappDrv "server"}/* deps/${name}/build/
chmod -R 755 deps/${name}/build/*
'';
};
electronBuilds = {
"23.1.0" = {
"linux-x64" = pkgs.fetchurl {
url =
"https://github.com/electron/electron/releases/download/v23.1.0/electron-v23.1.0-linux-x64.zip";
sha256 = "sha256-fqwx/a+xhUr2W9Rr6L8xGFEH2xl5PeUs5HfEj8jSDyk=";
};
"win32-x64" = pkgs.fetchurl {
url =
"https://github.com/electron/electron/releases/download/v23.1.0/electron-v23.1.0-win32-x64.zip";
sha256 = "sha256-UnbuaHBFnxbuhGk3Uwamp8A+Rp9ZyETmAQZWvGQo8OY=";
};
"win32-ia32" = pkgs.fetchurl {
url =
"https://github.com/electron/electron/releases/download/v23.1.0/electron-v23.1.0-win32-ia32.zip";
sha256 = "sha256-GAB7V4P9t5qMCpQk0/ZJkLnPo09UtWmTJ/M+UKG+gyg=";
};
"darwin-x64" = pkgs.fetchurl {
url =
"https://github.com/electron/electron/releases/download/v23.1.0/electron-v23.1.0-darwin-x64.zip";
sha256 = "sha256-+MnFGuGQzKSya//09sOjq27viLPTysdhvzfFxTPD8+0=";
};
"darwin-arm64" = pkgs.fetchurl {
url =
"https://github.com/electron/electron/releases/download/v23.1.0/electron-v23.1.0-darwin-arm64.zip";
sha256 = "sha256-rXQthvZCDMSc2xzpPwqRnqNCjKkCh4u7MkHuYDAw7/8=";
};
};
};
electronZipDir = let electronBuild = electronBuilds."23.1.0";
in pkgs.linkFarm "electron-zip-dir" [
{
name = "${electronBuild.linux-x64.name}";
path = electronBuild.linux-x64;
}
{
name = "${electronBuild.win32-x64.name}";
path = electronBuild.win32-x64;
}
{
name = "${electronBuild.win32-ia32.name}";
path = electronBuild.win32-ia32;
}
{
name = "${electronBuild.darwin-x64.name}";
path = electronBuild.darwin-x64;
}
{
name = "${electronBuild.darwin-arm64.name}";
path = electronBuild.darwin-arm64;
}
];
buildZip = arch:
pkgs.mkYarnPackage rec {
name = package.name;
version = package.version;
src = pkgs.nix-gitignore.gitignoreSource [ ".git" ] ./.;
electron_zip_dir = electronZipDir;
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
extraBuildInputs = [ pkgs.zip ];
# DEBUG = "*";
buildPhase = ''
mkdir home
touch home/.skip-forge-system-check
rm ./deps/${name}/${name}
HOME="$(realpath home)" yarn run electron-forge -- make --arch ${arch} --platform darwin --targets @electron-forge/maker-zip
'';
installPhase =
"cp -r ./deps/${name}/out/make/zip/darwin/${arch} $out";
distPhase = "true";
};
buildExeSquirrel = arch:
pkgs.mkYarnPackage rec {
name = package.name;
version = package.version;
src = pkgs.nix-gitignore.gitignoreSource [ ".git" ] ./.;
electron_zip_dir = electronZipDir;
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
extraBuildInputs =
[ pkgs.wineWowPackages.full pkgs.mono pkgs.fontconfig pkgs.zip ];
# DEBUG = "*";
preConfigure = ''
# substituteInPlace package.json --replace "electron-forge make" "yarn exec electron-forge -- make --arch ${arch} --platform win32 --targets @electron-forge/maker-squirrel"
'';
buildPhase = ''
# electron-forge needs 'home' with a skip check file
mkdir home
touch home/.skip-forge-system-check
## squirrel is upset with symlink './deps/name/name -> .deps/name'
#rm ./deps/${name}/${name}
## squirrel needs write access to node_modules
#rm ./deps/${name}/node_modules
#rm ./node_modules/${name}
#cp -r ./node_modules ./deps/${name}/node_modules
#chmod -R 755 ./deps/${name}/node_modules
## squirrel needs fontconfig
## squirrel tries to start a GUI app and fails
# DISPLAY=:0 HOME="$(realpath home)" FONTCONFIG_FILE=${pkgs.fontconfig.out}/etc/fonts/fonts.conf FONTCONFIG_PATH=${pkgs.fontconfig.out}/etc/fonts/ yarn run build:electron
'';
installPhase =
"cp -r ./deps/${name}/out/make/squirrel.windows/${arch} $out";
distPhase = "true";
};
buildExe = arch:
pkgs.mkYarnPackage rec {
name = package.name;
version = package.version;
src = pkgs.nix-gitignore.gitignoreSource [ ".git" ] ./.;
electron_zip_dir = electronZipDir;
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
extraBuildInputs =
[ pkgs.wineWowPackages.full pkgs.mono pkgs.fontconfig pkgs.zip ];
# DEBUG = "*";
preConfigure = ''
substituteInPlace package.json --replace "electron-forge make" "yarn exec electron-forge -- make --platform win32 --arch ${arch} --targets @electron-forge/maker-zip"
'';
buildPhase = ''
# electron-forge needs 'home' with a skip check file
mkdir home
touch home/.skip-forge-system-check
HOME="$(realpath home)" yarn run build:electron
'';
installPhase =
"cp -r ./deps/appname/out/make/zip/win32/${arch} $out";
distPhase = "true";
};
buildRpm = arch:
let
builtRpm = pkgs.vmTools.runInLinuxVM (pkgs.mkYarnPackage rec {
memSize = 4096; # 4 GiB for the VM
name = package.name;
version = package.version;
src = pkgs.nix-gitignore.gitignoreSource [ ".git" ] ./.;
electron_zip_dir = electronZipDir;
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
extraBuildInputs = [ pkgs.rpm ];
# DEBUG = "*";
preConfigure = ''
substituteInPlace package.json --replace "electron-forge make" "yarn exec electron-forge -- make --arch ${arch} --platform linux --targets @electron-forge/maker-rpm"
'';
buildPhase = ''
mkdir home
touch home/.skip-forge-system-check
rm ./deps/${name}/${name}
HOME="$(realpath home)" yarn run build:electron
'';
installPhase = "cp -r ./deps/${name}/out/make/rpm/${arch} $out";
distPhase = "true";
dontFixup = true;
});
in pkgs.runCommand builtRpm.name { version = builtRpm.version; } ''
cp -r ${builtRpm}/* $out
'';
buildDeb = arch:
pkgs.mkYarnPackage rec {
name = package.name;
version = package.version;
src = pkgs.nix-gitignore.gitignoreSource [ ".git" ] ./.;
electron_zip_dir = electronZipDir;
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
extraBuildInputs = [ pkgs.dpkg pkgs.fakeroot ];
# DEBUG = "*";
preConfigure = ''
substituteInPlace package.json --replace "electron-forge make" "yarn exec electron-forge -- make --arch ${arch} --platform linux --targets @electron-forge/maker-deb"
'';
buildPhase = ''
mkdir home
touch home/.skip-forge-system-check
rm ./deps/${name}/${name}
HOME="$(realpath home)" yarn run build:electron
'';
installPhase = "cp -r ./deps/${name}/out/make/deb/${arch} $out";
distPhase = "true";
};
in rec {
packages = {
inherit webapp server;
linux = {
x64 = {
deb = buildDeb "x64";
rpm = buildRpm "x64";
};
};
windows = { x64 = { exe = buildExe "x64"; }; };
macos = {
x64 = { zip = buildZip "x64"; };
arm64 = { zip = buildZip "arm64"; };
};
all = pkgs.linkFarm "electron-appname" [
{
name = "linux-x64-deb";
path = packages.linux.x64.deb;
}
{
name = "linux-x64-rpm";
path = packages.linux.x64.rpm;
}
{
name = "windows-x64-exe";
path = packages.windows.x64.exe;
}
{
name = "macos-arm64-zip";
path = packages.macos.arm64.zip;
}
{
name = "macos-x64-zip";
path = packages.macos.x64.zip;
}
];
};
defaultPackage = packages.webapp;
defaultApp = server;
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
nodejs
yarn
(if system == "x86_64-linux" then [
# debian builds
dpkg
fakeroot
# rpm builds
rpm
# exe builds
wineWowPackages.full
mono
# zip builds
zip
# github releases
gitAndTools.gh
] else
[ ])
];
# prevent electron download from electron in package.json
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
# use the electron builds from here
electron_zip_dir = electronZipDir;
};
});
}