summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorRaito Bezarius2023-11-17 15:52:29 +0100
committerRaito Bezarius2023-11-17 15:53:08 +0100
commit10baca4935656089dabca0f07e3ef89f1f954375 (patch)
treeccdf0c34be571519b9b94797ec0a94838252f118 /nixos/modules
parentf653734c4dabbc041e7fcc72149f93567b10137c (diff)
nixos/invidious: do not use `ensureDBOwnership`
Invidious uses a strange setup where the database name is different from the system username
for non-explicit reasons.

Because of that, it makes it hard to migrate it to use `ensureDBOwnership`, we leave it to Invidious' maintainers
to pick up the pieces.
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/services/web-apps/invidious.nix9
1 files changed, 9 insertions, 0 deletions
diff --git a/nixos/modules/services/web-apps/invidious.nix b/nixos/modules/services/web-apps/invidious.nix
index fc9c1ec06f65..e4fbc6fd9368 100644
--- a/nixos/modules/services/web-apps/invidious.nix
+++ b/nixos/modules/services/web-apps/invidious.nix
@@ -109,8 +109,16 @@ let
     # Default to using the local database if we create it
     services.invidious.database.host = lib.mkDefault null;
 
+
+    # TODO(raitobezarius to maintainers of invidious): I strongly advise to clean up the kemal specific
+    # thing for 24.05 and use `ensureDBOwnership`.
+    # See https://github.com/NixOS/nixpkgs/issues/216989
+    systemd.services.postgresql.postStart = lib.mkAfter ''
+      $PSQL -tAc 'ALTER DATABASE "${cfg.settings.db.dbname}" OWNER TO "${cfg.settings.db.user}";'
+    '';
     services.postgresql = {
       enable = true;
+      ensureUsers = lib.singleton { name = cfg.settings.db.user; ensureDBOwnership = false; };
       ensureDatabases = lib.singleton cfg.settings.db.dbname;
       # This is only needed because the unix user invidious isn't the same as
       # the database user. This tells postgres to map one to the other.
@@ -130,6 +138,7 @@ let
       documentation = [ "https://docs.invidious.io/Database-Information-and-Maintenance.md" ];
       startAt = lib.mkDefault "weekly";
       path = [ config.services.postgresql.package ];
+      after = [ "postgresql.service" ];
       script = ''
         psql ${cfg.settings.db.dbname} ${cfg.settings.db.user} -c "DELETE FROM nonces * WHERE expire < current_timestamp"
         psql ${cfg.settings.db.dbname} ${cfg.settings.db.user} -c "TRUNCATE TABLE videos"