summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIzorkin <izorkin@elven.pw>2021-02-15 18:44:38 +0300
committerIzorkin <izorkin@elven.pw>2022-12-16 16:14:39 +0300
commite2cebf2134ff2128b312bf018d450b1ba9b1f30b (patch)
treeba8dd8294d4c4be3014184dbf3e0bbd7f80c4806
parentfbcb61bd7eb19914cbd88789c3586a63ff46b72b (diff)
nixos/mastodon: fix init db on remote postgresql
-rw-r--r--nixos/modules/services/web-apps/mastodon.nix22
1 files changed, 20 insertions, 2 deletions
diff --git a/nixos/modules/services/web-apps/mastodon.nix b/nixos/modules/services/web-apps/mastodon.nix
index a6cd7432db24..fcfaf3bb57c1 100644
--- a/nixos/modules/services/web-apps/mastodon.nix
+++ b/nixos/modules/services/web-apps/mastodon.nix
@@ -530,7 +530,16 @@ in {
};
systemd.services.mastodon-init-db = lib.mkIf cfg.automaticMigrations {
- script = ''
+ script = lib.optionalString (!databaseActuallyCreateLocally) ''
+ umask 077
+
+ export PGPASSFILE
+ PGPASSFILE=$(mktemp)
+ cat > $PGPASSFILE <<EOF
+ ${cfg.database.host}:${toString cfg.database.port}:${cfg.database.name}:${cfg.database.user}:$(cat ${cfg.database.passwordFile})
+ EOF
+
+ '' + ''
if [ `psql ${cfg.database.name} -c \
"select count(*) from pg_class c \
join pg_namespace s on s.oid = c.relnamespace \
@@ -541,9 +550,18 @@ in {
else
rails db:migrate
fi
+ '' + lib.optionalString (!databaseActuallyCreateLocally) ''
+ rm $PGPASSFILE
+ unset PGPASSFILE
'';
path = [ cfg.package pkgs.postgresql ];
- environment = env;
+ environment = env // (if (!databaseActuallyCreateLocally)
+ then {
+ PGHOST = cfg.database.host;
+ PGUSER = cfg.database.user;
+ }
+ else {}
+ );
serviceConfig = {
Type = "oneshot";
EnvironmentFile = [ "/var/lib/mastodon/.secrets_env" ];