]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/system/eldiron.nix
Move secrets to flakes
[perso/Immae/Config/Nix.git] / modules / private / system / eldiron.nix
CommitLineData
7e214bf9 1{ config, pkgs, lib, ... }:
f807d917 2{
34abd6af
IB
3 deployment = {
4 targetUser = "root";
5 targetHost = config.hostEnv.ips.main.ip4;
6 substituteOnDestination = true;
7 };
282c67a1
IB
8 # ssh-keyscan eldiron | nix-shell -p ssh-to-age --run ssh-to-age
9 secrets.ageKeys = [ "age1dxr5lhvtnjssfaqpnf6qx80h8gfwkxg3tdf35m6n9wljmk7wadfs3kmahj" ];
34abd6af
IB
10 boot = {
11 kernelModules = [ "kvm-intel" ];
12 blacklistedKernelModules = [ "nvidiafb" ];
13 loader.timeout = 1;
14 loader.grub.devices = [ "/dev/sda" "/dev/sdb" ];
15 kernel.sysctl = {
16 # https://github.com/Netflix/security-bulletins/blob/master/advisories/third-party/2019-001.md
17 "net.ipv4.tcp_sack" = 0;
18 };
19 supportedFilesystems = [ "zfs" ];
20 kernelParams = ["zfs.zfs_arc_max=6442450944"];
21 kernelPackages = pkgs.linuxPackages_latest;
22 initrd.availableKernelModules = [ "ahci" "sd_mod" ];
23 initrd.secrets = {
24 "/boot/pass.key" = "/boot/pass.key";
25 };
26 };
27 services.udev.extraRules = ''
28 ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="c8:60:00:56:a0:88", NAME="eth0"
29 '';
30 nix.maxJobs = 8;
31 powerManagement.cpuFreqGovernor = "powersave";
282c67a1 32 myEnv = import ../../../nixops/secrets/environment.nix;
f807d917 33
7e214bf9 34 fileSystems = {
ef909e24
IB
35 # pools:
36 # zpool: ashift=12
37 # zfast: ashift=12
38 # zfs:
39 # zpool/: acltype=posixacl ; xattr=sa ; atime=off ; mountpoint=legacy
40 # zpool/root: encryption=on ; keyformat=passphrase ; keylocation=file:///boot/pass.key
41 # zpool/root/var: atime=on
42 # zfast/: acltype=posixacl ; xattr=sa ; atime=off ; mountpoint=legacy
43 # zfast/root: encryption=on ; keyformat=passphrase ; keylocation=file:///boot/pass.key
44 # zfast/root/etc: ø
45 # zfast/root/nix: ø
46 # zfast/root/tmp: async=disabled
47 # zfast/root/var: atime=on
48 # zfast/root/var/lib: ø
49 # zfast/root/var/lib/mysql: logbias=throughput ; atime=off ; primarycache=metadata
50 # zfast/root/var/lib/postgresql: recordsize=8K ; atime=off ; logbias=throughput
51 # zfast/root/var/lib/postgresql/11.0: ø
52 # zfast/root/var/lib/postgresql/11.0/pg_wal: ø
34abd6af 53 "/" = { fsType = "zfs"; device = "zpool/root"; };
7e214bf9
IB
54 "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/e6bb18fb-ff56-4b5f-ae9f-e60d40dc0622"; };
55 "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; };
ef909e24
IB
56 "/nix" = { fsType = "zfs"; device = "zfast/root/nix"; };
57 "/tmp" = { fsType = "zfs"; device = "zfast/root/tmp"; };
7e214bf9 58 "/var" = { fsType = "zfs"; device = "zpool/root/var"; };
ef909e24
IB
59 "/var/lib/mysql" = { fsType = "zfs"; device = "zfast/root/var/lib/mysql"; };
60 "/var/lib/postgresql" = { fsType = "zfs"; device = "zfast/root/var/lib/postgresql"; };
61 "/var/lib/postgresql/11.0" = { fsType = "zfs"; device = "zfast/root/var/lib/postgresql/11.0"; };
62 "/var/lib/postgresql/11.0/pg_wal" = { fsType = "zfs"; device = "zfast/root/var/lib/postgresql/11.0/pg_wal"; };
7e214bf9 63 };
34abd6af
IB
64 swapDevices = [ { label = "swap1"; } { label = "swap2"; } ];
65 hardware.enableRedistributableFirmware = true;
7e214bf9
IB
66
67 services.zfs = {
7e214bf9 68 autoScrub = {
05a3b252 69 enable = false;
7e214bf9
IB
70 };
71 };
f807d917 72 networking = {
31e11cdf 73 hostId = "8262ca33"; # generated with head -c4 /dev/urandom | od -A none -t x4
f807d917 74 firewall.enable = true;
05a3b252 75 # FIXME: on next reboot, remove the /27 and the localCommands
34abd6af
IB
76 interfaces."eth0".ipv4.addresses =
77 pkgs.lib.attrsets.mapAttrsToList
78 (n: ips: { address = ips.ip4; prefixLength = 32; })
79 (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips)
80 ++ [ { address = config.hostEnv.ips.main.ip4; prefixLength = 27; } ];
f807d917
IB
81 interfaces."eth0".ipv6.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
82 (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or []))
619e4f46 83 config.hostEnv.ips);
34abd6af
IB
84 defaultGateway = "176.9.151.65";
85 localCommands = ''
86 # FIXME: Those commands were added by nixops and may not be
87 # actually needed
88 ip -6 addr add '2a01:4f8:160:3445::/64' dev 'eth0' || true
89 ip -4 route change '176.9.151.64/27' via '176.9.151.65' dev 'eth0' || true
90 ip -6 route add default via 'fe80::1' dev eth0 || true
91 '';
92 nameservers = [
93 "213.133.98.98"
94 "213.133.99.99"
95 "213.133.100.100"
96 "2a01:4f8:0:a0a1::add:1010"
97 "2a01:4f8:0:a102::add:9999"
98 "2a01:4f8:0:a111::add:9898"
99 ];
f807d917
IB
100 };
101
102 imports = builtins.attrValues (import ../..);
103
104 myServices.buildbot.enable = true;
105 myServices.databases.enable = true;
106 myServices.gitolite.enable = true;
3bc32d9e 107 myServices.monitoring.enable = true;
f807d917
IB
108 myServices.irc.enable = true;
109 myServices.pub.enable = true;
110 myServices.tasks.enable = true;
8415083e
IB
111 myServices.mpd.enable = true;
112 myServices.dns.enable = true;
113 myServices.certificates.enable = true;
114 myServices.websites.enable = true;
ef118cb3 115 myServices.gemini.enable = true;
8415083e 116 myServices.mail.enable = true;
3f453c7d 117 myServices.ejabberd.enable = true;
ea9c6fe8 118 myServices.vpn.enable = true;
f807d917 119 services.pure-ftpd.enable = true;
5b42284e 120 services.duplyBackup.enable = false;
213c323a 121 services.duplyBackup.profiles.oldies.rootDir = "/var/lib/oldies";
f807d917 122
e43fdf34
IB
123 services.netdata.enable = true;
124 services.netdata.config.global."memory mode" = "none";
125 services.netdata.config.health."enabled" = "no";
126 services.netdata.config.web.mode = "none";
c081a03a 127 users.users."${config.services.netdata.user}".extraGroups = [ "keys" ];
da30ae4f 128 environment.etc."netdata/stream.conf".source = config.secrets.fullPaths."netdata-stream.conf";
8bf83d7a 129 secrets.keys = [
c081a03a
IB
130 {
131 dest = "netdata-stream.conf";
132 user = config.services.netdata.user;
133 group = config.services.netdata.group;
134 permissions = "0400";
135 text = ''
136 [stream]
137 enabled = yes
138 destination = ${config.myEnv.monitoring.netdata_aggregator}
139 api key = ${config.myEnv.monitoring.netdata_keys.eldiron}
140 '';
141 }
8bf83d7a 142 {
5dda316b 143 dest = "zrepl_backup/identity";
8bf83d7a
IB
144 user = "root";
145 group = "root";
146 permissions = "0400";
5dda316b 147 text = config.myEnv.zrepl_backup.ssh_key.private;
8bf83d7a
IB
148 }
149 ];
150 programs.ssh.knownHosts.dilion = {
151 hostNames = ["dilion.immae.eu"];
152 publicKey = let
153 profile = config.myEnv.rsync_backup.profiles.dilion;
154 in
155 "${profile.host_key_type} ${profile.host_key}";
156 };
157
f807d917
IB
158 services.cron = {
159 enable = true;
4227853a 160 mailto = "cron@immae.eu";
f807d917
IB
161 systemCronJobs = [
162 ''
fb7611c1
IB
163 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtpd -g "immae.eu.*Recipient address rejected"
164 # Need a way to blacklist properly
165 # 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtpd -g "NOQUEUE:"
166 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtp -g "status=bounced"
f807d917
IB
167 ''
168 ];
169 };
170
f831eb7e
IB
171 fileSystems."/var/lib/pub/immae/devtools" = {
172 device = "/run/current-system/sw/bin/bindfs#/var/lib/ftp/devtools.immae.eu/";
173 fsType = "fuse";
174 options = [ "force-user=pub" "create-for-user=wwwrun" "create-for-group=wwwrun" ];
175 };
740a6506 176 environment.systemPackages = [ pkgs.bindfs ];
f831eb7e 177
5dda316b
IB
178 services.zrepl = {
179 enable = true;
180 config = let
181 redis_dump = pkgs.writeScript "redis-dump" ''
182 #! ${pkgs.stdenv.shell}
183 ${pkgs.redis}/bin/redis-cli bgsave
184 '';
185 in ''
186 jobs:
187 - type: push
188 # must not change
189 name: "backup-to-dilion"
190 filesystems:
191 "zpool/root": true
192 "zpool/root/etc": true
193 "zpool/root/var<": true
194 connect:
195 type: ssh+stdinserver
196 host: dilion.immae.eu
197 user: backup
198 port: 22
199 identity_file: ${config.secrets.fullPaths."zrepl_backup/identity"}
200 snapshotting:
201 type: periodic
202 prefix: zrepl_
8b150321
IB
203 interval: 1h
204 #hooks:
205 # - type: mysql-lock-tables
206 # dsn: "${config.myEnv.zrepl_backup.mysql.user}:${config.myEnv.zrepl_backup.mysql.password}@tcp(localhost)/"
207 # filesystems:
208 # "zpool/root/var": true
209 # - type: command
210 # path: ${redis_dump}
211 # err_is_fatal: false
212 # filesystems:
213 # "zpool/root/var": true
5dda316b
IB
214 send:
215 encrypted: true
216 pruning:
217 keep_sender:
5dda316b
IB
218 - type: regex
219 regex: "^manual_.*"
220 - type: grid
8b150321 221 grid: 24x1h | 7x1d | 4x7d | 6x30d
5dda316b
IB
222 regex: "^zrepl_.*"
223 keep_receiver:
224 - type: regex
225 regex: "^manual_.*"
226 - type: grid
8b150321 227 grid: 6x4h | 7x1d | 4x7d | 6x30d
5dda316b
IB
228 regex: "^zrepl_.*"
229 '';
230 };
f807d917
IB
231 # This value determines the NixOS release with which your system is
232 # to be compatible, in order to avoid breaking some software such as
233 # database servers. You should change this only after NixOS release
234 # notes say you should.
61ebe69b 235 # https://nixos.org/nixos/manual/release-notes.html
d43e0c61 236 system.stateVersion = "20.03"; # Did you read the comment?
f807d917 237}