]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/system/backup-2.nix
Add backup MX
[perso/Immae/Config/Nix.git] / modules / private / system / backup-2.nix
CommitLineData
8415083e 1{ privateFiles }:
619e4f46 2{ config, pkgs, resources, ... }:
8415083e
IB
3{
4 boot.kernelPackages = pkgs.linuxPackages_latest;
ab8f306d 5 myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; };
ab8f306d 6
8415083e
IB
7 imports = builtins.attrValues (import ../..);
8
9 deployment = {
10 targetEnv = "hetznerCloud";
11 hetznerCloud = {
ab8f306d 12 authToken = config.myEnv.hetznerCloud.authToken;
8415083e
IB
13 datacenter = "hel1-dc2";
14 location ="hel1";
15 serverType = "cx11";
16 };
17 };
18
ae485806
IB
19 fileSystems = {
20 "/backup2" = {
21 fsType = "ext4";
22 device = "UUID=b9425333-f567-435d-94d8-b26c22d93426";
23 };
24 };
25
26 networking = {
27 firewall.enable = true;
28 interfaces."ens3".ipv4.addresses = pkgs.lib.attrsets.mapAttrsToList
29 (n: ips: { address = ips.ip4; prefixLength = 32; })
619e4f46 30 (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips);
ae485806
IB
31 interfaces."ens3".ipv6.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
32 (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or []))
619e4f46 33 config.hostEnv.ips);
dc0e644a 34 defaultGateway6 = { address = "fe80::1"; interface = "ens3"; };
285380fe
IB
35 };
36
619e4f46
IB
37 myServices.certificates.enable = true;
38 services.nginx = {
39 enable = true;
40 recommendedOptimisation = true;
41 recommendedGzipSettings = true;
42 recommendedProxySettings = true;
43 };
44 networking.firewall.allowedTCPPorts = [ 80 443 ];
45
4227853a
IB
46 services.cron = {
47 mailto = "cron@immae.eu";
48 enable = true;
49 };
50
285380fe
IB
51 services.rsyncBackup = {
52 mountpoint = "/backup2";
ab8f306d
IB
53 mailto = config.myEnv.rsync_backup.mailto;
54 profiles = config.myEnv.rsync_backup.profiles;
55 ssh_key_public = config.myEnv.rsync_backup.ssh_key.public;
56 ssh_key_private = config.myEnv.rsync_backup.ssh_key.private;
ae485806
IB
57 };
58
deca5e9b 59 myServices.mailRelay.enable = true;
619e4f46 60 myServices.mailBackup.enable = true;
9f202523 61 myServices.monitoring.enable = true;
ec9b6564
IB
62 myServices.databasesReplication = {
63 postgresql = {
64 enable = true;
65 base = "/backup2";
66 hosts = {
67 eldiron = {
68 slot = "backup_2";
619e4f46 69 connection = "postgresql://backup-2:${config.hostEnv.ldap.password}@eldiron.immae.eu";
ec9b6564
IB
70 };
71 };
72 };
9f6a7862
IB
73 mariadb = {
74 enable = true;
75 base = "/backup2";
76 hosts = {
77 eldiron = {
78 serverId = 2;
79 # mysql resolves "backup-2" host and checks the ip, but uses /etc/hosts which only contains ip4
ab8f306d 80 host = config.myEnv.servers.eldiron.ips.main.ip4;
9f6a7862
IB
81 port = "3306";
82 user = "backup-2";
619e4f46 83 password = config.hostEnv.ldap.password;
9f6a7862 84 dumpUser = "root";
ab8f306d 85 dumpPassword = config.myEnv.databases.mysql.systemUsers.root;
9f6a7862
IB
86 };
87 };
88 };
dded6699
IB
89 redis = {
90 enable = true;
91 base = "/backup2";
92 hosts = {
93 eldiron = {
94 host = "127.0.0.1";
95 port = "16379";
96 };
97 };
98 };
16b80abd
IB
99 openldap = {
100 enable = true;
101 base = "/backup2";
102 hosts = {
103 eldiron = {
ab8f306d
IB
104 url = "ldaps://${config.myEnv.ldap.host}:636";
105 dn = config.myEnv.ldap.replication_dn;
106 password = config.myEnv.ldap.replication_pw;
107 base = config.myEnv.ldap.base;
16b80abd
IB
108 };
109 };
110 };
ec9b6564
IB
111 };
112
8415083e
IB
113 # This value determines the NixOS release with which your system is
114 # to be compatible, in order to avoid breaking some software such as
115 # database servers. You should change this only after NixOS release
116 # notes say you should.
117 # https://nixos.org/nixos/manual/release-notes.html
118 system.stateVersion = "19.03"; # Did you read the comment?
119}