about summary refs log tree commit diff
path: root/wikiwiki.nix
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2023-11-04 05:02:17 +0900
committerNguyễn Gia Phong <cnx@loang.net>2023-11-04 05:08:35 +0900
commit5db4d7b2c9c315a7f996a5c103ca9e62b8830862 (patch)
treef3093906a00db3c4da607586f28ab710787fb7ba /wikiwiki.nix
parent5f1653842dd91fbeff94472f6e3848f12492fd9f (diff)
downloadnixos-conf-5db4d7b2c9c315a7f996a5c103ca9e62b8830862.tar.gz
Backup wiki research
Diffstat (limited to 'wikiwiki.nix')
-rw-r--r--wikiwiki.nix57
1 files changed, 56 insertions, 1 deletions
diff --git a/wikiwiki.nix b/wikiwiki.nix
index aa24e01..db53a8a 100644
--- a/wikiwiki.nix
+++ b/wikiwiki.nix
@@ -16,7 +16,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with loang configuration.  If not, see <https://www.gnu.org/licenses/>.
 
-{ config, lib, ... }:
+{ config, lib, pkgs, ... }:
 let hostname = "nhanh.${config.networking.domain}";
 in {
   services = {
@@ -33,10 +33,15 @@ in {
         $wgGroupPermissions['*']['read'] = false;
         $wgGroupPermissions['*']['edit'] = false;
         $wgGroupPermissions['*']['createaccount'] = false;
+        $wgLogos = [
+          'svg' => "https://upload.wikimedia.org/wikipedia/commons/e/e1/Wiki_research_logo.svg",
+        ];
+        $wgFileExtensions = array_merge($wgFileExtensions, [ 'pdf' ]);
       '';
       name = "Research on Wikipedia governance";
       nginx.hostName = hostname;
       passwordFile = "/dev/null"; # this is so dumb
+      uploadsDir = "/mnt/nas/www/nhanh.loang.net";
       webserver = "nginx";
     };
 
@@ -60,5 +65,55 @@ in {
         "~ ^/w/(skins|extensions)/.+\\.(css|js|gif|jpg|jpeg|png|svg|wasm|ttf|woff|woff2)$" = rewrite;
       };
     };
+
+    phpfpm.pools.mediawiki.phpOptions = ''
+      post_max_size = 100M
+      upload_max_filesize = 100M
+    '';
+
+    postgresqlBackup.databases = [ "mediawiki" ];
   };
+
+  systemd = let
+    service = user: script: {
+      inherit script;
+      serviceConfig  = {
+        Type = "oneshot";
+        User = user;
+      };
+    };
+    timer = unit: {
+      wantedBy = [ "timers.target" ];
+      timerConfig = {
+        OnBootSec = "1d";
+        OnUnitActiveSec = "1d";
+        Unit = "${unit}.service";
+      };
+    };
+  in {
+    services = {
+      "wiki-db-backup" = service "postgres" ''
+        today=$(${pkgs.coreutils}/bin/date --iso-8601)
+        backup=/mnt/nas/backup/nhanh.loang.net/$today.sql.zstd
+        ${pkgs.coreutils}/bin/install -g mediawiki -m 640\
+          /mnt/nas/backup/postgresql/mediawiki.sql.zstd $backup
+      '';
+      "wiki-uploads-backup" = service "mediawiki" ''
+        backup=/mnt/nas/backup/nhanh.loang.net
+        ${pkgs.rsync}/bin/rsync -a --delete\
+          /mnt/nas/www/nhanh.loang.net/ $backup/latest/
+        today=$(${pkgs.coreutils}/bin/date --iso-8601)
+        ${pkgs.coreutils}/bin/cp -al $backup/{latest,$today}
+      '';
+    };
+    timers = {
+      "wiki-db-backup" = timer "wiki-uploads-backup";
+      "wiki-uploads-backup" = timer "wiki-uploads-backup";
+    };
+  };
+
+  users.groups.mediawiki.members = [
+    "mediawiki" "nginx" "postgres"
+    "ooze" "cnx"
+  ];
 }