diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2021-06-06 23:35:46 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2021-06-06 23:35:46 +0200 |
commit | a565d58b53473c40fcb8b6e1e16b83906a76fbdd (patch) | |
tree | 516b5e3610c33e84ae0ea09f4808538eb15a539a /pkgs/umami | |
parent | 5be300c116687fb79d37c0a7733b8e4b2bcdf1a1 (diff) | |
download | Nix-a565d58b53473c40fcb8b6e1e16b83906a76fbdd.tar.gz Nix-a565d58b53473c40fcb8b6e1e16b83906a76fbdd.tar.zst Nix-a565d58b53473c40fcb8b6e1e16b83906a76fbdd.zip |
Add umami
Diffstat (limited to 'pkgs/umami')
-rw-r--r-- | pkgs/umami/build-geo.patch | 15 | ||||
-rw-r--r-- | pkgs/umami/default.nix | 72 |
2 files changed, 87 insertions, 0 deletions
diff --git a/pkgs/umami/build-geo.patch b/pkgs/umami/build-geo.patch new file mode 100644 index 0000000..7a4f075 --- /dev/null +++ b/pkgs/umami/build-geo.patch | |||
@@ -0,0 +1,15 @@ | |||
1 | diff --git a/scripts/build-geo.js b/scripts/build-geo.js | ||
2 | index cc66f94..5464b54 100644 | ||
3 | --- a/scripts/build-geo.js | ||
4 | +++ b/scripts/build-geo.js | ||
5 | @@ -22,9 +22,7 @@ if (!fs.existsSync(dest)) { | ||
6 | |||
7 | const download = url => | ||
8 | new Promise(resolve => { | ||
9 | - https.get(url, res => { | ||
10 | - resolve(res.pipe(zlib.createGunzip({})).pipe(tar.t())); | ||
11 | - }); | ||
12 | + resolve(fs.createReadStream(url).pipe(zlib.createGunzip({})).pipe(tar.t())); | ||
13 | }); | ||
14 | |||
15 | download(url).then( | ||
diff --git a/pkgs/umami/default.nix b/pkgs/umami/default.nix new file mode 100644 index 0000000..5620f90 --- /dev/null +++ b/pkgs/umami/default.nix | |||
@@ -0,0 +1,72 @@ | |||
1 | { nodejs, writeScriptBin, stdenv, yarn2nix-moretea, lib, fetchzip, fetchurl, zlib, openssl, fetchFromGitHub }: | ||
2 | let | ||
3 | version = "1.17.0"; | ||
4 | geolite2-country-url = "https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/master/redist/GeoLite2-Country.tar.gz"; | ||
5 | geolite2-country = fetchurl { | ||
6 | url = geolite2-country-url; | ||
7 | sha256 = "0mdjvx1dfpkhg5kbp7jnrspzybaavhlxmna44l7rw05nrw5nv9zw"; | ||
8 | }; | ||
9 | toBin = sha256: name: fetchurl { | ||
10 | inherit name sha256; | ||
11 | url = "https://binaries.prisma.sh/all_commits/e421996c87d5f3c8f7eeadd502d4ad402c89464d/debian-openssl-1.1.x/${name}.gz"; | ||
12 | downloadToTemp = true; | ||
13 | executable = true; | ||
14 | postFetch = '' | ||
15 | cat "$downloadedFile" | gunzip > $out | ||
16 | patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" \ | ||
17 | --set-rpath "${lib.makeLibraryPath [ openssl zlib ]}:$(patchelf --print-rpath $out)" \ | ||
18 | $out | ||
19 | chmod +x $out | ||
20 | ''; | ||
21 | }; | ||
22 | binaries = { | ||
23 | DATABASE_TYPE = "postgresql"; | ||
24 | PRISMA_QUERY_ENGINE_BINARY = toBin "1sy67xqvbmgzksw7bl31k74k41jr44n514idqbi70j2i6jxbrl4j" "query-engine"; | ||
25 | PRISMA_INTROSPECTION_ENGINE_BINARY = toBin "1kcszg11f71sg2y0ki7kg4prwlyb67bdjpjcky9kyjd8n9ilc8hj" "introspection-engine"; | ||
26 | PRISMA_MIGRATION_ENGINE_BINARY = toBin "1lmz0wwjaavap9k6z5ysqrhlgs3r3kc9jpri2lv0lq95qmwr5hzq" "migration-engine"; | ||
27 | PRISMA_FMT_BINARY = toBin "0241aszja3j1pp7pxs40irmfj06ilfjbzyqjzrzrb5azk7izwm73" "prisma-fmt"; | ||
28 | }; | ||
29 | src = fetchFromGitHub { | ||
30 | owner = "mikecao"; | ||
31 | repo = "umami"; | ||
32 | rev = "v${version}"; | ||
33 | sha256 = "15jfgf057lsl20vdw45v5cim5d2ilalzaaxn6h82pz4d2fj1w0nh"; | ||
34 | }; | ||
35 | node-modules = yarn2nix-moretea.mkYarnModules rec { | ||
36 | pname = "umami"; | ||
37 | inherit version; | ||
38 | name = "${pname}-${version}"; | ||
39 | yarnLock = "${src}/yarn.lock"; | ||
40 | packageJSON = "${src}/package.json"; | ||
41 | pkgConfig.npm-run-all.postInstall = '' | ||
42 | patchShebangs . | ||
43 | ''; | ||
44 | pkgConfig.rollup.postInstall = '' | ||
45 | patchShebangs . | ||
46 | ''; | ||
47 | }; | ||
48 | package = stdenv.mkDerivation (binaries // { | ||
49 | pname = "umami"; | ||
50 | inherit version src; | ||
51 | buildInputs = [ nodejs ]; | ||
52 | patches = [ ./build-geo.patch ]; | ||
53 | configurePhase = '' | ||
54 | cp -r ${node-modules}/node_modules . | ||
55 | chmod u+w -R node_modules | ||
56 | ''; | ||
57 | buildPhase = '' | ||
58 | sed -i -e "s@${geolite2-country-url}@${geolite2-country}@" scripts/build-geo.js | ||
59 | npm run build | ||
60 | ''; | ||
61 | installPhase = '' | ||
62 | cp -a . $out | ||
63 | ''; | ||
64 | }); | ||
65 | script = writeScriptBin "umami" ('' | ||
66 | #! ${stdenv.shell} | ||
67 | cd ${package} | ||
68 | '' + builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: v: "export ${n}=${v}") binaries) + "\n" + '' | ||
69 | ${nodejs}/bin/npm run start-env | ||
70 | ''); | ||
71 | in | ||
72 | script // { nodeApp = package; } | ||