mirror of
https://git.pvv.ntnu.no/Drift/pvv-nixos-config.git
synced 2026-08-11 05:42:33 +02:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d25d0f8b56 | ||
|
|
4525de1d10 |
@@ -197,7 +197,6 @@
|
|||||||
inputs.pvv-calendar-bot.nixosModules.default
|
inputs.pvv-calendar-bot.nixosModules.default
|
||||||
inputs.minecraft-heatmap.nixosModules.default
|
inputs.minecraft-heatmap.nixosModules.default
|
||||||
self.nixosModules.gickup
|
self.nixosModules.gickup
|
||||||
self.nixosModules.hugepages
|
|
||||||
self.nixosModules.matrix-ooye
|
self.nixosModules.matrix-ooye
|
||||||
];
|
];
|
||||||
overlays = [
|
overlays = [
|
||||||
@@ -310,7 +309,6 @@
|
|||||||
bluemap = ./modules/bluemap.nix;
|
bluemap = ./modules/bluemap.nix;
|
||||||
drumknotty = ./modules/drumknotty;
|
drumknotty = ./modules/drumknotty;
|
||||||
gickup = ./modules/gickup;
|
gickup = ./modules/gickup;
|
||||||
hugepages = ./modules/hugepages.nix;
|
|
||||||
matrix-ooye = ./modules/matrix-ooye.nix;
|
matrix-ooye = ./modules/matrix-ooye.nix;
|
||||||
python-http-handlers = ./modules/python-http-handlers.nix;
|
python-http-handlers = ./modules/python-http-handlers.nix;
|
||||||
robots-txt = ./modules/robots-txt.nix;
|
robots-txt = ./modules/robots-txt.nix;
|
||||||
|
|||||||
@@ -41,24 +41,38 @@ in
|
|||||||
path = with pkgs; [
|
path = with pkgs; [
|
||||||
cfg.package
|
cfg.package
|
||||||
coreutils
|
coreutils
|
||||||
|
diffutils
|
||||||
zstd
|
zstd
|
||||||
];
|
];
|
||||||
|
|
||||||
script = let
|
script = ''
|
||||||
rotations = 2;
|
|
||||||
in ''
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
OUT_FILE="$STATE_DIRECTORY/mysql-dump-$(date --iso-8601).sql.zst"
|
dump() {
|
||||||
|
local name="$1" out tmp
|
||||||
|
out="$STATE_DIRECTORY/$name.sql.zst"
|
||||||
|
tmp="$out.tmp"
|
||||||
|
shift
|
||||||
|
"$@" | zstd -9 --rsyncable -f -o "$tmp"
|
||||||
|
if cmp -s "$tmp" "$out" 2>/dev/null; then
|
||||||
|
rm -f "$tmp"
|
||||||
|
else
|
||||||
|
mv -f "$tmp" "$out"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
mysqldump --all-databases | zstd --compress -9 --rsyncable -o "$OUT_FILE"
|
declare -A keep
|
||||||
|
while IFS= read -r db; do
|
||||||
|
[ -n "$db" ] || continue
|
||||||
|
dump "$db" mysqldump --skip-dump-date --databases "$db"
|
||||||
|
keep["$db.sql.zst"]=1
|
||||||
|
done < <(mysql -N -e 'SHOW DATABASES' | grep -vE '^(information_schema|performance_schema)$')
|
||||||
|
|
||||||
# NOTE: this needs to be a hardlink for rrsync to allow sending it
|
# drop dumps of databases that no longer exist
|
||||||
rm "$STATE_DIRECTORY/mysql-dump-latest.sql.zst" ||:
|
for f in "$STATE_DIRECTORY"/*.sql.zst; do
|
||||||
ln -T "$OUT_FILE" "$STATE_DIRECTORY/mysql-dump-latest.sql.zst"
|
[ -e "$f" ] || continue
|
||||||
|
base="$(basename "$f")"
|
||||||
while [ "$(find "$STATE_DIRECTORY" -type f -printf '.' | wc -c)" -gt '${toString (rotations + 1)}' ]; do
|
[ -n "''${keep[$base]:-}" ] || rm -f "$f"
|
||||||
rm "$(find "$STATE_DIRECTORY" -type f -printf '%T+ %p\n' | sort | head -n 1 | cut -d' ' -f2)"
|
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
let
|
let
|
||||||
cfg = config.services.mysql;
|
cfg = config.services.mysql;
|
||||||
dataDir = "/data/mysql";
|
dataDir = "/data/mysql";
|
||||||
|
|
||||||
innodbBufferPoolMB = 128;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ ./backup.nix ];
|
imports = [ ./backup.nix ];
|
||||||
@@ -28,10 +26,6 @@ in
|
|||||||
# Useful for the mysqld prometheus exporter
|
# Useful for the mysqld prometheus exporter
|
||||||
userstat = 1;
|
userstat = 1;
|
||||||
|
|
||||||
# Memory settings
|
|
||||||
innodb_buffer_pool_size = "${toString innodbBufferPoolMB}M";
|
|
||||||
"large-pages" = 1;
|
|
||||||
|
|
||||||
# This was needed in order to be able to use all of the old users
|
# This was needed in order to be able to use all of the old users
|
||||||
# during migration from knakelibrak to bicep in Sep. 2023
|
# during migration from knakelibrak to bicep in Sep. 2023
|
||||||
secure_auth = 0;
|
secure_auth = 0;
|
||||||
@@ -53,10 +47,6 @@ in
|
|||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.kernel.hugepages.reservations.mysql = lib.mkIf cfg.enable (
|
|
||||||
builtins.ceil (innodbBufferPoolMB / config.boot.kernel.hugepages.size)
|
|
||||||
);
|
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = lib.mkIf cfg.enable [ 3306 ];
|
networking.firewall.allowedTCPPorts = lib.mkIf cfg.enable [ 3306 ];
|
||||||
|
|
||||||
systemd.tmpfiles.settings."10-mysql".${dataDir}.d = lib.mkIf cfg.enable {
|
systemd.tmpfiles.settings."10-mysql".${dataDir}.d = lib.mkIf cfg.enable {
|
||||||
|
|||||||
@@ -41,25 +41,42 @@ in
|
|||||||
|
|
||||||
path = with pkgs; [
|
path = with pkgs; [
|
||||||
coreutils
|
coreutils
|
||||||
|
diffutils
|
||||||
zstd
|
zstd
|
||||||
cfg.package
|
cfg.package
|
||||||
];
|
];
|
||||||
|
|
||||||
script = let
|
script = ''
|
||||||
rotations = 2;
|
|
||||||
in ''
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
OUT_FILE="$STATE_DIRECTORY/postgresql-dump-$(date --iso-8601).sql.zst"
|
dump() {
|
||||||
|
local name="$1" out tmp
|
||||||
|
out="$STATE_DIRECTORY/$name.sql.zst"
|
||||||
|
tmp="$out.tmp"
|
||||||
|
shift
|
||||||
|
"$@" | zstd -9 --rsyncable -f -o "$tmp"
|
||||||
|
if cmp -s "$tmp" "$out" 2>/dev/null; then
|
||||||
|
rm -f "$tmp"
|
||||||
|
else
|
||||||
|
mv -f "$tmp" "$out"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
pg_dumpall -U postgres | zstd --compress -9 --rsyncable -o "$OUT_FILE"
|
declare -A keep
|
||||||
|
dump globals pg_dumpall -U postgres --globals-only --restrict-key=backup
|
||||||
|
keep[globals.sql.zst]=1
|
||||||
|
|
||||||
# NOTE: this needs to be a hardlink for rrsync to allow sending it
|
while IFS= read -r db; do
|
||||||
rm "$STATE_DIRECTORY/postgresql-dump-latest.sql.zst" ||:
|
[ -n "$db" ] || continue
|
||||||
ln -T "$OUT_FILE" "$STATE_DIRECTORY/postgresql-dump-latest.sql.zst"
|
dump "$db" pg_dump -U postgres -C -d "$db" --restrict-key=backup
|
||||||
|
keep["$db.sql.zst"]=1
|
||||||
|
done < <(psql -U postgres -tAc "SELECT datname FROM pg_database WHERE datallowconn ORDER BY datname")
|
||||||
|
|
||||||
while [ "$(find "$STATE_DIRECTORY" -type f -printf '.' | wc -c)" -gt '${toString (rotations + 1)}' ]; do
|
# drop dumps of databases that no longer exist
|
||||||
rm "$(find "$STATE_DIRECTORY" -type f -printf '%T+ %p\n' | sort | head -n 1 | cut -d' ' -f2)"
|
for f in "$STATE_DIRECTORY"/*.sql.zst; do
|
||||||
|
[ -e "$f" ] || continue
|
||||||
|
base="$(basename "$f")"
|
||||||
|
[ -n "''${keep[$base]:-}" ] || rm -f "$f"
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
{ config, lib, pkgs, values, ... }:
|
{ config, lib, pkgs, values, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.services.postgresql;
|
cfg = config.services.postgresql;
|
||||||
|
|
||||||
sharedBuffersMB = 8192;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
@@ -31,7 +29,7 @@ in
|
|||||||
superuser_reserved_connections = 3;
|
superuser_reserved_connections = 3;
|
||||||
|
|
||||||
# Memory Settings
|
# Memory Settings
|
||||||
shared_buffers = "${toString sharedBuffersMB} MB";
|
shared_buffers = "8192 MB";
|
||||||
work_mem = "32 MB";
|
work_mem = "32 MB";
|
||||||
maintenance_work_mem = "420 MB";
|
maintenance_work_mem = "420 MB";
|
||||||
effective_cache_size = "22 GB";
|
effective_cache_size = "22 GB";
|
||||||
@@ -95,10 +93,6 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.kernel.hugepages.reservations.postgresql = lib.mkIf cfg.enable (
|
|
||||||
builtins.ceil (sharedBuffersMB / config.boot.kernel.hugepages.size)
|
|
||||||
);
|
|
||||||
|
|
||||||
systemd.tmpfiles.settings."10-postgresql"."/data/postgresql".d = lib.mkIf cfg.enable {
|
systemd.tmpfiles.settings."10-postgresql"."/data/postgresql".d = lib.mkIf cfg.enable {
|
||||||
user = config.systemd.services.postgresql.serviceConfig.User;
|
user = config.systemd.services.postgresql.serviceConfig.User;
|
||||||
group = config.systemd.services.postgresql.serviceConfig.Group;
|
group = config.systemd.services.postgresql.serviceConfig.Group;
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
{ config, lib, ... }:
|
|
||||||
let
|
|
||||||
cfg = config.boot.kernel.hugepages;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.boot.kernel.hugepages = {
|
|
||||||
size = lib.mkOption {
|
|
||||||
type = lib.types.enum [ 2 1024 ];
|
|
||||||
default = 2;
|
|
||||||
description = ''
|
|
||||||
Hugepage size in MB.
|
|
||||||
|
|
||||||
You can use this value to calculate the amount of memory you will have available as hugepages.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
reservations = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf lib.types.ints.unsigned;
|
|
||||||
default = { };
|
|
||||||
description = ''
|
|
||||||
Number of hugepages each service wants reserved in vm.nr_hugepages,
|
|
||||||
keyed by service name.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
|
||||||
boot.kernelParams = let
|
|
||||||
num = {
|
|
||||||
"2" = "2M";
|
|
||||||
"1024" = "1G";
|
|
||||||
}.${toString cfg.size};
|
|
||||||
in [ "hugepagesz=${num}" ];
|
|
||||||
|
|
||||||
boot.kernel.sysctl."vm.nr_hugepages" =
|
|
||||||
lib.foldl' (a: b: a + b) 0 (lib.attrValues cfg.reservations);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user