]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - flakes/mypackages/pkgs/umami/default.nix
Add flake skeletons
[perso/Immae/Config/Nix.git] / flakes / mypackages / pkgs / umami / default.nix
CommitLineData
a565d58b
IB
1{ nodejs, writeScriptBin, stdenv, yarn2nix-moretea, lib, fetchzip, fetchurl, zlib, openssl, fetchFromGitHub }:
2let
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 '');
71in
72 script // { nodeApp = package; }