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