1 { config, pkgs, lib, ports, name, secrets, ... }:
3 # ssh-keyscan eldiron | nix-shell -p ssh-to-age --run ssh-to-age
4 secrets.ageKeys = [ "age1dxr5lhvtnjssfaqpnf6qx80h8gfwkxg3tdf35m6n9wljmk7wadfs3kmahj" ];
6 kernelModules = [ "kvm-intel" ];
7 blacklistedKernelModules = [ "nvidiafb" ];
9 loader.grub.devices = [ "/dev/sda" "/dev/sdc" ];
11 # https://github.com/Netflix/security-bulletins/blob/master/advisories/third-party/2019-001.md
12 "net.ipv4.tcp_sack" = 0;
14 supportedFilesystems = [ "zfs" ];
15 kernelParams = ["zfs.zfs_arc_max=6442450944"];
16 kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
17 initrd.availableKernelModules = [ "ahci" "sd_mod" ];
19 "/boot/pass.key" = "/boot/pass.key";
22 services.udev.extraRules = ''
23 ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="c8:60:00:56:a0:88", NAME="eth0"
25 nix.settings.max-jobs = 8;
26 nixpkgs.config.permittedInsecurePackages = [
27 "python-2.7.18.6" # for nagios-cli
28 "nodejs-16.20.2" # for landing page building
31 nixpkgs.overlays = builtins.attrValues ports.overlays;
32 powerManagement.cpuFreqGovernor = "powersave";
34 security.acme.certs."${name}".postRun = builtins.concatStringsSep "\n" [
35 (lib.optionalString config.services.websites.env.production.enable "/run/current-system/sw/bin/machinectl shell httpd-production /usr/bin/env systemctl reload httpd.service")
36 (lib.optionalString config.services.websites.env.integration.enable "/run/current-system/sw/bin/machinectl shell httpd-integration /usr/bin/env systemctl reload httpd.service")
44 # zpool/: acltype=posixacl ; xattr=sa ; atime=off ; mountpoint=legacy
45 # zpool/root: encryption=on ; keyformat=passphrase ; keylocation=file:///boot/pass.key
46 # zpool/root/var: atime=on
47 # zfast/: acltype=posixacl ; xattr=sa ; atime=off ; mountpoint=legacy
48 # zfast/root: encryption=on ; keyformat=passphrase ; keylocation=file:///boot/pass.key
51 # zfast/root/tmp: async=disabled
52 # zfast/root/var: atime=on
53 # zfast/root/var/lib: ø
54 # zfast/root/var/lib/mysql: logbias=throughput ; atime=off ; primarycache=metadata
55 # zfast/root/var/lib/postgresql: recordsize=8K ; atime=off ; logbias=throughput
56 # zfast/root/var/lib/postgresql/11.0: ø
57 # zfast/root/var/lib/postgresql/11.0/pg_wal: ø
58 "/" = { fsType = "zfs"; device = "zpool/root"; };
59 "/boot" = { fsType = "ext4"; device = "/dev/disk/by-uuid/e6bb18fb-ff56-4b5f-ae9f-e60d40dc0622"; };
60 "/etc" = { fsType = "zfs"; device = "zpool/root/etc"; };
61 "/nix" = { fsType = "zfs"; device = "zfast/root/nix"; };
62 "/tmp" = { fsType = "zfs"; device = "zfast/root/tmp"; };
63 "/var" = { fsType = "zfs"; device = "zpool/root/var"; };
64 "/var/lib/mysql" = { fsType = "zfs"; device = "zfast/root/var/lib/mysql"; };
65 "/var/lib/postgresql" = { fsType = "zfs"; device = "zfast/root/var/lib/postgresql"; };
66 "/var/lib/postgresql/11.0" = { fsType = "zfs"; device = "zfast/root/var/lib/postgresql/11.0"; };
67 "/var/lib/postgresql/11.0/pg_wal" = { fsType = "zfs"; device = "zfast/root/var/lib/postgresql/11.0/pg_wal"; };
69 swapDevices = [ { label = "swap1"; } { label = "swap2"; } ];
70 hardware.enableRedistributableFirmware = true;
78 hostId = "8262ca33"; # generated with head -c4 /dev/urandom | od -A none -t x4
79 firewall.enable = true;
80 firewall.allowedTCPPorts = [ config.myEnv.ports.zrepl_flony ];
81 # FIXME: on next reboot, remove the /27 and the localCommands
82 interfaces."eth0".ipv4.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
83 (n: ips: map (ip: { address = ip; prefixLength = 32; }) (ips.ip4 or []))
84 (pkgs.lib.attrsets.filterAttrs (n: v: n != "main") config.hostEnv.ips))
85 ++ [ { address = lib.head config.hostEnv.ips.main.ip4; prefixLength = 27; } ];
86 interfaces."eth0".ipv6.addresses = pkgs.lib.flatten (pkgs.lib.attrsets.mapAttrsToList
87 (n: ips: map (ip: { address = ip; prefixLength = (if n == "main" && ip == pkgs.lib.head ips.ip6 then 64 else 128); }) (ips.ip6 or []))
89 defaultGateway = "176.9.151.65";
91 # FIXME: Those commands were added by nixops and may not be
93 ip -6 addr add '2a01:4f8:160:3445::/64' dev 'eth0' || true
94 ip -4 route change '176.9.151.64/27' via '176.9.151.65' dev 'eth0' || true
95 ip -6 route add default via 'fe80::1' dev eth0 || true
101 "2a01:4f8:0:a0a1::add:1010"
102 "2a01:4f8:0:a102::add:9999"
103 "2a01:4f8:0:a111::add:9898"
108 secrets.nixosModules.users-config-eldiron
110 ./databases/mariadb.nix
112 ./databases/postgresql.nix
113 ./databases/redis.nix
135 myServices.buildbot.enable = true;
136 myServices.databases.enable = true;
137 myServices.gitolite.enable = true;
138 myServices.monitoring.enable = true;
139 myServices.irc.enable = true;
140 myServices.pub.enable = true;
141 myServices.tasks.enable = true;
142 myServices.mpd.enable = true;
143 myServices.dns.enable = true;
144 myServices.websites.enable = true;
145 myServices.gemini.enable = true;
146 myServices.mail.enable = true;
147 myServices.ejabberd.enable = true;
148 myServices.vpn.enable = true;
149 myServices.ftp.enable = true;
151 myServices.chatonsProperties.hostings.infogerance = {
152 file.datetime = "2022-08-27T18:50:00";
154 name = "Infogérance";
155 description = "Administration de serveurs";
156 website = "https://www.immae.eu/";
157 logo = "https://assets.immae.eu/logo.jpg";
158 type = "HOSTEDSERVER";
160 status.description = "OK";
161 registration.load = "OPEN";
162 install.type = "PACKAGE";
170 permissions = "0400";
173 user = immae_auth_read
174 password = {{ .postgresql.immae_auth_read }}
178 auth_query = SELECT ((mechanism = 'SSHA' AND password = encode(digest( %p || salt, 'sha1'), 'hex')) OR (mechanism = 'PLAIN' AND password = %p)) FROM ldap_users WHERE login = %u OR login || '@' || realm = %u
179 #pwd_query = WITH newsalt as (select gen_random_bytes(4)) UPDATE ldap_users SET password = encode(digest( %p || (SELECT * FROM newsalt), 'sha1'), 'hex'), salt = (SELECT * FROM newsalt), mechanism = 'SSHA' WHERE login = %u OR login || '@' || realm = %u
183 "zrepl_backup/identity" = {
186 permissions = "0400";
187 text = config.myEnv.zrepl_backup.ssh_key.private;
189 "zrepl/${name}.key" = {
190 permissions = "0400";
191 text = config.myEnv.zrepl_backup.certs."${name}".key;
195 } // builtins.listToAttrs (map (x: lib.attrsets.nameValuePair "zrepl/certificates/${x}.crt" {
196 permissions = "0400";
197 text = config.myEnv.zrepl_backup.certs."${x}".certificate;
200 }) (builtins.attrNames config.myEnv.zrepl_backup.certs));
202 programs.ssh.knownHosts.dilion = {
203 extraHostNames = ["dilion.immae.eu"];
204 publicKey = config.myEnv.servers.dilion.hostKey;
209 mailto = "cron@immae.eu";
212 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtpd -g "immae.eu.*Recipient address rejected"
213 # Need a way to blacklist properly
214 # 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtpd -g "NOQUEUE:"
215 0 0 * * * root journalctl -q --since="25 hours ago" -u postfix -t postfix/smtp -g "status=bounced"
220 environment.systemPackages = [ pkgs.bindfs ];
222 environment.etc."mdadm.conf" = {
226 text = "MAILADDR ${config.myEnv.monitoring.email}";
229 systemd.services.zrepl.path = [ pkgs.openssh ];
237 name = "backup-to-dilion";
238 filesystems."zpool/root" = true;
239 filesystems."zpool/root/etc" = true;
240 filesystems."zpool/root/var<" = true;
242 address = "dilion.immae.eu:19000";
244 server_cn = "dilion";
245 ca = config.secrets.fullPaths."zrepl/certificates/dilion.crt";
246 cert = config.secrets.fullPaths."zrepl/certificates/eldiron.crt";
247 key = config.secrets.fullPaths."zrepl/eldiron.key";
255 # type = "mysql-lock-tables";
256 # dsn = "${config.myEnv.zrepl_backup.mysql.user}:${config.myEnv.zrepl_backup.mysql.password}@tcp(localhost)/";
257 # filesystems."zpool/root/var" = true;
261 # path = pkgs.writeScript "redis-dump" ''
262 # #!${pkgs.stdenv.shell}
263 # ${pkgs.redis}/bin/redis-cli bgsave
265 # err_is_fatal = false;
266 # filesystems."zpool/root/var" = true;
270 send.encrypted = true;
271 pruning.keep_sender = [
272 { type = "regex"; regex = "^manual_.*"; }
273 { type = "grid"; grid = "24x1h | 7x1d | 4x7d | 6x30d"; regex = "^zrepl_.*"; }
275 pruning.keep_receiver = [
276 { type = "regex"; regex = "^manual_.*"; }
277 { type = "grid"; grid = "6x4h | 7x1d | 4x7d | 6x30d"; regex = "^zrepl_.*"; }
283 name = "backup-to-wd-zpool";
285 serve.listen = ":${builtins.toString config.myEnv.ports.zrepl_flony}";
286 serve.ca = config.secrets.fullPaths."zrepl/certificates/flony.crt";
287 serve.cert = config.secrets.fullPaths."zrepl/certificates/eldiron.crt";
288 serve.key = config.secrets.fullPaths."zrepl/eldiron.key";
289 serve.client_cns = [ "flony" ];
290 filesystems."zpool/root" = true;
291 filesystems."zpool/root/etc" = true;
292 filesystems."zpool/root/var<" = true;
293 filesystems."zfast/root/var<" = true;
294 send.encrypted = true;
295 snapshotting.type = "manual";
301 environment.etc."fail2ban/filter.d/postgresql.conf".text = ''
303 failregex = <HOST> \S+ FATAL: password authentication failed for user .+$
304 <HOST> \S+ FATAL: PAM authentication failed for user.+$
305 <HOST> \S+ FATAL: no pg_hba.conf entry for host.+$
307 environment.etc."fail2ban/filter.d/mysqld-auth.local".text = ''
309 _daemon = mysql[-\w]*
311 services.fail2ban.jails.dovecot = ''
314 services.fail2ban.jails.postfix-sasl = ''
317 services.fail2ban.jails.proftpd = ''
320 services.fail2ban.jails.postgresql = ''
323 logpath = %(syslog_daemon)s
324 backend = %(default_backend)s
325 journalmatch = _SYSTEMD_UNIT=postgresql.service + _COMM=postgres
327 services.fail2ban.jails.mysqld-auth = ''
329 journalmatch = _SYSTEMD_UNIT=mysql.service + _COMM=mysqld
331 # This value determines the NixOS release with which your system is
332 # to be compatible, in order to avoid breaking some software such as
333 # database servers. You should change this only after NixOS release
334 # notes say you should.
335 # https://nixos.org/nixos/manual/release-notes.html
336 system.stateVersion = "23.05"; # Did you read the comment?
338 security.pam.services.ldap.text = ''
339 # Authentication from ldap for pgsql
340 auth required ${pkgs.pam_pgsql}/lib/security/pam_pgsql.so config_file=/var/secrets/ldap/pam_pgsql
341 account required ${pkgs.pam_pgsql}/lib/security/pam_pgsql.so config_file=/var/secrets/ldap/pam_pgsql
343 services.saslauthd = {
347 environment.etc."sasl2/slapd.conf".text = ''
349 pwcheck_method: saslauthd
350 saslauthd_path: /run/saslauthd/mux