Compare commits

...

10 Commits

Author SHA1 Message Date
371b6409b4 WIP
All checks were successful
Eval nix flake / evals (push) Successful in 9m11s
2026-01-30 04:14:30 +09:00
0131e5af6d temmie: combine homedirs in overlayfs 2026-01-30 04:00:17 +09:00
af0bf7b254 bicep/{postgres,mysql}: fix old backup deletion
All checks were successful
Build topology graph / evals (push) Successful in 3m22s
Eval nix flake / evals (push) Successful in 9m8s
2026-01-29 14:57:46 +09:00
bcf8b1607f bicep/{postgres,mysql}: use hardlink for latest backup file
Some checks failed
Build topology graph / evals (push) Successful in 3m22s
Eval nix flake / evals (push) Has been cancelled
2026-01-29 14:53:07 +09:00
1d46fd1ec6 bicep/{postgres,mysql}: keep multiple backups, point at latest with symlink
All checks were successful
Build topology graph / evals (push) Successful in 5m22s
Eval nix flake / evals (push) Successful in 9m18s
2026-01-29 14:16:34 +09:00
bac53be707 bicep/{postgres,mysql}: use zstd for backup compression
All checks were successful
Build topology graph / evals (push) Successful in 5m13s
Eval nix flake / evals (push) Successful in 9m25s
2026-01-29 13:50:35 +09:00
f08bd96b74 bicep/{postgres,mysql}: move backups to /data
All checks were successful
Build topology graph / evals (push) Successful in 3m22s
Eval nix flake / evals (push) Successful in 9m13s
2026-01-29 13:41:06 +09:00
25f2a13391 packages/mediawiki-extensions: bump all
Some checks failed
Build topology graph / evals (push) Successful in 3m25s
Eval nix flake / evals (push) Has been cancelled
2026-01-29 13:34:42 +09:00
8774c81d23 bicep/{postgres,mysql}: custom backup units
Some checks failed
Build topology graph / evals (push) Has been cancelled
Eval nix flake / evals (push) Has been cancelled
2026-01-29 13:32:28 +09:00
d6eca5c4e3 bicep/{postgres,mysql}: split config into several files
All checks were successful
Build topology graph / evals (push) Successful in 5m27s
Eval nix flake / evals (push) Successful in 7m57s
2026-01-29 13:18:25 +09:00
8 changed files with 290 additions and 113 deletions

View File

@@ -9,8 +9,8 @@
./services/calendar-bot.nix
#./services/git-mirrors
./services/minecraft-heatmap.nix
./services/mysql.nix
./services/postgres.nix
./services/mysql
./services/postgresql
./services/matrix
];

View File

@@ -0,0 +1,82 @@
{ config, lib, pkgs, ... }:
let
cfg = config.services.mysql;
backupDir = "/data/mysql-backups";
in
{
# services.mysqlBackup = lib.mkIf cfg.enable {
# enable = true;
# location = "/var/lib/mysql-backups";
# };
systemd.tmpfiles.settings."10-mysql-backups".${backupDir}.d = {
user = "mysql";
group = "mysql";
mode = "700";
};
services.rsync-pull-targets = lib.mkIf cfg.enable {
enable = true;
locations.${backupDir} = {
user = "root";
rrsyncArgs.ro = true;
authorizedKeysAttrs = [
"restrict"
"no-agent-forwarding"
"no-port-forwarding"
"no-pty"
"no-X11-forwarding"
];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJgj55/7Cnj4cYMJ5sIkl+OwcGeBe039kXJTOf2wvo9j mysql rsync backup";
};
};
# NOTE: instead of having the upstream nixpkgs postgres backup unit trigger
# another unit, it was easier to just make one ourselves.
systemd.services."backup-mysql" = lib.mkIf cfg.enable {
description = "Backup MySQL data";
requires = [ "mysql.service" ];
path = with pkgs; [
cfg.package
coreutils
zstd
];
script = let
rotations = 2;
in ''
set -euo pipefail
OUT_FILE="$STATE_DIRECTORY/mysql-dump-$(date --iso-8601).sql.zst"
mysqldump --all-databases | zstd --compress -9 --rsyncable -o "$OUT_FILE"
# NOTE: this needs to be a hardlink for rrsync to allow sending it
rm "$STATE_DIRECTORY/mysql-dump-latest.sql.zst" ||:
ln -T "$OUT_FILE" "$STATE_DIRECTORY/mysql-dump-latest.sql.zst"
while [ $(find -type f -printf '.' "$STATE_DIRECTORY" | wc -c) -gt ${toString (rotations + 1)} ]; do
rm $(find "$STATE_DIRECTORY" -type f -printf '%T+ %p\n' | sort | head -n 1 | cut -d' ' -f2)
done
'';
serviceConfig = {
Type = "oneshot";
User = "mysql";
Group = "mysql";
UMask = "0077";
Nice = 19;
IOSchedulingClass = "best-effort";
IOSchedulingPriority = 7;
StateDirectory = [ "mysql-backups" ];
BindPaths = [ "${backupDir}:/var/lib/mysql-backups" ];
# TODO: hardening
};
startAt = "*-*-* 02:15:00";
};
}

