]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/system/backup-2.nix
Add chatons infos
[perso/Immae/Config/Nix.git] / modules / private / system / backup-2.nix
1 { config, pkgs, resources, name, lib, ... }:
2 {
3 deployment = {
4 targetUser = "root";
5 targetHost = lib.head config.hostEnv.ips.main.ip4;
6 substituteOnDestination = true;
7 };
8 # ssh-keyscan backup-2 | nix-shell -p ssh-to-age --run ssh-to-age
9 secrets.ageKeys = [ "age1kk3nr27qu42j28mcfdag5lhq0zu2pky7gfanvne8l4z2ctevjpgskmw0sr" ];
10 secrets.keys = {
11 "rsync_backup/identity" = {
12 user = "backup";
13 group = "backup";
14 permissions = "0400";
15 text = config.myEnv.rsync_backup.ssh_key.private;
16 };
17 "rsync_backup/identity.pub" = {
18 user = "backup";
19 group = "backup";
20 permissions = "0444";
21 text = config.myEnv.rsync_backup.ssh_key.public;
22 };
23 };
24 boot.kernelPackages = pkgs.linuxPackages_latest;
25 myEnv = import ../../../nixops/secrets/environment.nix;
26
27 imports = [ <nixpkgs/nixos/modules/profiles/qemu-guest.nix> ] ++ builtins.attrValues (import ../..);
28
29 fileSystems = {
30 "/backup2" = {
31 fsType = "ext4";
32 device = "UUID=b9425333-f567-435d-94d8-b26c22d93426";
33 };
34 "/" = { device = "/dev/sda1"; fsType = "ext4"; };
35 };
36
37 networking = {
38 firewall.enable = true;
39 interfaces."ens3".ipv4.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
40 (n: ips: map (ip: { address = ip; prefixLength = 32; }) (ips.ip4 or []))
41 (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips));
42 interfaces."ens3".ipv6.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
43 (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or []))
44 config.hostEnv.ips);
45 defaultGateway6 = { address = "fe80::1"; interface = "ens3"; };
46 };
47
48 boot.loader.grub.device = "nodev";
49
50 myServices.certificates.enable = true;
51 security.acme.certs."${name}" = {
52 group = config.services.nginx.group;
53 };
54 services.nginx = {
55 enable = true;
56 recommendedOptimisation = true;
57 recommendedGzipSettings = true;
58 recommendedProxySettings = true;
59 };
60 networking.firewall.allowedTCPPorts = [ 80 443 ];
61
62 services.cron = {
63 mailto = "cron@immae.eu";
64 enable = true;
65 };
66
67 myServices.chatonsProperties.hostings.rsync-backup = {
68 file.datetime = "2022-08-27T16:00:00";
69 hosting = {
70 name = "Rsync backups";
71 description = "Remote initiated rsync backups";
72 website = "backup-2.v.immae.eu";
73 status.level = "OK";
74 status.description = "OK";
75 registration.load = "OPEN";
76 install.type = "PACKAGE";
77 };
78 software = {
79 name = "rsync";
80 website = "https://rsync.samba.org/";
81 license.url = "https://rsync.samba.org/GPL.html";
82 license.name = "GNU General Public License version 3";
83 version = pkgs.rsync.version;
84 source.url = "https://github.com/WayneD/rsync";
85 };
86 };
87
88 services.rsyncBackup = {
89 mountpoint = "/backup2";
90 profiles = config.myEnv.rsync_backup.profiles;
91 ssh_key_public = config.secrets.fullPaths."rsync_backup/identity.pub";
92 ssh_key_private = config.secrets.fullPaths."rsync_backup/identity";
93 };
94
95 myServices.mailRelay.enable = true;
96 myServices.mailBackup.enable = true;
97 myServices.monitoring.enable = true;
98 myServices.databasesReplication = {
99 postgresql = {
100 enable = true;
101 base = "/backup2";
102 mainPackage = pkgs.postgresql;
103 hosts = {
104 eldiron = {
105 slot = "backup_2";
106 connection = "postgresql://backup-2:${config.hostEnv.ldap.password}@eldiron.immae.eu";
107 package = pkgs.postgresql;
108 };
109 };
110 };
111 mariadb = {
112 enable = true;
113 base = "/backup2";
114 hosts = {
115 eldiron = {
116 serverId = 2;
117 # mysql resolves "backup-2" host and checks the ip, but uses /etc/hosts which only contains ip4
118 host = lib.head config.myEnv.servers.eldiron.ips.main.ip4;
119 port = "3306";
120 user = "backup-2";
121 password = config.hostEnv.ldap.password;
122 dumpUser = "root";
123 dumpPassword = config.myEnv.databases.mysql.systemUsers.root;
124 };
125 };
126 };
127 redis = {
128 enable = true;
129 base = "/backup2";
130 hosts = {
131 eldiron = {
132 host = "127.0.0.1";
133 port = "16379";
134 };
135 };
136 };
137 openldap = {
138 enable = true;
139 base = "/backup2";
140 hosts = {
141 eldiron = {
142 url = "ldaps://${config.myEnv.ldap.host}:636";
143 dn = config.myEnv.ldap.replication_dn;
144 password = config.myEnv.ldap.replication_pw;
145 base = config.myEnv.ldap.base;
146 };
147 };
148 };
149 };
150
151 # This value determines the NixOS release with which your system is
152 # to be compatible, in order to avoid breaking some software such as
153 # database servers. You should change this only after NixOS release
154 # notes say you should.
155 # https://nixos.org/nixos/manual/release-notes.html
156 system.stateVersion = "20.03"; # Did you read the comment?
157 }