]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/system/eldiron.nix
Migrate dilion to ZFS
[perso/Immae/Config/Nix.git] / modules / private / system / eldiron.nix
1 { privateFiles }:
2 { config, pkgs, lib, ... }:
3 {
4 boot.supportedFilesystems = [ "zfs" ];
5 boot.kernelParams = ["zfs.zfs_arc_max=6442450944"];
6 boot.kernelPackages = pkgs.linuxPackages_latest;
7 myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; };
8
9 fileSystems = {
10 "/" = lib.mkForce { fsType = "zfs"; device = "zpool/root"; };
11 "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/e6bb18fb-ff56-4b5f-ae9f-e60d40dc0622"; };
12 "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; };
13 "/nix" = { fsType = "zfs"; device = "zpool/root/nix"; };
14 "/tmp" = { fsType = "zfs"; device = "zpool/root/tmp"; };
15 "/var" = { fsType = "zfs"; device = "zpool/root/var"; };
16 };
17 boot.initrd.secrets = {
18 "/boot/pass.key" = "/boot/pass.key";
19 };
20
21 services.zfs = {
22 autoSnapshot = {
23 enable = true;
24 };
25 autoScrub = {
26 enable = true;
27 };
28 };
29 networking = {
30 hostId = "8262ca33"; # generated with head -c4 /dev/urandom | od -A none -t x4
31 firewall.enable = true;
32 # 176.9.151.89 declared in nixops -> infra / tools
33 interfaces."eth0".ipv4.addresses = pkgs.lib.attrsets.mapAttrsToList
34 (n: ips: { address = ips.ip4; prefixLength = 32; })
35 (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips);
36 interfaces."eth0".ipv6.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
37 (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or []))
38 config.hostEnv.ips);
39 };
40
41 imports = builtins.attrValues (import ../..);
42
43 boot.kernel.sysctl = {
44 # https://github.com/Netflix/security-bulletins/blob/master/advisories/third-party/2019-001.md
45 "net.ipv4.tcp_sack" = 0;
46 };
47 myServices.buildbot.enable = true;
48 myServices.databases.enable = true;
49 myServices.gitolite.enable = true;
50 myServices.monitoring.enable = true;
51 myServices.irc.enable = true;
52 myServices.pub.enable = true;
53 myServices.tasks.enable = true;
54 myServices.mpd.enable = true;
55 myServices.dns.enable = true;
56 myServices.certificates.enable = true;
57 myServices.websites.enable = true;
58 myServices.mail.enable = true;
59 myServices.ejabberd.enable = true;
60 myServices.vpn.enable = true;
61 services.pure-ftpd.enable = true;
62 services.duplyBackup.enable = true;
63 services.duplyBackup.profiles.oldies.rootDir = "/var/lib/oldies";
64
65 secrets.keys = [
66 {
67 dest = "rsync_backup/identity";
68 user = "root";
69 group = "root";
70 permissions = "0400";
71 text = config.myEnv.rsync_backup.ssh_key.private;
72 }
73 ];
74 programs.ssh.knownHosts.dilion = {
75 hostNames = ["dilion.immae.eu"];
76 publicKey = let
77 profile = config.myEnv.rsync_backup.profiles.dilion;
78 in
79 "${profile.host_key_type} ${profile.host_key}";
80 };
81
82 deployment = {
83 targetEnv = "hetzner";
84 hetzner = {
85 robotUser = config.myEnv.hetzner.user;
86 robotPass = config.myEnv.hetzner.pass;
87 mainIPv4 = config.hostEnv.ips.main.ip4;
88 partitions = ''
89 clearpart --all --initlabel --drives=sda,sdb
90
91 part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
92 part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb
93
94 part raid.1 --grow --ondisk=sda
95 part raid.2 --grow --ondisk=sdb
96
97 raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2
98 '';
99 };
100 };
101
102 services.cron = {
103 enable = true;
104 mailto = "cron@immae.eu";
105 systemCronJobs = [
106 ''
107 # The star after /var/lib/* avoids deleting all folders in case of problem
108 0 3,9,15,21 * * * root rsync -e "ssh -i /var/secrets/rsync_backup/identity" --new-compress -aAXv --delete --numeric-ids --super --rsync-path="sudo rsync" /var/lib/* backup@dilion.immae.eu: > /dev/null
109 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtpd -g "immae.eu.*Recipient address rejected"
110 # Need a way to blacklist properly
111 # 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtpd -g "NOQUEUE:"
112 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtp -g "status=bounced"
113 ''
114 ];
115 };
116
117 fileSystems."/var/lib/pub/immae/devtools" = {
118 device = "/run/current-system/sw/bin/bindfs#/var/lib/ftp/devtools.immae.eu/";
119 fsType = "fuse";
120 options = [ "force-user=pub" "create-for-user=wwwrun" "create-for-group=wwwrun" ];
121 };
122 environment.systemPackages = [ pkgs.bindfs ];
123
124 # This value determines the NixOS release with which your system is
125 # to be compatible, in order to avoid breaking some software such as
126 # database servers. You should change this only after NixOS release
127 # notes say you should.
128 # https://nixos.org/nixos/manual/release-notes.html
129 system.stateVersion = "20.03"; # Did you read the comment?
130 }