bad.net.ru.nix 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. { config, pkgs, inputs, ... }:
  2. let
  3. dns = "regru";
  4. domain = "bad.net.ru";
  5. email = "badya65@gmail.com";
  6. homepage.root = "/system/data/homepage";
  7. public = {
  8. alias = "/system/data/pub/";
  9. extraConfig = ''
  10. fancyindex on;
  11. fancyindex_exact_size on;
  12. directio 4M;
  13. '';
  14. };
  15. in {
  16. roles.server = {
  17. inherit domain;
  18. forgejo.enable = true;
  19. miniflux = {
  20. enable = true;
  21. adminCredentialsFile = config.age.secrets.miniflux.path;
  22. };
  23. nginx.enable = true;
  24. };
  25. age.secrets = with inputs.self.modules; {
  26. ${dns}.file = secrets.${dns};
  27. miniflux.file = secrets.miniflux;
  28. nix-serve.file = secrets."nix.bad.net.ru-1";
  29. };
  30. services.nix-serve = {
  31. enable = true;
  32. package = pkgs.nix-serve;
  33. secretKeyFile = config.age.secrets.nix-serve.path;
  34. };
  35. security.acme.certs.${domain} = {
  36. credentialFiles.REGRU_PASSWORD_FILE = config.age.secrets.${dns}.path;
  37. environmentFile = pkgs.writeText "${dns}-env" ''
  38. REGRU_USERNAME=${email}
  39. REGRU_POLLING_INTERVAL=10
  40. REGRU_PROPAGATION_TIMEOUT=3600
  41. '';
  42. domain = "*." + domain;
  43. dnsPropagationCheck = true;
  44. dnsProvider = dns;
  45. dnsResolver = "ns1.reg.ru:53";
  46. inherit email;
  47. extraDomainNames = [ domain ];
  48. inherit (config.security.acme.defaults) group;
  49. # server = "https://acme-staging-v02.api.letsencrypt.org/directory";
  50. };
  51. services.nginx.virtualHosts = {
  52. ${domain} = {
  53. forceSSL = true;
  54. enableACME = true;
  55. acmeRoot = null;
  56. locations."/" = homepage;
  57. locations."/pub/" = public;
  58. extraConfig = ''
  59. add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
  60. '';
  61. };
  62. "nix.${domain}" = {
  63. forceSSL = true;
  64. useACMEHost = domain;
  65. locations."/".proxyPass = "http://${config.services.nix-serve.bindAddress}:${toString config.services.nix-serve.port}";
  66. };
  67. "*.${domain}" = {
  68. default = true;
  69. forceSSL = true;
  70. useACMEHost = domain;
  71. globalRedirect = domain;
  72. };
  73. };
  74. }