default.nix 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. { config, pkgs, inputs, ... }:
  2. let
  3. user = "slark";
  4. in {
  5. imports = with inputs.self.modules; [
  6. ./disko.nix
  7. domains."fail2banana.ru"
  8. ];
  9. documentation = {
  10. doc.enable = false;
  11. man.enable = false;
  12. nixos.enable = false;
  13. };
  14. nixpkgs.hostPlatform = "x86_64-linux";
  15. boot = {
  16. initrd = {
  17. availableKernelModules = [
  18. "uhci_hcd" "ehci_pci" "ata_piix" "ahci" "firewire_ohci"
  19. "pata_jmicron" "usb_storage" "usbhid" "floppy" "sd_mod" "sr_mod"
  20. ];
  21. kernelModules = [ "kvm-intel" ];
  22. };
  23. loader = {
  24. grub = {
  25. enable = true;
  26. memtest86.enable = true;
  27. };
  28. timeout = 2;
  29. };
  30. zfs.devNodes = "/dev/disk/by-partlabel";
  31. };
  32. environment.persistence."/system/persist" = {
  33. directories = [
  34. "/etc/ssh"
  35. "/var/backup"
  36. "/var/db/sudo"
  37. "/var/lib"
  38. "/var/log"
  39. ];
  40. files = [
  41. "/etc/machine-id"
  42. ];
  43. };
  44. fileSystems = {
  45. "/etc/ssh" = {
  46. depends = [ "/system" ];
  47. neededForBoot = true;
  48. };
  49. "/system".neededForBoot = true;
  50. };
  51. age.secrets = with inputs.self.modules; {
  52. blackberry-wg0.file = secrets.blackberry-wg0;
  53. yama-wg0-blackberry.file = secrets.yama-wg0-blackberry;
  54. };
  55. networking = {
  56. hostId = "51a82d4c";
  57. hostName = "blackberry";
  58. dhcpcd.enable = true;
  59. useDHCP = true;
  60. firewall.allowedUDPPorts = [ 41820 ];
  61. wireguard.interfaces = {
  62. wg0 = {
  63. ips = [ "10.0.0.50/24" ];
  64. listenPort = 41820;
  65. privateKeyFile = config.age.secrets.blackberry-wg0.path;
  66. peers = [
  67. { # yama
  68. publicKey = "Tan9IHvGvzeHFBSg3ZnhqNuJFYtAB+hfybbh9SPWRwk=";
  69. presharedKeyFile = config.age.secrets.yama-wg0-blackberry.path;
  70. allowedIPs = [ "10.0.0.1/32" ];
  71. }
  72. ];
  73. };
  74. };
  75. };
  76. security = {
  77. polkit.extraConfig = ''
  78. polkit.addRule(function(action, subject) {
  79. if (subject.active && subject.isInGroup("wheel"))
  80. return polkit.Result.YES;
  81. });
  82. '';
  83. sudo.wheelNeedsPassword = false;
  84. };
  85. environment.etc = {
  86. "fail2ban/filter.d/nextcloud.local".text = ''
  87. [Definition]
  88. _groupsre = (?:(?:,?\s*"\w+":(?:"[^"]+"|\w+))*)
  89. failregex = ^.*\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Login failed:
  90. ^.*\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Trusted domain error.
  91. datepattern = ,?\s*"time"\s*:\s*"%%Y-%%m-%%d[T ]%%H:%%M:%%S(%%z)?"
  92. '';
  93. "fail2ban/filter.d/vaultwarden.local".text = ''
  94. [Definition]
  95. failregex = ^.*Username or password is incorrect\. Try again\. IP: <ADDR>\. Username: <F-USER>.*</F-USER>\.$
  96. ignoreregex =
  97. '';
  98. };
  99. programs.atop.netatop.enable = true;
  100. services = {
  101. btrfs.autoScrub = {
  102. enable = true;
  103. fileSystems = [ "/system" ];
  104. };
  105. fail2ban = {
  106. enable = true;
  107. bantime-increment.enable = true;
  108. ignoreIP = [ "192.168.0.0/16" ];
  109. jails = {
  110. nextcloud.settings = {
  111. backend = "systemd";
  112. bantime = 600;
  113. filter = "nextcloud";
  114. findtime = 600;
  115. port = "443";
  116. protocol = "tcp";
  117. };
  118. vaultwarden.settings = {
  119. backend = "systemd";
  120. bantime = 600;
  121. filter = "vaultwarden";
  122. findtime = 600;
  123. port = "443";
  124. protocol = "tcp";
  125. };
  126. };
  127. };
  128. openssh.enable = true;
  129. postgresql.package = pkgs.postgresql_16;
  130. postgresqlBackup = {
  131. enable = true;
  132. compression = "zstd";
  133. startAt = "04:00";
  134. };
  135. restic.backups.localbackup = {
  136. exclude = [ "all.prev.sql.zstd" ];
  137. initialize = true;
  138. passwordFile = "/data/secrets/restic-password";
  139. paths = [
  140. config.services.postgresqlBackup.location
  141. ];
  142. pruneOpts = [ "--keep-last 60" ];
  143. repository = "/data/backups";
  144. timerConfig = {
  145. OnCalendar = "04:30";
  146. Persistent = true;
  147. };
  148. };
  149. zfs.autoScrub = {
  150. enable = true;
  151. pools = [ "datapool" ];
  152. };
  153. };
  154. zramSwap.enable = true;
  155. users.users = {
  156. ${user} = {
  157. extraGroups = [ "wheel" "audio" "video" ];
  158. initialPassword = user;
  159. isNormalUser = true;
  160. openssh.authorizedKeys.keys = import inputs.self.modules.keys.aya;
  161. };
  162. root.initialPassword = user;
  163. };
  164. home-manager.users.${user} = {};
  165. }