In #356221 nixpkgs removed `services.plausible.adminUser.*` because Plausible upstream removed the ability to do that with an easy CLI command, see: https://github.com/plausible/analytics/pull/2357#issuecomment-4595200593 However, Plausible's default setup without automatic admin user creation is unsafe for Plausible instances exposed to the Internet because it offers a setup wizard, allowing anybody who can reach its webserver to create the first admin users. Plausible is usually exposed to the Internet, given that it is a web analytics tool which must be web-reachable to function. NixOS defaults configure it to listen only on `localhost`, which is already good, but on NixOS it generally makes sense to be able to configure services declaratively so they work out of the box on first deploy. Workarounds such as "deploy first binding only to localhost, manually do the setup wizard, then deploy another config to expose it" are annoying. Thus, this commit adds back the original declarative `adminUser` implementation, doing the needed DB changes directly, race-free, and with better security (allowing to configure a password has instead of a plain-text password). Assisted-By: Zoo Code with Claude Opus 4.8, human review
1.4 KiB
1.4 KiB
Plausible
Plausible is a privacy-friendly alternative to Google analytics.
Basic Usage
At first, a secret key is needed to be generated. This can be done with e.g.
$ openssl rand -base64 64
After that, plausible can be deployed like this:
{
services.plausible = {
enable = true;
server = {
baseUrl = "http://analytics.example.org";
# secretKeybaseFile is a path to the file which contains the secret generated
# with openssl as described above.
secretKeybaseFile = "/run/secrets/plausible-secret-key-base";
# With an admin user seeded (below), registration can be locked down
# so only invited users (or nobody) can create further accounts.
disableRegistration = "invite_only";
};
# If you do not declare `adminUser`, Plausible shows an unauthenticated
# "first launch" setup wizard where anybody reaching the instance can create
# the first admin account. That may be convenient, but is also a security
# risk if somebody else uses it before you do.
adminUser = {
email = "admin@analytics.example.org";
# passwordHashFile is a path to a file containing the bcrypt hash of the
# admin user's password, e.g. generated with `mkpasswd -m bcrypt`.
passwordHashFile = "/run/secrets/plausible-admin-password-hash";
};
};
}