summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIzorkin <izorkin@elven.pw>2022-03-22 22:21:47 +0300
committerIzorkin <izorkin@elven.pw>2022-12-16 16:19:39 +0300
commit8e14bf10c2a60f57b1bb10c74111fb8ecf811ba2 (patch)
tree4695381ee7ffebf3d50fd39d0b0d2547ddf4a719
parente2cebf2134ff2128b312bf018d450b1ba9b1f30b (diff)
nixos/mastodon: update database configuration
-rw-r--r--nixos/doc/manual/from_md/release-notes/rl-2305.section.xml17
-rw-r--r--nixos/doc/manual/release-notes/rl-2305.section.md4
-rw-r--r--nixos/modules/services/web-apps/mastodon.nix50
3 files changed, 54 insertions, 17 deletions
diff --git a/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml
index b73aa325bbf7..27c09f6629e7 100644
--- a/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml
+++ b/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml
@@ -146,6 +146,17 @@
</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.
@@ -210,6 +221,12 @@
</listitem>
<listitem>
<para>
+ <literal>mastodon</literal> now supports connection to a
+ remote <literal>PostgreSQL</literal> database.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
A new <literal>virtualisation.rosetta</literal> module was
added to allow running <literal>x86_64</literal> binaries
through
diff --git a/nixos/doc/manual/release-notes/rl-2305.section.md b/nixos/doc/manual/release-notes/rl-2305.section.md
index 84216758bad5..c9dfd0582c28 100644
--- a/nixos/doc/manual/release-notes/rl-2305.section.md
+++ b/nixos/doc/manual/release-notes/rl-2305.section.md
@@ -43,6 +43,8 @@ In addition to numerous new and upgraded packages, this release has the followin
- 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}
@@ -64,6 +66,8 @@ In addition to numerous new and upgraded packages, this release has the followin
- 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).
- Resilio sync secret keys can now be provided using a secrets file at runtime, preventing these secrets from ending up in the Nix store.
diff --git a/nixos/modules/services/web-apps/mastodon.nix b/nixos/modules/services/web-apps/mastodon.nix
index fcfaf3bb57c1..b6e2309555f2 100644
--- a/nixos/modules/services/web-apps/mastodon.nix
+++ b/nixos/modules/services/web-apps/mastodon.nix
@@ -1,7 +1,9 @@
-{ 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";
@@ -23,7 +25,6 @@ let
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;
@@ -37,7 +38,8 @@ let
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" ];
@@ -314,8 +316,13 @@ in {
};
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.";
};
@@ -333,8 +340,8 @@ in {
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`.
@@ -468,7 +475,18 @@ in {
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);
@@ -512,10 +530,11 @@ in {
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;
@@ -555,13 +574,10 @@ in {
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" ];