mirror of
https://git.pvv.ntnu.no/Drift/pvv-nixos-config.git
synced 2026-01-12 02:18:25 +01:00
Compare commits
3 Commits
ccefcb01fa
...
backup-dat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4521d404ae | ||
|
|
f498b82b07 | ||
|
|
9034a71927 |
@@ -26,14 +26,10 @@ Det er sikkert lurt å lage en PR først om du ikke er vandt til nix enda.
|
|||||||
Innen 24h skal alle systemene hente ned den nye konfigurasjonen og deploye den.
|
Innen 24h skal alle systemene hente ned den nye konfigurasjonen og deploye den.
|
||||||
|
|
||||||
Du kan tvinge en maskin til å oppdatere seg før dette ved å kjøre:
|
Du kan tvinge en maskin til å oppdatere seg før dette ved å kjøre:
|
||||||
`nixos-rebuild switch --update-input nixpkgs --update-input nixpkgs-unstable --no-write-lock-file --refresh --upgrade --flake git+https://git.pvv.ntnu.no/Drift/pvv-nixos-config.git`
|
`nixos-rebuild switch --update-input nixpkgs --update-input nixpkgs-unstable --no-write-lock-file --refresh --flake git+https://git.pvv.ntnu.no/Drift/pvv-nixos-config.git --upgrade`
|
||||||
|
|
||||||
som root på maskinen.
|
som root på maskinen.
|
||||||
|
|
||||||
Hvis du ikke har lyst til å oppdatere alle pakkene (og kanskje måtte vente en stund!) kan du kjøre
|
|
||||||
|
|
||||||
`nixos-rebuild switch --override-input nixpkgs nixpkgs --override-input nixpkgs-unstable nixpkgs-unstable --flake git+https://git.pvv.ntnu.no/Drift/pvv-nixos-config.git`
|
|
||||||
|
|
||||||
## Seksjonen for hemmeligheter
|
## Seksjonen for hemmeligheter
|
||||||
|
|
||||||
For at hemmeligheter ikke skal deles med hele verden i git - eller å være world
|
For at hemmeligheter ikke skal deles med hele verden i git - eller å være world
|
||||||
|
|||||||
@@ -23,12 +23,8 @@
|
|||||||
*/
|
*/
|
||||||
registry = {
|
registry = {
|
||||||
"nixpkgs".flake = inputs.nixpkgs;
|
"nixpkgs".flake = inputs.nixpkgs;
|
||||||
"nixpkgs-unstable".flake = inputs.nixpkgs-unstable;
|
|
||||||
"pvv-nix".flake = inputs.self;
|
"pvv-nix".flake = inputs.self;
|
||||||
};
|
};
|
||||||
nixPath = [
|
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
|
||||||
"nixpkgs=${inputs.nixpkgs}"
|
|
||||||
"unstable=${inputs.nixpkgs-unstable}"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
52
flake.lock
generated
52
flake.lock
generated
@@ -7,11 +7,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1725242307,
|
"lastModified": 1715445235,
|
||||||
"narHash": "sha256-a2iTMBngegEZvaNAzzxq5Gc5Vp3UWoGUqWtK11Txbic=",
|
"narHash": "sha256-SUu+oIWn+xqQIOlwfwNfS9Sek4i1HKsrLJchsDReXwA=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "disko",
|
"repo": "disko",
|
||||||
"rev": "96073e6423623d4a8027e9739d2af86d6422ea7a",
|
"rev": "159d87ea5b95bbdea46f0288a33c5e1570272725",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -67,11 +67,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1716065905,
|
"lastModified": 1715364232,
|
||||||
"narHash": "sha256-08uhxBzfakfhl/ooc+gMzDupWKYvTeyQZwuvB1SBS7A=",
|
"narHash": "sha256-ZJC3SkanEgbV7p+LFhP+85CviRWOXJNHzZwR/Stb7hE=",
|
||||||
"owner": "Programvareverkstedet",
|
"owner": "Programvareverkstedet",
|
||||||
"repo": "grzegorz",
|
"repo": "grzegorz",
|
||||||
"rev": "0481aef6553ae9aee86e4edb4ca0ed4f2eba2058",
|
"rev": "3841cda1cdcac470440b06838d56a2eb2256378c",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -87,11 +87,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1716115695,
|
"lastModified": 1715384651,
|
||||||
"narHash": "sha256-aI65l4x+U5v3i/nfn6N3eW5IZodmf4pyAByE7vTJh8I=",
|
"narHash": "sha256-7RhckgUTjqeCjWkhiCc1iB+5CBx9fl80d/3O4Jh+5kM=",
|
||||||
"owner": "Programvareverkstedet",
|
"owner": "Programvareverkstedet",
|
||||||
"repo": "grzegorz-clients",
|
"repo": "grzegorz-clients",
|
||||||
"rev": "b9444658fbb39cd1bf1c61ee5a1d5f0641c49abe",
|
"rev": "738a4f3dd887f7c3612e4e772b83cbfa3cde5693",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -143,11 +143,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1725198597,
|
"lastModified": 1719520878,
|
||||||
"narHash": "sha256-w3sjCEbnc242ByJ18uebzgjFZY3QU7dZhmLwPsJIZJs=",
|
"narHash": "sha256-5BXzNOl2RVHcfS/oxaZDKOi7gVuTyWPibQG0DHd5sSc=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "3524b030c839db4ea4ba16737789c6fb8a1769c6",
|
"rev": "a44bedbb48c367f0476e6a3a27bf28f6330faf23",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -158,27 +158,27 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs-stable": {
|
"nixpkgs-stable": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1721524707,
|
"lastModified": 1714858427,
|
||||||
"narHash": "sha256-5NctRsoE54N86nWd0psae70YSLfrOek3Kv1e8KoXe/0=",
|
"narHash": "sha256-tCxeDP4C1pWe2rYY3IIhdA40Ujz32Ufd4tcrHPSKx2M=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "556533a23879fc7e5f98dd2e0b31a6911a213171",
|
"rev": "b980b91038fc4b09067ef97bbe5ad07eecca1e76",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"ref": "release-24.05",
|
"ref": "release-23.11",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs-unstable": {
|
"nixpkgs-unstable": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1725183711,
|
"lastModified": 1715435713,
|
||||||
"narHash": "sha256-gkjg8FfjL92azt3gzZUm1+v+U4y+wbQE630uIf4Aybo=",
|
"narHash": "sha256-lb2HqDQGfTdnCCpc1pgF6fkdgIOuBQ0nP8jjVSfLFqg=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "a2c345850e5e1d96c62e7fa8ca6c9d77ebad1c37",
|
"rev": "52b40f6c4be12742b1504ca2eb4527e597bf2526",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -214,11 +214,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1725212759,
|
"lastModified": 1722722932,
|
||||||
"narHash": "sha256-yZBsefIarFUEhFRj+rCGMp9Zvag3MCafqV/JfGVRVwc=",
|
"narHash": "sha256-K81a2GQpY2kRX+C9ek9r91THlZB674CqRTSMMb5IO7E=",
|
||||||
"ref": "refs/heads/master",
|
"ref": "refs/heads/master",
|
||||||
"rev": "e7b66b4bc6a89bab74bac45b87e9434f5165355f",
|
"rev": "6580cfe546c902cdf11e17b0b8aa30b3c412bb34",
|
||||||
"revCount": 473,
|
"revCount": 465,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.pvv.ntnu.no/Projects/nettsiden.git"
|
"url": "https://git.pvv.ntnu.no/Projects/nettsiden.git"
|
||||||
},
|
},
|
||||||
@@ -249,11 +249,11 @@
|
|||||||
"nixpkgs-stable": "nixpkgs-stable"
|
"nixpkgs-stable": "nixpkgs-stable"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1725201042,
|
"lastModified": 1715244550,
|
||||||
"narHash": "sha256-lj5pxOwidP0W//E7IvyhbhXrnEUW99I07+QpERnzTS4=",
|
"narHash": "sha256-ffOZL3eaZz5Y1nQ9muC36wBCWwS1hSRLhUzlA9hV2oI=",
|
||||||
"owner": "Mic92",
|
"owner": "Mic92",
|
||||||
"repo": "sops-nix",
|
"repo": "sops-nix",
|
||||||
"rev": "5db5921e40ae382d6716dce591ea23b0a39d96f7",
|
"rev": "0dc50257c00ee3c65fef3a255f6564cfbfe6eb7f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -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,58 @@
|
|||||||
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;
|
||||||
|
# rsyncTarget = "root@isvegg.pvv.ntnu.no:/mnt/backup1/bicep/mysql";
|
||||||
|
rsyncTarget = "/data/backup/mysql";
|
||||||
|
in ''
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
mysqldump --all-databases | 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}" '${rsyncTarget}'
|
||||||
|
'';
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "mysql";
|
||||||
|
Group = "mysql";
|
||||||
|
UMask = "0077";
|
||||||
|
|
||||||
|
Nice = 19;
|
||||||
|
IOSchedulingClass = "best-effort";
|
||||||
|
IOSchedulingPriority = 7;
|
||||||
|
|
||||||
|
ReadWritePaths = [
|
||||||
|
backupDir
|
||||||
|
"/data/backup/mysql" # NOTE: should not be part of this option once rsyncTarget is remote
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
startAt = "*-*-* 02:15:00";
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.tmpfiles.settings."10-mysql-backup".${backupDir}.d = {
|
||||||
|
user = "mysql";
|
||||||
|
group = "mysql";
|
||||||
|
mode = "700";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
{ config, pkgs, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
|
let
|
||||||
|
backupDir = "/var/lib/postgresql/backups";
|
||||||
|
in
|
||||||
{
|
{
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
enable = true;
|
enable = true;
|
||||||
@@ -90,9 +93,57 @@
|
|||||||
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;
|
||||||
|
# rsyncTarget = "root@isvegg.pvv.ntnu.no:/mnt/backup1/bicep/postgresql";
|
||||||
|
rsyncTarget = "/data/backup/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}" '${rsyncTarget}'
|
||||||
|
'';
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "postgres";
|
||||||
|
Group = "postgres";
|
||||||
|
UMask = "0077";
|
||||||
|
|
||||||
|
Nice = 19;
|
||||||
|
IOSchedulingClass = "best-effort";
|
||||||
|
IOSchedulingPriority = 7;
|
||||||
|
|
||||||
|
ReadWritePaths = [
|
||||||
|
backupDir
|
||||||
|
"/data/backup/postgresql" # NOTE: should not be part of this option once rsyncTarget is remote
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
startAt = "*-*-* 01:15:00";
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.tmpfiles.settings."10-postgresql-backup".${backupDir}.d = {
|
||||||
|
user = "postgres";
|
||||||
|
group = "postgres";
|
||||||
|
mode = "700";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user