View File

@@ -4,6 +4,8 @@ let
dataDir = "/data/mysql";
in
{
imports = [ ./backup.nix ];
sops.secrets."mysql/password" = {
owner = "mysql";
group = "mysql";
@@ -42,27 +44,6 @@ in
}];
};
services.mysqlBackup = lib.mkIf cfg.enable {
enable = true;
location = "/var/lib/mysql-backups";
};
services.rsync-pull-targets = lib.mkIf cfg.enable {
enable = true;
locations.${config.services.mysqlBackup.location} = {
user = "root";
rrsyncArgs.ro = true;
authorizedKeysAttrs = [
"restrict"
"no-agent-forwarding"
"no-port-forwarding"
"no-pty"
"no-X11-forwarding"
];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJgj55/7Cnj4cYMJ5sIkl+OwcGeBe039kXJTOf2wvo9j mysql rsync backup";
};
};
networking.firewall.allowedTCPPorts = lib.mkIf cfg.enable [ 3306 ];
systemd.tmpfiles.settings."10-mysql".${dataDir}.d = lib.mkIf cfg.enable {

View File

@@ -0,0 +1,83 @@
{ config, lib, pkgs, ... }:
let
cfg = config.services.postgresql;
backupDir = "/data/postgresql-backups";
in
{
# services.postgresqlBackup = lib.mkIf cfg.enable {
# enable = true;
# location = "/var/lib/postgresql-backups";
# backupAll = true;
# };
systemd.tmpfiles.settings."10-postgresql-backups".${backupDir}.d = {
user = "postgres";
group = "postgres";
mode = "700";
};
services.rsync-pull-targets = lib.mkIf cfg.enable {
enable = true;
locations.${backupDir} = {
user = "root";
rrsyncArgs.ro = true;
authorizedKeysAttrs = [
"restrict"
"no-agent-forwarding"
"no-port-forwarding"
"no-pty"
"no-X11-forwarding"
];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGvO7QX7QmwSiGLXEsaxPIOpAqnJP3M+qqQRe5dzf8gJ postgresql rsync backup";
};
};
# NOTE: instead of having the upstream nixpkgs postgres backup unit trigger
# another unit, it was easier to just make one ourselves
systemd.services."backup-postgresql" = {
description = "Backup PostgreSQL data";
requires = [ "postgresql.service" ];
path = with pkgs; [
coreutils
zstd
cfg.package
];
script = let
rotations = 2;
in ''
set -euo pipefail
OUT_FILE="$STATE_DIRECTORY/postgresql-dump-$(date --iso-8601).sql.zst"
pg_dumpall -U postgres | zstd --compress -9 --rsyncable -o "$OUT_FILE"
# NOTE: this needs to be a hardlink for rrsync to allow sending it
rm "$STATE_DIRECTORY/postgresql-dump-latest.sql.zst" ||:
ln -T "$OUT_FILE" "$STATE_DIRECTORY/postgresql-dump-latest.sql.zst"
while [ $(find -type f -printf '.' "$STATE_DIRECTORY" | wc -c) -gt ${toString (rotations + 1)} ]; do
rm $(find "$STATE_DIRECTORY" -type f -printf '%T+ %p\n' | sort | head -n 1 | cut -d' ' -f2)
done
'';
serviceConfig = {
Type = "oneshot";
User = "postgres";
Group = "postgres";
UMask = "0077";
Nice = 19;
IOSchedulingClass = "best-effort";
IOSchedulingPriority = 7;
StateDirectory = [ "postgresql-backups" ];
BindPaths = [ "${backupDir}:/var/lib/postgresql-backups" ];
# TODO: hardening
};
startAt = "*-*-* 01:15:00";
};
}

View File

@@ -3,6 +3,8 @@ let
cfg = config.services.postgresql;
in
{
imports = [ ./backup.nix ];
services.postgresql = {
enable = true;
package = pkgs.postgresql_18;
@@ -121,26 +123,4 @@ in
networking.firewall.allowedTCPPorts = lib.mkIf cfg.enable [ 5432 ];
networking.firewall.allowedUDPPorts = lib.mkIf cfg.enable [ 5432 ];
services.postgresqlBackup = lib.mkIf cfg.enable {
enable = true;
location = "/var/lib/postgres-backups";
backupAll = true;
};
services.rsync-pull-targets = lib.mkIf cfg.enable {
enable = true;
locations.${config.services.postgresqlBackup.location} = {
user = "root";
rrsyncArgs.ro = true;
authorizedKeysAttrs = [
"restrict"
"no-agent-forwarding"
"no-port-forwarding"
"no-pty"
"no-X11-forwarding"
];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGvO7QX7QmwSiGLXEsaxPIOpAqnJP3M+qqQRe5dzf8gJ postgresql rsync backup";
};
};
}

View File

@@ -1,60 +1,76 @@
{ lib, values, ... }:
let
# See microbel:/etc/exports
letters = [ "a" "b" "c" "d" "h" "i" "j" "k" "l" "m" "z" ];
letters = [ "a" "b" "c" "d" "h" "i" "j" "k" "l" "m" "z" ];
in
{
systemd.targets."pvv-homedirs" = {
description = "PVV Homedir Partitions";
};
systemd.mounts = map (l: {
description = "PVV Homedir Partition ${l}";
systemd.mounts =
(map (l: {
description = "PVV Homedir Partition ${l}";
before = [ "remote-fs.target" ];
wantedBy = [ "multi-user.target" ];
requiredBy = [ "pvv-homedirs.target" ];
before = [ "remote-fs.target" ];
wantedBy = [ "multi-user.target" ];
requiredBy = [ "pvv-homedirs.target" ];
type = "nfs";
what = "homepvv${l}.pvv.ntnu.no:/export/home/pvv/${l}";
where = "/run/pvv-home-mounts/${l}";
type = "nfs";
what = "homepvv${l}.pvv.ntnu.no:/export/home/pvv/${l}";
where = "/run/pvv-home-mounts/${l}";
options = lib.concatStringsSep "," [
"nfsvers=3"
options = lib.concatStringsSep "," [
"nfsvers=3"
# NOTE: this is a bit unfortunate. The address above seems to resolve to IPv6 sometimes,
# and it doesn't seem possible to specify proto=tcp,tcp6, meaning we have to tell
# NFS which exact address to use here, despite it being specified in the `what` attr :\
"proto=tcp"
"addr=${values.hosts.microbel.ipv4}"
"mountproto=tcp"
"mounthost=${values.hosts.microbel.ipv4}"
"port=2049"
# NOTE: this is a bit unfortunate. The address above seems to resolve to IPv6 sometimes,
# and it doesn't seem possible to specify proto=tcp,tcp6, meaning we have to tell
# NFS which exact address to use here, despite it being specified in the `what` attr :\
"proto=tcp"
"addr=${values.hosts.microbel.ipv4}"
"mountproto=tcp"
"mounthost=${values.hosts.microbel.ipv4}"
"port=2049"
# NOTE: this is yet more unfortunate. When enabling locking, it will sometimes complain about connection failed.
# dmesg(1) reveals that it has something to do with registering the lockdv1 RPC service (errno: 111), not
# quite sure how to fix it. Living life on dangerous mode for now.
"nolock"
# NOTE: this is yet more unfortunate. When enabling locking, it will sometimes complain about connection failed.
# dmesg(1) reveals that it has something to do with registering the lockdv1 RPC service (errno: 111), not
# quite sure how to fix it. Living life on dangerous mode for now.
"nolock"
# Don't wait on every read/write
"async"
# Don't wait on every read/write
"async"
# Always keep mounted
"noauto"
# Always keep mounted
"noauto"
# We don't want to update access time constantly
"noatime"
# We don't want to update access time constantly
"noatime"
# No SUID/SGID, no special devices
"nosuid"
"nodev"
# No SUID/SGID, no special devices
"nosuid"
"nodev"
# TODO: are there cgi scripts that modify stuff in peoples homedirs?
# "ro"
"rw"
# TODO: are there cgi scripts that modify stuff in peoples homedirs?
# "ro"
"rw"
# TODO: can we enable this and still run cgi stuff?
# "noexec"
];
}) letters;
# TODO: can we enable this and still run cgi stuff?
# "noexec"
];
}) letters)
++ [{
description = "PVV Merged Homedir OverlayFS";
after = [ "remote-fs.target" ];
wantedBy = [ "multi-user.target" ];
requiredBy = [ "pvv-homedirs.target" ];
type = "overlay";
what = "overlay";
where = "/run/pvv-home-mounts-merged";
options = lib.concatStringsSep "," [
"lowerdir=${lib.concatMapStringsSep ":" (l: "/run/pvv-home-mounts/${l}") letters}"
];
}];
}

View File

@@ -1,18 +1,51 @@
{ ... }:
{ config, lib, pkgs, ... }:
let
cfg = config.services.httpd;
in
{
services.httpd = {
enable = true;
adminAddr = "drift@pvv.ntnu.no";
# extraModules = [];
enablePHP = true;
phpPackage = pkgs.php.buildEnv {
extraConfig = ''
display_errors=0
post_max_size = 40M
upload_max_filesize = 40M
extension=sysvsem.so
'';
};
# enablePerl = true;
extraModules = [ "userdir" ];
# virtualHosts."userweb.pvv.ntnu.no" = {
virtualHosts."temmie.pvv.ntnu.no" = {
forceSSL = true;
enableACME = true;
extraConfig = ''
UserDir /home/pvv-merged/*/web-docs
UserDir disabled root
UserDir enabled oysteikt
AddHandler cgi-script .cgi
<Directory "/home/pvv-merged/*/web-docs">
Options MultiViews Indexes SymLinksIfOwnerMatch ExecCGI IncludesNoExec
AllowOverride All
Require all granted
</Directory>
'';
};
};
networking.firewall.allowedTCPPorts = [
80
443
];
systemd.services.httpd = {
after = [ "pvv-homedirs.target" ];
requires = [ "pvv-homedirs.target" ];
@@ -20,8 +53,10 @@
serviceConfig = {
ProtectHome = "tmpfs";
BindPaths = let
letters = [ "a" "b" "c" "d" "h" "i" "j" "k" "l" "m" "z" ];
in map (l: "/run/pvv-home-mounts/${l}:/home/pvv/${l}") letters;
homeLetters = [ "a" "b" "c" "d" "h" "i" "j" "k" "l" "m" "z" ];
in (map (l: "/run/pvv-home-mounts/${l}:/home/pvv/${l}") homeLetters) ++ [
"/run/pvv-home-mounts-merged:/home/pvv-merged/"
];
};
};

View File

@@ -33,63 +33,63 @@ in
lib.mergeAttrsList [
(mw-ext {
name = "CodeEditor";
commit = "6e5b06e8cf2d040c0abb53ac3735f9f3c96a7a4f";
hash = "sha256-Jee+Ws9REUohywhbuemixXKaTRc54+cIlyUNDCyYcEM=";
commit = "83e1d0c13f34746f0d7049e38b00e9ab0a47c23f";
hash = "sha256-qH9fSQZGA+z6tBSh1DaTKLcujqA6K/vQmZML9w5X8mU=";
})
(mw-ext {
name = "CodeMirror";
commit = "da9c5d4f03e6425f6f2cf68b75d21311e0f7e77e";
hash = "sha256-aL+v9xeqKHGmQVUWVczh54BkReu+fP49PT1NP7eTC6k=";
commit = "af2b08b9ad2b89a64b2626cf80b026c5b45e9922";
hash = "sha256-CxXPwCKUlF9Tg4JhwLaKQyvt43owq75jCugVtb3VX+I=";
})
(mw-ext {
name = "DeleteBatch";
commit = "122072bbfb4eab96ed8c1451a3e74b5557054c58";
hash = "sha256-L6AXoyFJEZoAQpLO6knJvYtQ6JJPMtaa+WhpnwbJeNU=";
commit = "3d6f2fd0e3efdae1087dd0cc8b1f96fe0edf734f";
hash = "sha256-iD9EjDIW7AGpZan74SIRcr54dV8W7xMKIDjatjdVkKs=";
})
(mw-ext {
name = "PluggableAuth";
commit = "5caf605b9dfdd482cb439d1ba2000cba37f8b018";
hash = "sha256-TYJqR9ZvaWJ7i1t0XfgUS05qqqCgxAH8tRTklz/Bmlg=";
commit = "85e96acd1ac0ebcdaa29c20eae721767a938f426";
hash = "sha256-bMVhrg8FsfWhXF605Cj5TgI0A6Jy/MIQ5aaUcLQQ0Ss=";
})
(mw-ext {
name = "Popups";
commit = "7ed940a09f83f869cbc0bc20f3ca92f85b534951";
hash = "sha256-pcDPcu4kSvMHfSOuShrod694TKI9Oo3AEpMP9DXp9oY=";
commit = "410e2343c32a7b18dcdc2bbd995b0bfdf3bf5f37";
hash = "sha256-u2AlR75x54rCpiK9Mz00D9odJCn8fmi6DRU4QKmKqSc=";
})
(mw-ext {
name = "Scribunto";
commit = "e755852a8e28a030a21ded2d5dd7270eb933b683";
hash = "sha256-zyI5nSE+KuodJOWyV0CQM7G0GfkKEgfoF/czi2/qk98=";
commit = "904f323f343dba5ff6a6cdd143c4a8ef5b7d2c55";
hash = "sha256-ZOVYhjMMyWbqwZOBb39hMIRmzzCPEnz2y8Q2jgyeERw=";
})
(mw-ext {
name = "SimpleSAMLphp";
kebab-name = "simple-saml-php";
commit = "d41b4efd3cc44ca3f9f12e35385fc64337873c2a";
hash = "sha256-wfzXtsEEEjQlW5QE4Rf8pasAW/KSJsLkrez13baxeqA=";
commit = "a2f77374713473d594e368de24539aebcc1a800a";
hash = "sha256-5+t3VQFKcrIffDNPJ4RWBIWS6K1gTOcEleYWmM6xWms=";
})
(mw-ext {
name = "TemplateData";
commit = "fd7cf4d95a70ef564130266f2a6b18f33a2a2ff9";
hash = "sha256-5OhDPFhIi55Eh5+ovMP1QTjNBb9Sm/3vyArNCApAgSw=";
commit = "76a6a04bd13a606923847ba68750b5d98372cacd";
hash = "sha256-X2+U5PMqzkSljw2ypIvJUSaPDaonTkQx89OgKzf5scw=";
})
(mw-ext {
name = "TemplateStyles";
commit = "0f7b94a0b094edee1c2a9063a3c42a1bdc0282d9";
hash = "sha256-R406FgNcIip9St1hurtZoPPykRQXBrkJRKA9hapG81I=";
commit = "7de60a8da6576d7930f293d19ef83529abf52704";
hash = "sha256-iPmFDoO5V4964CVyd1mBSQcNlW34odbvpm2CfDBlPBU=";
})
(mw-ext {
name = "UserMerge";
commit = "d1917817dd287e7d883e879459d2d2d7bc6966f2";
hash = "sha256-la3/AQ38DMsrZ2f24T/z3yKzIrbyi3w6FIB5YfxGK9U=";
commit = "71eb53ff4289ac4efaa31685ab8b6483c165a584";
hash = "sha256-OfKSEPgctfr659oh5jf99T0Rzqn+60JhNaZq+2gfubk=";
})
(mw-ext {
name = "VisualEditor";
commit = "032364cfdff33818e6ae0dfa251fe3973b0ae4f3";
hash = "sha256-AQDdq9r6rSo8h4u1ERonH14/1i1BgLGdzANEiQ065PU=";
commit = "a6a63f53605c4d596c3df1dcc2583ffd3eb8d929";
hash = "sha256-4d8picO66uzKoxh1TdyvKLHebc6ZL7N2DdXLV2vgBL4=";
})
(mw-ext {
name = "WikiEditor";
commit = "cb9f7e06a9c59b6d3b31c653e5886b7f53583d01";
hash = "sha256-UWi3Ac+LCOLliLkXnS8YL0rD/HguuPH5MseqOm0z7s4=";
commit = "0a5719bb95326123dd0fee1f88658358321ed7be";
hash = "sha256-eQMyjhdm1E6TkktIHad1NMeMo8QNoO8z4A05FYOMCwQ=";
})
]