lol

umami: init at 2.19.0

authored by

Diogo Correia and committed by
Niklas Hambüchen
c53516fd e3d4cd73

+254
+197
pkgs/by-name/um/umami/package.nix
··· 1 + { 2 + lib, 3 + stdenvNoCC, 4 + fetchFromGitHub, 5 + fetchurl, 6 + makeWrapper, 7 + nodejs, 8 + pnpm_10, 9 + prisma-engines, 10 + openssl, 11 + rustPlatform, 12 + # build variables 13 + databaseType ? "postgresql", 14 + collectApiEndpoint ? "", 15 + trackerScriptNames ? [ ], 16 + basePath ? "", 17 + }: 18 + let 19 + sources = lib.importJSON ./sources.json; 20 + pnpm = pnpm_10; 21 + 22 + geocities = stdenvNoCC.mkDerivation { 23 + pname = "umami-geocities"; 24 + version = sources.geocities.date; 25 + src = fetchurl { 26 + url = "https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/${sources.geocities.rev}/redist/GeoLite2-City.tar.gz"; 27 + inherit (sources.geocities) hash; 28 + }; 29 + 30 + doBuild = false; 31 + 32 + installPhase = '' 33 + mkdir -p $out 34 + cp ./GeoLite2-City.mmdb $out/GeoLite2-City.mmdb 35 + ''; 36 + 37 + meta.license = lib.licenses.cc-by-40; 38 + }; 39 + 40 + # Pin the specific version of prisma to the one used by upstream 41 + # to guarantee compatibility. 42 + prisma-engines' = prisma-engines.overrideAttrs (old: rec { 43 + version = "6.7.0"; 44 + src = fetchFromGitHub { 45 + owner = "prisma"; 46 + repo = "prisma-engines"; 47 + tag = version; 48 + hash = "sha256-Ty8BqWjZluU6a5xhSAVb2VoTVY91UUj6zoVXMKeLO4o="; 49 + }; 50 + cargoHash = "sha256-HjDoWa/JE6izUd+hmWVI1Yy3cTBlMcvD9ANsvqAoHBI="; 51 + 52 + cargoDeps = rustPlatform.fetchCargoVendor { 53 + inherit (old) pname; 54 + inherit src version; 55 + hash = cargoHash; 56 + }; 57 + }); 58 + in 59 + stdenvNoCC.mkDerivation (finalAttrs: { 60 + pname = "umami"; 61 + version = "2.19.0"; 62 + 63 + nativeBuildInputs = [ 64 + makeWrapper 65 + nodejs 66 + pnpm.configHook 67 + ]; 68 + 69 + src = fetchFromGitHub { 70 + owner = "umami-software"; 71 + repo = "umami"; 72 + tag = "v${finalAttrs.version}"; 73 + hash = "sha256-luiwGmCujbFGWANSCOiHIov56gsMQ6M+Bj0stcz9he8="; 74 + }; 75 + 76 + # install dev dependencies as well, for rollup 77 + pnpmInstallFlags = [ "--prod=false" ]; 78 + 79 + pnpmDeps = pnpm.fetchDeps { 80 + inherit (finalAttrs) 81 + pname 82 + pnpmInstallFlags 83 + version 84 + src 85 + ; 86 + fetcherVersion = 2; 87 + hash = "sha256-2GiCeCt/mU5Dm5YHQgJF3127WPHq5QLX8JRcUv6B6lE="; 88 + }; 89 + 90 + env.CYPRESS_INSTALL_BINARY = "0"; 91 + env.NODE_ENV = "production"; 92 + env.NEXT_TELEMETRY_DISABLED = "1"; 93 + 94 + # copy-db-files uses this variable to decide which Prisma schema to use 95 + env.DATABASE_TYPE = databaseType; 96 + 97 + env.COLLECT_API_ENDPOINT = collectApiEndpoint; 98 + env.TRACKER_SCRIPT_NAME = lib.concatStringsSep "," trackerScriptNames; 99 + env.BASE_PATH = basePath; 100 + 101 + # Allow prisma-cli to find prisma-engines without having to download them 102 + env.PRISMA_QUERY_ENGINE_LIBRARY = "${prisma-engines'}/lib/libquery_engine.node"; 103 + env.PRISMA_SCHEMA_ENGINE_BINARY = "${prisma-engines'}/bin/schema-engine"; 104 + 105 + buildPhase = '' 106 + runHook preBuild 107 + 108 + pnpm copy-db-files 109 + pnpm build-db-client # prisma generate 110 + 111 + pnpm build-tracker 112 + pnpm build-app 113 + 114 + runHook postBuild 115 + ''; 116 + 117 + checkPhase = '' 118 + runHook preCheck 119 + 120 + pnpm test 121 + 122 + runHook postCheck 123 + ''; 124 + 125 + doCheck = true; 126 + 127 + installPhase = '' 128 + runHook preInstall 129 + 130 + mv .next/standalone $out 131 + mv .next/static $out/.next/static 132 + 133 + # Include prisma cli in next standalone build. 134 + # This is preferred to using the prisma in nixpkgs because it guarantees 135 + # the version matches. 136 + # See https://nextjs-forum.com/post/1280550687998083198 137 + # and https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#caveats 138 + # Unfortunately, using outputFileTracingIncludes doesn't work because of pnpm's symlink structure, 139 + # so we just copy the files manually. 140 + mkdir -p $out/node_modules/.bin 141 + cp node_modules/.bin/prisma $out/node_modules/.bin 142 + cp -a node_modules/prisma $out/node_modules 143 + cp -a node_modules/.pnpm/@prisma* $out/node_modules/.pnpm 144 + cp -a node_modules/.pnpm/prisma* $out/node_modules/.pnpm 145 + # remove broken symlinks (some dependencies that are not relevant for running migrations) 146 + find "$out"/node_modules/.pnpm/@prisma* -xtype l -exec rm {} \; 147 + find "$out"/node_modules/.pnpm/prisma* -xtype l -exec rm {} \; 148 + 149 + cp -R public $out/public 150 + cp -R prisma $out/prisma 151 + 152 + ln -s ${geocities} $out/geo 153 + 154 + mkdir -p $out/bin 155 + # Run database migrations before starting umami. 156 + # Add openssl to PATH since it is required for prisma to make SSL connections. 157 + # Force working directory to $out because umami assumes many paths are relative to it (e.g., prisma and geolite). 158 + makeWrapper ${nodejs}/bin/node $out/bin/umami-server \ 159 + --set NODE_ENV production \ 160 + --set NEXT_TELEMETRY_DISABLED 1 \ 161 + --set PRISMA_QUERY_ENGINE_LIBRARY "${prisma-engines'}/lib/libquery_engine.node" \ 162 + --set PRISMA_SCHEMA_ENGINE_BINARY "${prisma-engines'}/bin/schema-engine" \ 163 + --prefix PATH : ${ 164 + lib.makeBinPath [ 165 + openssl 166 + nodejs 167 + ] 168 + } \ 169 + --chdir $out \ 170 + --run "$out/node_modules/.bin/prisma migrate deploy" \ 171 + --add-flags "$out/server.js" 172 + 173 + runHook postInstall 174 + ''; 175 + 176 + passthru = { 177 + inherit 178 + sources 179 + geocities 180 + ; 181 + prisma-engines = prisma-engines'; 182 + updateScript = ./update.sh; 183 + }; 184 + 185 + meta = with lib; { 186 + changelog = "https://github.com/umami-software/umami/releases/tag/v${finalAttrs.version}"; 187 + description = "Simple, easy to use, self-hosted web analytics solution"; 188 + homepage = "https://umami.is/"; 189 + license = with lib.licenses; [ 190 + mit 191 + cc-by-40 # geocities 192 + ]; 193 + platforms = lib.platforms.linux; 194 + mainProgram = "umami-server"; 195 + maintainers = with maintainers; [ diogotcorreia ]; 196 + }; 197 + })
+7
pkgs/by-name/um/umami/sources.json
··· 1 + { 2 + "geocities": { 3 + "rev": "0817bc800279e26e9ff045b7b129385e5b23012e", 4 + "date": "2025-07-29", 5 + "hash": "sha256-Rw9UEvUu7rtXFvHEqKza6kn9LwT6C17zJ/ljoN+t6Ek=" 6 + } 7 + }
+50
pkgs/by-name/um/umami/update.sh
··· 1 + #!/usr/bin/env nix-shell 2 + #!nix-shell -i bash -p curl jq prefetch-yarn-deps nix-prefetch-github coreutils nix-update 3 + # shellcheck shell=bash 4 + 5 + # This script exists to update geocities version and pin prisma-engines version 6 + 7 + set -euo pipefail 8 + SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" 9 + 10 + old_version=$(nix-instantiate --eval -A 'umami.version' default.nix | tr -d '"' || echo "0.0.1") 11 + version=$(curl -s "https://api.github.com/repos/umami-software/umami/releases/latest" | jq -r ".tag_name") 12 + version="${version#v}" 13 + 14 + echo "Updating to $version" 15 + 16 + if [[ "$old_version" == "$version" ]]; then 17 + echo "Already up to date!" 18 + exit 0 19 + fi 20 + 21 + nix-update --version "$version" umami 22 + 23 + echo "Fetching geolite" 24 + geocities_rev_date=$(curl https://api.github.com/repos/GitSquared/node-geolite2-redist/branches/master | jq -r ".commit.sha, .commit.commit.author.date") 25 + geocities_rev=$(echo "$geocities_rev_date" | head -1) 26 + geocities_date=$(echo "$geocities_rev_date" | tail -1 | sed 's/T.*//') 27 + 28 + # upstream is kind enough to provide a file with the hash of the tar.gz archive 29 + geocities_hash=$(curl -s "https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/$geocities_rev/redist/GeoLite2-City.tar.gz.sha256") 30 + geocities_hash_sri=$(nix-hash --to-sri --type sha256 "$geocities_hash") 31 + 32 + cat <<EOF > "$SCRIPT_DIR/sources.json" 33 + { 34 + "geocities": { 35 + "rev": "$geocities_rev", 36 + "date": "$geocities_date", 37 + "hash": "$geocities_hash_sri" 38 + } 39 + } 40 + EOF 41 + 42 + echo "Pinning Prisma version" 43 + upstream_src="https://raw.githubusercontent.com/umami-software/umami/v$version" 44 + 45 + lock=$(mktemp) 46 + curl -s -o "$lock" "$upstream_src/pnpm-lock.yaml" 47 + prisma_version=$(grep "@prisma/engines@" "$lock" | head -n1 | awk -F"[@']" '{print $4}') 48 + rm "$lock" 49 + 50 + nix-update --version "$prisma_version" umami.prisma-engines