X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fprivate%2Fsystem%2Feldiron.nix;h=83e52b8989636d50328060d97412329c2bfc0f66;hb=5dda316b382211733cda7163b33bf388dd052671;hp=bf4cefb14cf9a291530274caed746843d4aa89e5;hpb=4227853a03923e04daf3dd511a4b5a1ab5d527e7;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/system/eldiron.nix b/modules/private/system/eldiron.nix index bf4cefb..83e52b8 100644 --- a/modules/private/system/eldiron.nix +++ b/modules/private/system/eldiron.nix @@ -1,19 +1,38 @@ { privateFiles }: -{ config, pkgs, myconfig, ... }: +{ config, pkgs, lib, ... }: { + boot.supportedFilesystems = [ "zfs" ]; + boot.kernelParams = ["zfs.zfs_arc_max=6442450944"]; boot.kernelPackages = pkgs.linuxPackages_latest; - _module.args.privateFiles = privateFiles; - _module.args.hostFQDN = "eldiron.immae.eu"; + myEnv = import "${privateFiles}/environment.nix" // { inherit privateFiles; }; + fileSystems = { + "/" = lib.mkForce { fsType = "zfs"; device = "zpool/root"; }; + "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/e6bb18fb-ff56-4b5f-ae9f-e60d40dc0622"; }; + "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; }; + "/nix" = { fsType = "zfs"; device = "zpool/root/nix"; }; + "/tmp" = { fsType = "zfs"; device = "zpool/root/tmp"; }; + "/var" = { fsType = "zfs"; device = "zpool/root/var"; }; + }; + boot.initrd.secrets = { + "/boot/pass.key" = "/boot/pass.key"; + }; + + services.zfs = { + autoScrub = { + enable = true; + }; + }; networking = { + hostId = "8262ca33"; # generated with head -c4 /dev/urandom | od -A none -t x4 firewall.enable = true; # 176.9.151.89 declared in nixops -> infra / tools interfaces."eth0".ipv4.addresses = pkgs.lib.attrsets.mapAttrsToList (n: ips: { address = ips.ip4; prefixLength = 32; }) - (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") myconfig.env.servers.eldiron.ips); + (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips); interfaces."eth0".ipv6.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or [])) - myconfig.env.servers.eldiron.ips); + config.hostEnv.ips); }; imports = builtins.attrValues (import ../..); @@ -34,15 +53,35 @@ myServices.certificates.enable = true; myServices.websites.enable = true; myServices.mail.enable = true; + myServices.ejabberd.enable = true; + myServices.vpn.enable = true; services.pure-ftpd.enable = true; services.duplyBackup.enable = true; + services.duplyBackup.profiles.oldies.rootDir = "/var/lib/oldies"; + + secrets.keys = [ + { + dest = "zrepl_backup/identity"; + user = "root"; + group = "root"; + permissions = "0400"; + text = config.myEnv.zrepl_backup.ssh_key.private; + } + ]; + programs.ssh.knownHosts.dilion = { + hostNames = ["dilion.immae.eu"]; + publicKey = let + profile = config.myEnv.rsync_backup.profiles.dilion; + in + "${profile.host_key_type} ${profile.host_key}"; + }; deployment = { targetEnv = "hetzner"; hetzner = { - robotUser = myconfig.env.hetzner.user; - robotPass = myconfig.env.hetzner.pass; - mainIPv4 = myconfig.env.servers.eldiron.ips.main.ip4; + robotUser = config.myEnv.hetzner.user; + robotPass = config.myEnv.hetzner.pass; + mainIPv4 = config.hostEnv.ips.main.ip4; partitions = '' clearpart --all --initlabel --drives=sda,sdb @@ -62,16 +101,79 @@ mailto = "cron@immae.eu"; systemCronJobs = [ '' - # The star after /var/lib/* avoids deleting all folders in case of problem - 0 3,9,15,21 * * * root rsync -e "ssh -i /root/.ssh/id_charon_vpn" -aAXvz --delete --numeric-ids --super --rsync-path="sudo rsync" /var/lib/* immae@immae.eu: > /dev/null + 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtpd -g "immae.eu.*Recipient address rejected" + # Need a way to blacklist properly + # 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtpd -g "NOQUEUE:" + 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtp -g "status=bounced" '' ]; }; + fileSystems."/var/lib/pub/immae/devtools" = { + device = "/run/current-system/sw/bin/bindfs#/var/lib/ftp/devtools.immae.eu/"; + fsType = "fuse"; + options = [ "force-user=pub" "create-for-user=wwwrun" "create-for-group=wwwrun" ]; + }; + environment.systemPackages = [ pkgs.bindfs ]; + + services.zrepl = { + enable = true; + config = let + redis_dump = pkgs.writeScript "redis-dump" '' + #! ${pkgs.stdenv.shell} + ${pkgs.redis}/bin/redis-cli bgsave + ''; + in '' + jobs: + - type: push + # must not change + name: "backup-to-dilion" + filesystems: + "zpool/root": true + "zpool/root/etc": true + "zpool/root/var<": true + connect: + type: ssh+stdinserver + host: dilion.immae.eu + user: backup + port: 22 + identity_file: ${config.secrets.fullPaths."zrepl_backup/identity"} + snapshotting: + type: periodic + prefix: zrepl_ + interval: 15m + hooks: + - type: mysql-lock-tables + dsn: "${config.myEnv.zrepl_backup.mysql.user}:${config.myEnv.zrepl_backup.mysql.password}@tcp(localhost)/" + filesystems: + "zpool/root/var": true + - type: command + path: ${redis_dump} + err_is_fatal: false + filesystems: + "zpool/root/var": true + send: + encrypted: true + pruning: + keep_sender: + - type: not_replicated + - type: regex + regex: "^manual_.*" + - type: grid + grid: 1x1h(keep=all) | 24x1h | 7x1d | 4x7d | 6x30d + regex: "^zrepl_.*" + keep_receiver: + - type: regex + regex: "^manual_.*" + - type: grid + grid: 1x1h(keep=all) | 24x1h | 7x1d | 4x7d | 6x30d + regex: "^zrepl_.*" + ''; + }; # This value determines the NixOS release with which your system is # to be compatible, in order to avoid breaking some software such as # database servers. You should change this only after NixOS release # notes say you should. # https://nixos.org/nixos/manual/release-notes.html - system.stateVersion = "19.03"; # Did you read the comment? + system.stateVersion = "20.03"; # Did you read the comment? }