{ pkgs, ... }:
let
  globals = import ../../config/globals.nix ;
in {
  systemd.services.wiki-js = {
   requires = [ "postgresql.service" ];
   after    = [ "postgresql.service" ];
 };
 services.wiki-js = {
   enable = true;
   settings = {
     db = {
       db  = "wiki-js";
       host = "/run/postgresql";
       type = "postgres";
       user = "wiki-js";
     };
     port = 3002 ;
    };
 };
 services.postgresql = {
   enable = true;
   ensureDatabases = [ "wiki-js" ];
   ensureUsers = [{
     name = "wiki-js";
     ensureDBOwnership = true;
   }];
 };

 services.caddy.virtualHosts.${globals.services.wikijs.url}.extraConfig = ''
    reverse_proxy localhost:${toString globals.services.wikijs.port}
 '';
}
