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
|
{
lib,
stdenv,
fetchFromGitHub,
buildNpmPackage,
systemdLibs,
coreutils,
ffmpeg-headless,
imagemagick_light,
procps,
python3,
xorg,
nix-update-script,
# chromedriver is more efficient than geckodriver, but is available on less platforms.
withChromium ? (lib.elem stdenv.hostPlatform.system chromedriver.meta.platforms),
chromedriver,
chromium,
withFirefox ? (lib.elem stdenv.hostPlatform.system geckodriver.meta.platforms),
geckodriver,
firefox,
}:
assert
(!withFirefox && !withChromium) -> throw "Either `withFirefox` or `withChromium` must be enabled.";
buildNpmPackage rec {
pname = "sitespeed-io";
version = "37.3.2";
src = fetchFromGitHub {
owner = "sitespeedio";
repo = "sitespeed.io";
tag = "v${version}";
hash = "sha256-sLRwNWAP83Lcnz39AkPc//NIGwRf70UqritTVJqMiws=";
};
postPatch = ''
ln -s npm-shrinkwrap.json package-lock.json
'';
# Don't try to download the browser drivers
CHROMEDRIVER_SKIP_DOWNLOAD = true;
GECKODRIVER_SKIP_DOWNLOAD = true;
EDGEDRIVER_SKIP_DOWNLOAD = true;
buildInputs = [
systemdLibs
];
dontNpmBuild = true;
npmInstallFlags = [ "--omit=dev" ];
npmDepsHash = "sha256-mDcvAvZgTJ4vEHb6ZAtZrBnmHglf1i4Yipl3bxIkw0s=";
postInstall = ''
mv $out/bin/sitespeed{.,-}io
mv $out/bin/sitespeed{.,-}io-wpr
'';
postFixup =
let
chromiumArgs = lib.concatStringsSep " " [
"--browsertime.chrome.chromedriverPath=${lib.getExe chromedriver}"
"--browsertime.chrome.binaryPath=${lib.getExe chromium}"
];
firefoxArgs = lib.concatStringsSep " " [
"--browsertime.firefox.geckodriverPath=${lib.getExe geckodriver}"
"--browsertime.firefox.binaryPath=${lib.getExe firefox}"
# Firefox crashes if the profile template dir is not writable
"--browsertime.firefox.profileTemplate=$(mktemp -d)"
];
in
''
wrapProgram $out/bin/sitespeed-io \
--set PATH ${
lib.makeBinPath [
(python3.withPackages (p: [
p.numpy
p.opencv4
p.pyssim
]))
ffmpeg-headless
imagemagick_light
xorg.xorgserver
procps
coreutils
]
} \
${lib.optionalString withChromium "--add-flags '${chromiumArgs}'"} \
${lib.optionalString withFirefox "--add-flags '${firefoxArgs}'"} \
${lib.optionalString (!withFirefox && withChromium) "--add-flags '-b chrome'"} \
${lib.optionalString (withFirefox && !withChromium) "--add-flags '-b firefox'"}
'';
passthru = {
updateScript = nix-update-script { };
};
meta = {
description = "Open source tool that helps you monitor, analyze and optimize your website speed and performance";
homepage = "https://sitespeed.io";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ misterio77 ];
platforms = lib.unique (geckodriver.meta.platforms ++ chromedriver.meta.platforms);
mainProgram = "sitespeed-io";
};
}
|