nixos/mastodon: update database configuration

Izorkin 8e14bf10 e2cebf21

Changed files
+54 -17
nixos
doc
manual
from_md
release-notes
release-notes
modules
services
web-apps
+17
nixos/doc/manual/from_md/release-notes/rl-2305.section.xml
···
</listitem>
<listitem>
<para>
+
In <literal>mastodon</literal> it is now necessary to specify
+
location of file with <literal>PostgreSQL</literal> database
+
password. In
+
<literal>services.mastodon.database.passwordFile</literal>
+
parameter default value
+
<literal>/var/lib/mastodon/secrets/db-password</literal> has
+
been changed to <literal>null</literal>.
+
</para>
+
</listitem>
+
<listitem>
+
<para>
The <literal>nix.readOnlyStore</literal> option has been
renamed to <literal>boot.readOnlyNixStore</literal> to clarify
that it configures the NixOS boot process, not the Nix daemon.
···
<para>
The minimal ISO image now uses the
<literal>nixos/modules/profiles/minimal.nix</literal> profile.
+
</para>
+
</listitem>
+
<listitem>
+
<para>
+
<literal>mastodon</literal> now supports connection to a
+
remote <literal>PostgreSQL</literal> database.
</para>
</listitem>
<listitem>
+4
nixos/doc/manual/release-notes/rl-2305.section.md
···
- Qt 5.12 and 5.14 have been removed, as the corresponding branches have been EOL upstream for a long time. This affected under 10 packages in nixpkgs, largely unmaintained upstream as well, however, out-of-tree package expressions may need to be updated manually.
+
- In `mastodon` it is now necessary to specify location of file with `PostgreSQL` database password. In `services.mastodon.database.passwordFile` parameter default value `/var/lib/mastodon/secrets/db-password` has been changed to `null`.
+
- The `nix.readOnlyStore` option has been renamed to `boot.readOnlyNixStore` to clarify that it configures the NixOS boot process, not the Nix daemon.
## Other Notable Changes {#sec-release-23.05-notable-changes}
···
- To reduce closure size in `nixos/modules/profiles/minimal.nix` profile disabled installation documentations and manuals. Also disabled `logrotate` and `udisks2` services.
- The minimal ISO image now uses the `nixos/modules/profiles/minimal.nix` profile.
+
+
- `mastodon` now supports connection to a remote `PostgreSQL` database.
- A new `virtualisation.rosetta` module was added to allow running `x86_64` binaries through [Rosetta](https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment) inside virtualised NixOS guests on Apple silicon. This feature works by default with the [UTM](https://docs.getutm.app/) virtualisation [package](https://search.nixos.org/packages?channel=unstable&show=utm&from=0&size=1&sort=relevance&type=packages&query=utm).
+33 -17
nixos/modules/services/web-apps/mastodon.nix
···
-
{ config, lib, pkgs, ... }:
+
{ lib, pkgs, config, options, ... }:
let
cfg = config.services.mastodon;
+
opt = options.services.mastodon;
+
# We only want to create a database if we're actually going to connect to it.
databaseActuallyCreateLocally = cfg.database.createLocally && cfg.database.host == "/run/postgresql";
···
REDIS_HOST = cfg.redis.host;
REDIS_PORT = toString(cfg.redis.port);
DB_HOST = cfg.database.host;
-
DB_PORT = toString(cfg.database.port);
DB_NAME = cfg.database.name;
LOCAL_DOMAIN = cfg.localDomain;
SMTP_SERVER = cfg.smtp.host;
···
TRUSTED_PROXY_IP = cfg.trustedProxy;
}
-
// (if cfg.smtp.authenticate then { SMTP_LOGIN = cfg.smtp.user; } else {})
+
// lib.optionalAttrs (cfg.database.host != "/run/postgresql" && cfg.database.port != null) { DB_PORT = toString cfg.database.port; }
+
// lib.optionalAttrs cfg.smtp.authenticate { SMTP_LOGIN = cfg.smtp.user; }
// cfg.extraConfig;
systemCallsList = [ "@cpu-emulation" "@debug" "@keyring" "@ipc" "@mount" "@obsolete" "@privileged" "@setuid" ];
···
};
port = lib.mkOption {
-
type = lib.types.port;
-
default = 5432;
+
type = lib.types.nullOr lib.types.port;
+
default = if cfg.database.createLocally then null else 5432;
+
defaultText = lib.literalExpression ''
+
if config.${opt.database.createLocally}
+
then null
+
else 5432
+
'';
description = lib.mdDoc "Database host port.";
};
···
passwordFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
-
default = "/var/lib/mastodon/secrets/db-password";
-
example = "/run/keys/mastodon-db-password";
+
default = null;
+
example = "/var/lib/mastodon/secrets/db-password";
description = lib.mdDoc ''
A file containing the password corresponding to
{option}`database.user`.
···
assertions = [
{
assertion = databaseActuallyCreateLocally -> (cfg.user == cfg.database.user);
-
message = ''For local automatic database provisioning (services.mastodon.database.createLocally == true) with peer authentication (services.mastodon.database.host == "/run/postgresql") to work services.mastodon.user and services.mastodon.database.user must be identical.'';
+
message = ''
+
For local automatic database provisioning (services.mastodon.database.createLocally == true) with peer
+
authentication (services.mastodon.database.host == "/run/postgresql") to work services.mastodon.user
+
and services.mastodon.database.user must be identical.
+
'';
+
}
+
{
+
assertion = !databaseActuallyCreateLocally -> (cfg.database.host != "/run/postgresql");
+
message = ''
+
<option>services.mastodon.database.host</option> needs to be set if
+
<option>services.mastodon.database.createLocally</option> is not enabled.
+
'';
}
{
assertion = cfg.smtp.authenticate -> (cfg.smtp.user != null);
···
OTP_SECRET="$(cat ${cfg.otpSecretFile})"
VAPID_PRIVATE_KEY="$(cat ${cfg.vapidPrivateKeyFile})"
VAPID_PUBLIC_KEY="$(cat ${cfg.vapidPublicKeyFile})"
+
'' + lib.optionalString (cfg.database.passwordFile != null) ''
DB_PASS="$(cat ${cfg.database.passwordFile})"
-
'' + (if cfg.smtp.authenticate then ''
+
'' + lib.optionalString cfg.smtp.authenticate ''
SMTP_PASSWORD="$(cat ${cfg.smtp.passwordFile})"
-
'' else "") + ''
+
'' + ''
EOF
'';
environment = env;
···
unset PGPASSFILE
'';
path = [ cfg.package pkgs.postgresql ];
-
environment = env // (if (!databaseActuallyCreateLocally)
-
then {
-
PGHOST = cfg.database.host;
-
PGUSER = cfg.database.user;
-
}
-
else {}
-
);
+
environment = env // lib.optionalAttrs (!databaseActuallyCreateLocally) {
+
PGHOST = cfg.database.host;
+
PGUSER = cfg.database.user;
+
};
serviceConfig = {
Type = "oneshot";
EnvironmentFile = [ "/var/lib/mastodon/.secrets_env" ];