nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenvNoCC,
4 fetchFromGitHub,
5 fetchurl,
6 makeWrapper,
7 nixosTests,
8 nodejs,
9 fetchPnpmDeps,
10 pnpmConfigHook,
11 pnpm,
12 prisma_6,
13 prisma-engines_6,
14 openssl,
15 rustPlatform,
16 # build variables
17 collectApiEndpoint ? "",
18 trackerScriptNames ? [ ],
19 basePath ? "",
20}:
21let
22 sources = lib.importJSON ./sources.json;
23
24 geocities = stdenvNoCC.mkDerivation {
25 pname = "umami-geocities";
26 version = sources.geocities.date;
27 src = fetchurl {
28 url = "https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/${sources.geocities.rev}/redist/GeoLite2-City.tar.gz";
29 inherit (sources.geocities) hash;
30 };
31
32 doBuild = false;
33
34 installPhase = ''
35 mkdir -p $out
36 cp ./GeoLite2-City.mmdb $out/GeoLite2-City.mmdb
37 '';
38
39 meta.license = lib.licenses.cc-by-40;
40 };
41
42 # Pin the specific version of prisma to the one used by upstream
43 # to guarantee compatibility.
44 prisma-engines' = prisma-engines_6.overrideAttrs (old: rec {
45 version = "6.19.0";
46 src = fetchFromGitHub {
47 owner = "prisma";
48 repo = "prisma-engines";
49 tag = version;
50 hash = "sha256-icFgoKIrr3fGSVmSczlMJiT5KSb746kVldtrk+Q0wW8=";
51 };
52 cargoHash = "sha256-PgCfBcmK9RCA5BMacJ5oYEpo2DnBKx2xPbdLb79yCCY=";
53
54 cargoDeps = rustPlatform.fetchCargoVendor {
55 inherit (old) pname;
56 inherit src version;
57 hash = cargoHash;
58 };
59 });
60 prisma' = (prisma_6.override { prisma-engines_6 = prisma-engines'; }).overrideAttrs (old: rec {
61 version = "6.19.0";
62 src = fetchFromGitHub {
63 owner = "prisma";
64 repo = "prisma";
65 tag = version;
66 hash = "sha256-lFPAu296cQMDnEcLTReSHuLuOz13kd7n0GV+ifcX+lQ=";
67 };
68 pnpmDeps = old.pnpmDeps.override {
69 inherit src version;
70 hash = "sha256-9v30vhclD+sPcui/VG8dwaC8XGU6QFs/Gu8rjjoQy/w=";
71 };
72 });
73in
74stdenvNoCC.mkDerivation (finalAttrs: {
75 pname = "umami";
76 version = "3.0.3";
77
78 nativeBuildInputs = [
79 makeWrapper
80 nodejs
81 pnpmConfigHook
82 pnpm
83 ];
84
85 src = fetchFromGitHub {
86 owner = "umami-software";
87 repo = "umami";
88 tag = "v${finalAttrs.version}";
89 hash = "sha256-rkOD52suE6bihJqKvMdIvqHRIcWhSxXzUkCfmdNbC40=";
90 };
91
92 pnpmDeps = fetchPnpmDeps {
93 inherit (finalAttrs)
94 pname
95 version
96 src
97 ;
98 fetcherVersion = 3;
99 hash = "sha256-GFN94oySPCZA5K13XR8f/tByuHS571ohlYTFqaVw/Ns=";
100 };
101
102 env.CYPRESS_INSTALL_BINARY = "0";
103 env.NODE_ENV = "production";
104 env.NEXT_TELEMETRY_DISABLED = "1";
105
106 env.COLLECT_API_ENDPOINT = collectApiEndpoint;
107 env.TRACKER_SCRIPT_NAME = lib.concatStringsSep "," trackerScriptNames;
108 env.BASE_PATH = basePath;
109
110 # Needs to be non-empty during build
111 env.DATABASE_URL = "postgresql://";
112
113 # Allow prisma-cli to find prisma-engines without having to download them
114 # Only needed at build time for `prisma generate`.
115 env.PRISMA_QUERY_ENGINE_LIBRARY = "${prisma-engines'}/lib/libquery_engine.node";
116 env.PRISMA_SCHEMA_ENGINE_BINARY = "${prisma-engines'}/bin/schema-engine";
117
118 buildPhase = ''
119 runHook preBuild
120
121 pnpm build-db-client # prisma generate
122
123 pnpm build-tracker
124 pnpm build-app
125
126 runHook postBuild
127 '';
128
129 checkPhase = ''
130 runHook preCheck
131
132 pnpm test
133
134 runHook postCheck
135 '';
136
137 doCheck = true;
138
139 installPhase = ''
140 runHook preInstall
141
142 mv .next/standalone $out
143 mv .next/static $out/.next/static
144
145 cp -R public $out/public
146 cp -R prisma $out/prisma
147
148 ln -s ${geocities} $out/geo
149
150 mkdir -p $out/bin
151 # Run database migrations before starting umami.
152 # Add openssl to PATH since it is required for prisma to make SSL connections.
153 # Force working directory to $out because umami assumes many paths are relative to it (e.g., prisma and geolite).
154 makeWrapper ${nodejs}/bin/node $out/bin/umami-server \
155 --set NODE_ENV production \
156 --set NEXT_TELEMETRY_DISABLED 1 \
157 --prefix PATH : ${
158 lib.makeBinPath [
159 openssl
160 nodejs
161 ]
162 } \
163 --chdir $out \
164 --run "${lib.getExe prisma'} migrate deploy" \
165 --add-flags "$out/server.js"
166
167 runHook postInstall
168 '';
169
170 passthru = {
171 tests = {
172 inherit (nixosTests) umami;
173 };
174 inherit
175 sources
176 geocities
177 ;
178 prisma = prisma';
179 prisma-engines = prisma-engines';
180 updateScript = ./update.sh;
181 };
182
183 meta = {
184 changelog = "https://github.com/umami-software/umami/releases/tag/v${finalAttrs.version}";
185 description = "Simple, easy to use, self-hosted web analytics solution";
186 homepage = "https://umami.is/";
187 license = with lib.licenses; [
188 mit
189 cc-by-40 # geocities
190 ];
191 platforms = lib.platforms.linux;
192 mainProgram = "umami-server";
193 maintainers = with lib.maintainers; [ diogotcorreia ];
194 };
195})