Install privatebin, a pastebin alternative
diff --git a/modules/caddy/caddyfile.nix b/modules/caddy/caddyfile.nix
index f3c8b20..69fbe2b 100644
--- a/modules/caddy/caddyfile.nix
+++ b/modules/caddy/caddyfile.nix
@@ -18,6 +18,80 @@
     match = [{ host = hosts; }];
     terminal = true;
   };
+  PHPRoute = hosts: root: socket: {
+    handle = [
+      {
+        handler = "subroute";
+        routes = [
+          {
+            handle = [
+              {
+                handler = "vars";
+                inherit root;
+              }
+            ];
+          }
+          {
+            handle = [
+              {
+                handler = "static_response";
+                headers.Location = [ "{http.request.orig_uri.path}/" ];
+                status_code = 307;
+              }
+            ];
+            match = [
+              {
+                file.try_files = [ "{http.request.uri.path}/index.php" ];
+                not = [ { path = ["*/"]; } ];
+              }
+            ];
+          }
+          {
+            handle = [
+              {
+                handler = "rewrite";
+                uri = "{http.matchers.file.relative}";
+              }
+            ];
+            match = [
+              {
+                file = {
+                  split_path = [ ".php" ];
+                  try_files = [
+                    "{http.request.uri.path}"
+                    "{http.request.uri.path}/index.php"
+                    "index.php"
+                  ];
+                };
+              }
+            ];
+          }
+          {
+            handle = [
+              {
+                handler = "reverse_proxy";
+                transport = {
+                  protocol = "fastcgi";
+                  split_path = [".php"];
+                };
+                upstreams = [{ dial = socket; }];
+              }
+            ];
+            match = [{ path = ["*.php"]; }];
+          }
+          {
+            handle = [
+              {
+                handler = "file_server";
+              }
+            ];
+          }
+        ];
+      }
+    ];
+    match = [{ host = hosts; }];
+    terminal = true;
+  };
   HTTPRedirectRoute = hosts: goto: {
     handle = [
       {
@@ -286,6 +360,11 @@
             "syncthing.thecoded.prof"
             "syncthing.hopescaramels.com"
           ] [ "localhost:8384" ])
+          (PHPRoute
+            [ "paste.clicks.codes" "paste.coded.codes" ]
+            "${pkgs.privatebin}/share/privatebin"
+            "unix/${config.services.phpfpm.pools.privatebin.socket}"
+          )
         ];
       };
       srv1 = {
diff --git a/modules/postgres.nix b/modules/postgres.nix
index 8f6c5f1..7a5074a 100644
--- a/modules/postgres.nix
+++ b/modules/postgres.nix
@@ -12,6 +12,7 @@
 
     ensureDatabases = [
       "vaultwarden"
+      "privatebin"
     ];
 
     ensureUsers = [
@@ -34,6 +35,12 @@
           "DATABASE vaultwarden" = "ALL PRIVILEGES";
         };
       }
+      {
+        name = "privatebin";
+        ensurePermissions = {
+          "DATABASE privatebin" = "ALL PRIVILEGES";
+        };
+      }
     ] ++ (map
       (name: (
         {
@@ -66,6 +73,7 @@
     (lib.mkAfter (lib.pipe [
       { user = "clicks_grafana"; passwordFile = config.sops.secrets.clicks_grafana_db_password.path; }
       { user = "vaultwarden"; passwordFile = config.sops.secrets.clicks_bitwarden_db_password.path; }
+      { user = "privatebin"; passwordFile = config.sops.secrets.clicks_privatebin_db_password.path; }
     ] [
       (map (userData: ''
         $PSQL -tAc "ALTER USER ${userData.user} PASSWORD '$(cat ${userData.passwordFile})';"
@@ -77,6 +85,7 @@
   sops.secrets = lib.pipe [
     "clicks_grafana_db_password"
     "clicks_bitwarden_db_password"
+    "clicks_privatebin_db_password"
   ] [
     (map (name: {
       inherit name;
diff --git a/modules/privatebin.nix b/modules/privatebin.nix
new file mode 100644
index 0000000..5dd6a28
--- /dev/null
+++ b/modules/privatebin.nix
@@ -0,0 +1,73 @@
+{ config, lib, base, ... }:
+lib.recursiveUpdate
+{
+  services.nginx.enable = false; # PrivateBin attempts to enable nginx but we already use caddy
+  services.privatebin = {
+    enable = true;
+    settings = {
+      main = {
+        name = "Clicks Minute Paste";
+        basepath = "https://paste.clicks.codes/";
+        opendiscussion = true;
+        fileupload = true;
+
+        defaultformatter = "syntaxhighlighting";
+        syntaxhighlightingtheme = "sons-of-obsidian";
+        template = "bootstrap-dark";
+
+        info = ''Powered by <a href="https://privatebin.info/">PrivateBin</a>. Provided as a service free-of-charge by Clicks. Come chat with us <a href="https://matrix.to/#/#global:coded.codes"> on Matrix</a>'';
+        notice = "This service has no guarantee of uptime, and pastes are not backed up. If you need somewhere to host the last words of your wise old grandfather for time immemorial this is not the place.";
+        
+        langaugeselection = true;
+      };
+
+      expire.default = "1month";
+
+      expire_options = {
+        "5min" = 300; # looks bonkers, but I'm trying to keep the list ordered while also keeping the privatebin label formatter happy
+        "10min" = 600;
+        "1hour" = 3600;
+        "1day" = 86400;
+        "1week" = 604800;
+        "1month" = 2592000;
+      };
+
+      formatter_options = {
+        syntaxhighlighting = "Source Code";
+        markdown = "Markdown";
+        plaintext = "Plain Text";
+      };
+
+      traffic = {
+        exempted = "10.0.0.0/8,127.0.0.0/8,169.254.0.0/16,172.16.0.0/12,192.168.0.0/16";
+      };
+
+      model.class = "Database";
+      model_options = {
+        dsn = "pgsql:host=localhost;dbname=privatebin";
+        tbl = "privatebin";
+        usr = "privatebin";
+        pwd._env = "PRIVATEBIN_DB_PASSWORD";
+      };
+    };
+  };
+}
+(
+  if base != null
+    then {
+      services.privatebin.environmentFiles = [
+        config.scalpel.trafos."privatebin.env".destination
+      ];
+
+      scalpel.trafos."privatebin.env" = {
+        source = builtins.toFile "privatebin.env" ''
+          PRIVATEBIN_DB_PASSWORD=!!privatebin_db_password!!
+        '';
+        matchers."privatebin_db_password".secret =
+          config.sops.secrets.clicks_privatebin_db_password.path;
+        owner = config.users.users.privatebin.name;
+        group = config.users.users.privatebin.group;
+        mode = "0400";
+      };
+    }
+    else {})