Skip to content

Commit

Permalink
Merge pull request NixOS#253687 from dotlambda/plausible-2.0.0
Browse files Browse the repository at this point in the history
plausible: 1.4.4 -> 2.0.0
  • Loading branch information
dotlambda authored Sep 20, 2023
2 parents ba60622 + c4574a9 commit 728bae0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12,110 deletions.
5 changes: 2 additions & 3 deletions nixos/modules/services/web-apps/plausible.nix
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,10 @@ in {
# setup
${cfg.package}/createdb.sh
${cfg.package}/migrate.sh
export IP_GEOLOCATION_DB=${pkgs.dbip-country-lite}/share/dbip/dbip-country-lite.mmdb
${cfg.package}/bin/plausible eval "(Plausible.Release.prepare() ; Plausible.Auth.create_user(\"$ADMIN_USER_NAME\", \"$ADMIN_USER_EMAIL\", \"$ADMIN_USER_PWD\"))"
${optionalString cfg.adminUser.activate ''
if ! ${cfg.package}/init-admin.sh | grep 'already exists'; then
psql -d plausible <<< "UPDATE users SET email_verified=true;"
fi
psql -d plausible <<< "UPDATE users SET email_verified=true where email = '$ADMIN_USER_EMAIL';"
''}
exec plausible start
Expand Down
2 changes: 2 additions & 0 deletions nixos/tests/plausible.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
machine.succeed("curl -f localhost:8000 >&2")
machine.succeed("curl -f localhost:8000/js/script.js >&2")
csrf_token = machine.succeed(
"curl -c /tmp/cookies localhost:8000/login | grep '_csrf_token' | sed -E 's,.*value=\"(.*)\".*,\\1,g'"
)
Expand Down
62 changes: 38 additions & 24 deletions pkgs/servers/web-apps/plausible/default.nix
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
{ lib
, stdenv
, beamPackages
, buildNpmPackage
, fetchFromGitHub
, glibcLocales
, cacert
, mkYarnModules
, fetchYarnDeps
, nodejs
, nixosTests
}:

let
pname = "plausible";
version = "1.5.1";
version = "2.0.0";

src = fetchFromGitHub {
owner = "plausible";
repo = "analytics";
rev = "v${version}";
hash = "sha256-KcIZMsWlKGCZFi7DrTS8JMWEahdERoExtpBj+7Ec+FQ=";
hash = "sha256-yrTwxBguAZbfEKucUL+w49Hr6D7v9/2OjY1h27+w5WI=";
};

# TODO consider using `mix2nix` as soon as it supports git dependencies.
mixFodDeps = beamPackages.fetchMixDeps {
pname = "${pname}-deps";
inherit src version;
hash = "sha256-rLkD2FuNFKU3nB8FT/qPgSVP8H60qEmHtPvcdw4JUF8=";
hash = "sha256-CAyZLpjmw1JreK3MopqI0XsWhP+fJEMpXlww7CibSaM=";
};

yarnDeps = mkYarnModules {
pname = "${pname}-yarn-deps";
assets = buildNpmPackage {
pname = "${pname}-assets";
inherit version;
packageJSON = ./package.json;
yarnLock = ./yarn.lock;
yarnNix = ./yarn.nix;
preBuild = ''
mkdir -p tmp/deps
cp -r ${mixFodDeps}/phoenix tmp/deps/phoenix
cp -r ${mixFodDeps}/phoenix_html tmp/deps/phoenix_html
src = "${src}/assets";
npmDepsHash = "sha256-2t1M6RQhBjZxx36qawVUVC+ob9SvQIq5dy4HgVeY2Eo=";
dontNpmBuild = true;
installPhase = ''
runHook preInstall
cp -r . "$out"
runHook postInstall
'';
postBuild = ''
echo 'module.exports = {}' > $out/node_modules/flatpickr/dist/postcss.config.js
};

tracker = buildNpmPackage {
pname = "${pname}-tracker";
inherit version;
src = "${src}/tracker";
npmDepsHash = "sha256-y09jVSwUrxF0nLpLqS1yQweYL+iMF6jVx0sUdQtvrpc=";
dontNpmBuild = true;
installPhase = ''
runHook preInstall
cp -r . "$out"
runHook postInstall
'';
};
in
beamPackages.mixRelease {
inherit pname version src mixFodDeps;

nativeBuildInputs = [ nodejs ];
nativeBuildInputs = [
nodejs
];

passthru = {
tests = { inherit (nixosTests) plausible; };
Expand All @@ -58,11 +66,16 @@ beamPackages.mixRelease {
substituteInPlace lib/plausible_release.ex --replace 'defp prepare do' 'def prepare do'
'';

preBuild = ''
rm -r assets tracker
cp -r ${assets} assets
cp -r ${tracker} tracker
'';

postBuild = ''
export HOME=$TMPDIR
export NODE_OPTIONS=--openssl-legacy-provider # required for webpack compatibility with OpenSSL 3 (https://github.com/webpack/webpack/issues/14532)
ln -sf ${yarnDeps}/node_modules assets/node_modules
npm run deploy --prefix ./assets
npm run deploy --prefix ./tracker
# for external task you need a workaround for the no deps check flag
# https://github.com/phoenixframework/phoenix/issues/2690
Expand All @@ -72,8 +85,9 @@ beamPackages.mixRelease {
meta = with lib; {
license = licenses.agpl3Plus;
homepage = "https://plausible.io/";
description = " Simple, open-source, lightweight (< 1 KB) and privacy-friendly web analytics alternative to Google Analytics.";
maintainers = with maintainers; [ ];
changelog = "https://github.com/plausible/analytics/blob/${src.rev}/CHANGELOG.md";
description = " Simple, open-source, lightweight (< 1 KB) and privacy-friendly web analytics alternative to Google Analytics";
maintainers = with maintainers; [ softinio ];
platforms = platforms.unix;
};
}
72 changes: 0 additions & 72 deletions pkgs/servers/web-apps/plausible/package.json

This file was deleted.

Loading

0 comments on commit 728bae0

Please sign in to comment.