diff options
author | Izorkin <izorkin@elven.pw> | 2021-02-15 18:44:38 +0300 |
---|---|---|
committer | Izorkin <izorkin@elven.pw> | 2022-12-16 16:14:39 +0300 |
commit | e2cebf2134ff2128b312bf018d450b1ba9b1f30b (patch) | |
tree | ba8dd8294d4c4be3014184dbf3e0bbd7f80c4806 /nixos/modules/services | |
parent | fbcb61bd7eb19914cbd88789c3586a63ff46b72b (diff) | |
download | nixpkgs-e2cebf2134ff2128b312bf018d450b1ba9b1f30b.tar nixpkgs-e2cebf2134ff2128b312bf018d450b1ba9b1f30b.tar.gz nixpkgs-e2cebf2134ff2128b312bf018d450b1ba9b1f30b.tar.bz2 nixpkgs-e2cebf2134ff2128b312bf018d450b1ba9b1f30b.tar.lz nixpkgs-e2cebf2134ff2128b312bf018d450b1ba9b1f30b.tar.xz nixpkgs-e2cebf2134ff2128b312bf018d450b1ba9b1f30b.tar.zst nixpkgs-e2cebf2134ff2128b312bf018d450b1ba9b1f30b.zip |
nixos/mastodon: fix init db on remote postgresql
Diffstat (limited to 'nixos/modules/services')
-rw-r--r-- | nixos/modules/services/web-apps/mastodon.nix | 22 |
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 a6cd7432db2..fcfaf3bb57c 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" ]; |