mirror of
https://git.pvv.ntnu.no/Drift/pvv-nixos-config.git
synced 2025-12-15 14:47:14 +01:00
Compare commits
12 Commits
remote
...
087753eb1e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
087753eb1e | ||
|
|
6efebc5cb7 | ||
|
|
c12a47cee0 | ||
|
|
b9ef27565f | ||
|
|
f5c99b58c8 | ||
|
|
c780f7954c | ||
|
|
d64d8edd68 | ||
|
|
4de7bd09bd | ||
|
|
0f5c48902b | ||
|
|
2ff69dfec6 | ||
|
|
36a8868f94 | ||
|
|
fe3e5d6a3d |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
result*
|
result*
|
||||||
/configuration.nix
|
/configuration.nix
|
||||||
/.direnv/
|
/.direnv/
|
||||||
|
*.qcow2
|
||||||
|
|||||||
17
base.nix
17
base.nix
@@ -76,10 +76,19 @@
|
|||||||
# Trusted users on the nix builder machines
|
# Trusted users on the nix builder machines
|
||||||
users.groups."nix-builder-users".name = "nix-builder-users";
|
users.groups."nix-builder-users".name = "nix-builder-users";
|
||||||
|
|
||||||
|
# Let's not thermal throttle
|
||||||
|
services.thermald.enable = lib.mkIf (lib.all (x: x) [
|
||||||
|
(config.nixpkgs.system == "x86_64-linux")
|
||||||
|
(!config.boot.isContainer or false)
|
||||||
|
]) true;
|
||||||
|
|
||||||
services.openssh = {
|
services.openssh = {
|
||||||
enable = true;
|
enable = true;
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
PubkeyAcceptedAlgorithms=+ssh-rsa
|
PubkeyAcceptedAlgorithms=+ssh-rsa
|
||||||
|
Match Group wheel
|
||||||
|
PasswordAuthentication no
|
||||||
|
Match All
|
||||||
'';
|
'';
|
||||||
settings.PermitRootLogin = "yes";
|
settings.PermitRootLogin = "yes";
|
||||||
};
|
};
|
||||||
@@ -130,4 +139,12 @@
|
|||||||
acceptTerms = true;
|
acceptTerms = true;
|
||||||
defaults.email = "drift@pvv.ntnu.no";
|
defaults.email = "drift@pvv.ntnu.no";
|
||||||
};
|
};
|
||||||
|
# Let's not spam LetsEncrypt in `nixos-rebuild build-vm` mode:
|
||||||
|
virtualisation.vmVariant = {
|
||||||
|
security.acme.defaults.server = "https://127.0.0.1";
|
||||||
|
security.acme.preliminarySelfsigned = true;
|
||||||
|
|
||||||
|
users.users.root.initialPassword = "root";
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
8
flake.lock
generated
8
flake.lock
generated
@@ -194,11 +194,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1693136143,
|
"lastModified": 1723850344,
|
||||||
"narHash": "sha256-amHprjftc3y/bg8yf4hITCLa+ez5HIi0yGfR7TU6UIc=",
|
"narHash": "sha256-aT37O9l9eclWEnqxASVNBL1dKwDHZUOqdbA4VO9DJvw=",
|
||||||
"ref": "refs/heads/main",
|
"ref": "refs/heads/main",
|
||||||
"rev": "a32894b305f042d561500f5799226afd1faf5abb",
|
"rev": "38b66677ab8c01aee10cd59e745af9ce3ea88092",
|
||||||
"revCount": 9,
|
"revCount": 19,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.pvv.ntnu.no/Projects/calendar-bot.git"
|
"url": "https://git.pvv.ntnu.no/Projects/calendar-bot.git"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -135,10 +135,16 @@ in {
|
|||||||
script = let
|
script = let
|
||||||
logo-svg = ../../../../assets/logo_blue_regular.svg;
|
logo-svg = ../../../../assets/logo_blue_regular.svg;
|
||||||
logo-png = ../../../../assets/logo_blue_regular.png;
|
logo-png = ../../../../assets/logo_blue_regular.png;
|
||||||
|
extraLinks = pkgs.writeText "gitea-extra-links.tmpl" ''
|
||||||
|
<a class="item" href="https://www.pvv.ntnu.no/">PVV</a>
|
||||||
|
<a class="item" href="https://wiki.pvv.ntnu.no/">Wiki</a>
|
||||||
|
<a class="item" href="https://git.pvv.ntnu.no/Drift/-/projects/4">Tokyo Drift Issues</a>
|
||||||
|
'';
|
||||||
in ''
|
in ''
|
||||||
install -Dm444 ${logo-svg} ${cfg.customDir}/public/assets/img/logo.svg
|
install -Dm444 ${logo-svg} ${cfg.customDir}/public/assets/img/logo.svg
|
||||||
install -Dm444 ${logo-png} ${cfg.customDir}/public/assets/img/logo.png
|
install -Dm444 ${logo-png} ${cfg.customDir}/public/assets/img/logo.png
|
||||||
install -Dm444 ${./loading.apng} ${cfg.customDir}/public/assets/img/loading.png
|
install -Dm444 ${./loading.apng} ${cfg.customDir}/public/assets/img/loading.png
|
||||||
|
install -Dm444 ${extraLinks} ${cfg.customDir}/templates/custom/extra_links.tmpl
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,7 @@
|
|||||||
./services/mysql.nix
|
./services/mysql.nix
|
||||||
./services/postgres.nix
|
./services/postgres.nix
|
||||||
./services/mysql.nix
|
./services/mysql.nix
|
||||||
# TODO: fix the calendar bot
|
./services/calendar-bot.nix
|
||||||
# ./services/calendar-bot.nix
|
|
||||||
|
|
||||||
./services/matrix
|
./services/matrix
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -2,11 +2,19 @@
|
|||||||
let
|
let
|
||||||
cfg = config.services.pvv-calendar-bot;
|
cfg = config.services.pvv-calendar-bot;
|
||||||
in {
|
in {
|
||||||
sops.secrets."calendar-bot/matrix_token" = {
|
sops.secrets = {
|
||||||
sopsFile = ../../../secrets/bicep/bicep.yaml;
|
"calendar-bot/matrix_token" = {
|
||||||
key = "calendar-bot/matrix_token";
|
sopsFile = ../../../secrets/bicep/bicep.yaml;
|
||||||
owner = cfg.user;
|
key = "calendar-bot/matrix_token";
|
||||||
group = cfg.group;
|
owner = cfg.user;
|
||||||
|
group = cfg.group;
|
||||||
|
};
|
||||||
|
"calendar-bot/mysql_password" = {
|
||||||
|
sopsFile = ../../../secrets/bicep/bicep.yaml;
|
||||||
|
key = "calendar-bot/mysql_password";
|
||||||
|
owner = cfg.user;
|
||||||
|
group = cfg.group;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.pvv-calendar-bot = {
|
services.pvv-calendar-bot = {
|
||||||
@@ -18,6 +26,11 @@ in {
|
|||||||
user = "@bot_calendar:pvv.ntnu.no";
|
user = "@bot_calendar:pvv.ntnu.no";
|
||||||
channel = "!gkNLUIhYVpEyLatcRz:pvv.ntnu.no";
|
channel = "!gkNLUIhYVpEyLatcRz:pvv.ntnu.no";
|
||||||
};
|
};
|
||||||
|
database = {
|
||||||
|
host = "mysql.pvv.ntnu.no";
|
||||||
|
user = "calendar-bot";
|
||||||
|
passwordFile = config.sops.secrets."calendar-bot/mysql_password".path;
|
||||||
|
};
|
||||||
secretsFile = config.sops.secrets."calendar-bot/matrix_token".path;
|
secretsFile = config.sops.secrets."calendar-bot/matrix_token".path;
|
||||||
onCalendar = "*-*-* 09:00:00";
|
onCalendar = "*-*-* 09:00:00";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
{ pkgs, lib, config, values, ... }:
|
{ pkgs, lib, config, values, ... }:
|
||||||
|
let
|
||||||
|
backupDir = "/var/lib/mysql/backups";
|
||||||
|
in
|
||||||
{
|
{
|
||||||
sops.secrets."mysql/password" = {
|
sops.secrets."mysql/password" = {
|
||||||
owner = "mysql";
|
owner = "mysql";
|
||||||
@@ -36,11 +39,6 @@
|
|||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.mysqlBackup = {
|
|
||||||
enable = true;
|
|
||||||
location = "/var/lib/mysql/backups";
|
|
||||||
};
|
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = [ 3306 ];
|
networking.firewall.allowedTCPPorts = [ 3306 ];
|
||||||
|
|
||||||
systemd.services.mysql.serviceConfig = {
|
systemd.services.mysql.serviceConfig = {
|
||||||
@@ -50,4 +48,51 @@
|
|||||||
values.ipv6-space
|
values.ipv6-space
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# 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" = {
|
||||||
|
description = "Backup MySQL data";
|
||||||
|
requires = [ "mysql.service" ];
|
||||||
|
|
||||||
|
path = [
|
||||||
|
pkgs.coreutils
|
||||||
|
pkgs.rsync
|
||||||
|
pkgs.gzip
|
||||||
|
config.services.mysql.package
|
||||||
|
];
|
||||||
|
|
||||||
|
script = let
|
||||||
|
rotations = 10;
|
||||||
|
sshTarget1 = "root@isvegg.pvv.ntnu.no:/mnt/backup1/bicep/mysql";
|
||||||
|
sshTarget2 = "root@isvegg.pvv.ntnu.no:/mnt/backup2/bicep/mysql";
|
||||||
|
in ''
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
mysqldump | gzip -c -9 --rsyncable > "${backupDir}/$(date --iso-8601)-dump.sql.gz"
|
||||||
|
|
||||||
|
while [ $(ls -1 "${backupDir}" | wc -l) -gt ${toString rotations} ]; do
|
||||||
|
rm $(find "${backupDir}" -type f -printf '%T+ %p\n' | sort | head -n 1 | cut -d' ' -f2)
|
||||||
|
done
|
||||||
|
|
||||||
|
rsync -avz --delete "${backupDir}" '${sshTarget1}'
|
||||||
|
rsync -avz --delete "${backupDir}" '${sshTarget2}'
|
||||||
|
'';
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "mysql";
|
||||||
|
Group = "mysql";
|
||||||
|
UMask = "0077";
|
||||||
|
ReadWritePaths = [ backupDir ];
|
||||||
|
};
|
||||||
|
|
||||||
|
startAt = "*-*-* 02:15:00";
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.tmpfiles.settings."10-mysql-backup".${backupDir}.d = {
|
||||||
|
user = "mysql";
|
||||||
|
group = "mysql";
|
||||||
|
mode = "700";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{ config, pkgs, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
sslCert = config.security.acme.certs."postgres.pvv.ntnu.no";
|
sslCert = config.security.acme.certs."postgres.pvv.ntnu.no";
|
||||||
|
backupDir = "/var/lib/postgresql/backups";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
@@ -89,9 +90,50 @@ in
|
|||||||
networking.firewall.allowedTCPPorts = [ 5432 ];
|
networking.firewall.allowedTCPPorts = [ 5432 ];
|
||||||
networking.firewall.allowedUDPPorts = [ 5432 ];
|
networking.firewall.allowedUDPPorts = [ 5432 ];
|
||||||
|
|
||||||
services.postgresqlBackup = {
|
# NOTE: instead of having the upstream nixpkgs postgres backup unit trigger
|
||||||
enable = true;
|
# another unit, it was easier to just make one ourselves
|
||||||
location = "/var/lib/postgres/backups";
|
systemd.services."backup-postgresql" = {
|
||||||
backupAll = true;
|
description = "Backup PostgreSQL data";
|
||||||
|
requires = [ "postgresql.service" ];
|
||||||
|
|
||||||
|
path = [
|
||||||
|
pkgs.coreutils
|
||||||
|
pkgs.rsync
|
||||||
|
pkgs.gzip
|
||||||
|
config.services.postgresql.package
|
||||||
|
];
|
||||||
|
|
||||||
|
script = let
|
||||||
|
rotations = 10;
|
||||||
|
sshTarget1 = "root@isvegg.pvv.ntnu.no:/mnt/backup1/bicep/postgresql";
|
||||||
|
sshTarget2 = "root@isvegg.pvv.ntnu.no:/mnt/backup2/bicep/postgresql";
|
||||||
|
in ''
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
pg_dumpall -U postgres | gzip -c -9 --rsyncable > "${backupDir}/$(date --iso-8601)-dump.sql.gz"
|
||||||
|
|
||||||
|
while [ $(ls -1 "${backupDir}" | wc -l) -gt ${toString rotations} ]; do
|
||||||
|
rm $(find "${backupDir}" -type f -printf '%T+ %p\n' | sort | head -n 1 | cut -d' ' -f2)
|
||||||
|
done
|
||||||
|
|
||||||
|
rsync -avz --delete "${backupDir}" '${sshTarget1}'
|
||||||
|
rsync -avz --delete "${backupDir}" '${sshTarget2}'
|
||||||
|
'';
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "postgres";
|
||||||
|
Group = "postgres";
|
||||||
|
UMask = "0077";
|
||||||
|
ReadWritePaths = [ backupDir ];
|
||||||
|
};
|
||||||
|
|
||||||
|
startAt = "*-*-* 01:15:00";
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.tmpfiles.settings."10-postgresql-backup".${backupDir}.d = {
|
||||||
|
user = "postgres";
|
||||||
|
group = "postgres";
|
||||||
|
mode = "700";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
4
justfile
4
justfile
@@ -10,6 +10,10 @@ check:
|
|||||||
build-machine machine=`just _a_machine`:
|
build-machine machine=`just _a_machine`:
|
||||||
{{nom}} build .#nixosConfigurations.{{ machine }}.config.system.build.toplevel
|
{{nom}} build .#nixosConfigurations.{{ machine }}.config.system.build.toplevel
|
||||||
|
|
||||||
|
run-vm machine=`just _a_machine`:
|
||||||
|
nixos-rebuild build-vm --flake .#{{ machine }}
|
||||||
|
QEMU_NET_OPTS="hostfwd=tcp::8080-:80,hostfwd=tcp::8081-:443,hostfwd=tcp::2222-:22" ./result/bin/run-*-vm
|
||||||
|
|
||||||
@update-inputs:
|
@update-inputs:
|
||||||
nix eval .#inputs --apply builtins.attrNames --json \
|
nix eval .#inputs --apply builtins.attrNames --json \
|
||||||
| jq '.[]' -r \
|
| jq '.[]' -r \
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
calendar-bot:
|
calendar-bot:
|
||||||
matrix_token: ENC[AES256_GCM,data:zJv9sw6pEzb9hxKT682wsD87HC9iejbps2wl2Z5QW1XZUSBHdcqyg1pxd+jFKTeKGQ==,iv:zDbvF1H98NsECjCtGXS+Y9HIhXowzz9HF9mltqnArog=,tag:/ftcOSQ13ElkVJBxYIMUGQ==,type:str]
|
matrix_token: ENC[AES256_GCM,data:zJv9sw6pEzb9hxKT682wsD87HC9iejbps2wl2Z5QW1XZUSBHdcqyg1pxd+jFKTeKGQ==,iv:zDbvF1H98NsECjCtGXS+Y9HIhXowzz9HF9mltqnArog=,tag:/ftcOSQ13ElkVJBxYIMUGQ==,type:str]
|
||||||
|
mysql_password: ENC[AES256_GCM,data:Gqag8yOgPH3ntoT5TmaqJWv1j+si2qIyz5Ryfw5E2A==,iv:kQDcxnPfwJQcFovI4f87UDt18F8ah3z5xeY86KmdCyY=,tag:A1sCSNXJziAmtUWohqwJgg==,type:str]
|
||||||
mysql:
|
mysql:
|
||||||
password: ENC[AES256_GCM,data:KqEe0TVdeMIzPKsmFg9x0X9xWijnOk306ycyXTm2Tpqo/O0F,iv:Y+hlQ8n1ZIP9ncXBzd2kCSs/DWVTWhiEluFVwZFKRCA=,tag:xlaUk0Wftk62LpYE5pKNQw==,type:str]
|
password: ENC[AES256_GCM,data:KqEe0TVdeMIzPKsmFg9x0X9xWijnOk306ycyXTm2Tpqo/O0F,iv:Y+hlQ8n1ZIP9ncXBzd2kCSs/DWVTWhiEluFVwZFKRCA=,tag:xlaUk0Wftk62LpYE5pKNQw==,type:str]
|
||||||
sops:
|
sops:
|
||||||
@@ -62,8 +63,8 @@ sops:
|
|||||||
cTh5bnJ3WW90aXRCSUp6NHFYeU1tZ0kK4afdtJwGNu6wLRI0fuu+mBVeqVeB0rgX
|
cTh5bnJ3WW90aXRCSUp6NHFYeU1tZ0kK4afdtJwGNu6wLRI0fuu+mBVeqVeB0rgX
|
||||||
0q5hwyzjiRnHnyjF38CmcGgydSfDRmF6P+WIMbCwXC6LwfRhAmBGPg==
|
0q5hwyzjiRnHnyjF38CmcGgydSfDRmF6P+WIMbCwXC6LwfRhAmBGPg==
|
||||||
-----END AGE ENCRYPTED FILE-----
|
-----END AGE ENCRYPTED FILE-----
|
||||||
lastmodified: "2023-09-05T23:28:56Z"
|
lastmodified: "2024-08-15T21:18:33Z"
|
||||||
mac: ENC[AES256_GCM,data:pCWTkmCQgBOqhejK2sCLQ3H8bRXmXlToQxYmOG0IWDo2eGiZOLuIkZ1/1grYgfxAGiD4ysJod0nJuvo+eAsMeYAy6QJVtrOqO2d9V2NEdzLckXyYvwyJyZoFbNC5EW9471V0m4jLRSh5821ckNo/wtWFR11wfO15tI3MqtD1rtA=,iv:QDnckPl0LegaH0b7V4WAtmVXaL4LN+k3uKHQI2dkW7E=,tag:mScUQBR0ZHl1pi/YztrvFg==,type:str]
|
mac: ENC[AES256_GCM,data:uR5HgeDAYqoqB9kk1V6p0T30+v6WpQJi4+qIeCDRnoUPnQKUVR10hvBhICck+E+Uh8p+tGhM6Uf3YrAJAV0ZCUiNJjtwDJQQLUDT53vdOAXN4xADCQqNuhgVwVMaruoTheEiwOswRuhFeEwy0gBj3Ze2pu47lueHYclmEzumLeQ=,iv:t0UyXN2YaR2m7M/pV2wTLJG5wVfqTIUs7wSQMmyeTVw=,tag:O7dIffzrDAXz3kGx5uazhw==,type:str]
|
||||||
pgp:
|
pgp:
|
||||||
- created_at: "2024-08-04T00:03:40Z"
|
- created_at: "2024-08-04T00:03:40Z"
|
||||||
enc: |-
|
enc: |-
|
||||||
@@ -86,4 +87,4 @@ sops:
|
|||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
fp: F7D37890228A907440E1FD4846B9228E814A2AAC
|
fp: F7D37890228A907440E1FD4846B9228E814A2AAC
|
||||||
unencrypted_suffix: _unencrypted
|
unencrypted_suffix: _unencrypted
|
||||||
version: 3.7.3
|
version: 3.9.0
|
||||||
|
|||||||
Reference in New Issue
Block a user