summary refs log tree commit diff stats
path: root/system/linde.nix
diff options
context:
space:
mode:
Diffstat (limited to 'system/linde.nix')
-rw-r--r--system/linde.nix104
1 files changed, 96 insertions, 8 deletions
diff --git a/system/linde.nix b/system/linde.nix
index 2ae0b714..c0af9144 100644
--- a/system/linde.nix
+++ b/system/linde.nix
@@ -13,8 +13,10 @@ let
   net-gw = "172.31.1.1";
   net-ip6 = "2a01:4f8:c012:23a4::1";
   net-rdnsip = "2a01:4f8:c012:23a4::53";
+  net-acmeip = "2a01:4f8:c012:23a4::715";
   net-mask6 = "64";
   net-gw6 = "fe80::1";
+  domain = "alanpearce.eu";
   ts-domain = "hydra-pinecone.ts.net";
   golink = (builtins.getFlake (toString <golink>)).nixosModules.default;
 in
@@ -22,6 +24,7 @@ in
   imports =
     [
       <personal/modules/nixos/laminar.nix>
+      <personal/modules/nixos/goatcounter.nix>
       <home-manager/nixos>
       <agenix/modules/age.nix>
       <searchix/nix/modules>
@@ -155,6 +158,7 @@ in
 
   networking = {
     hostName = hostname;
+    inherit domain;
     useDHCP = false;
     dhcpcd.enable = false;
     nameservers = [
@@ -167,6 +171,7 @@ in
       ${net-ip4} = [ "${hostname}.alanpearce.eu" hostname ];
       ${net-ip6} = [ "${hostname}.alanpearce.eu" hostname ];
       ${net-rdnsip} = [ "dns" ];
+      ${net-acmeip} = [ "acme" ];
     };
     firewall = {
       enable = true;
@@ -224,6 +229,7 @@ in
         address = [
           "${net-ip6}/${net-mask6}"
           "${net-rdnsip}/${net-mask6}"
+          "${net-acmeip}/${net-mask6}"
         ];
         addresses = [{
           Address = "${net-ip4}/${net-mask4}";
@@ -344,6 +350,19 @@ in
   # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
   system.stateVersion = "23.05"; # Did you read the comment?
 
+  services.goatcounter = {
+    enable = true;
+    listenAddress = "localhost";
+    port = 8082;
+    package = (import <personal> { inherit pkgs; }).goatcounter;
+    settings = {
+      tls = "proxy";
+      websocket = true;
+      automigrate = true;
+      smtp = "smtp://localhost:25";
+    };
+  };
+
   services.powerdns =
     let
       inherit (lib.lists) flatten;
@@ -445,6 +464,24 @@ in
     };
   };
 
+  services.postfix =
+    let
+      localUser = "alan";
+      forwardingAddress = "alan@alanpearce.eu";
+    in
+    {
+      enable = true;
+      destination = [ ];
+      domain = config.networking.domain;
+      virtual = ''
+        @${config.networking.hostName}.${config.networking.domain} ${localUser}
+        ${localUser} ${forwardingAddress}
+      '';
+      config = {
+        inet_interfaces = "loopback-only";
+      };
+    };
+
   services.kresd = {
     enable = true;
     # package = pkgs.knot-resolver.override { extraFeatures = true; };
@@ -580,11 +617,37 @@ in
     };
   };
 
+  services.acme-dns = {
+    enable = true;
+    settings =
+      let
+        me = "acme.${domain}";
+      in
+      {
+        general = {
+          listen = "[${net-acmeip}]:53";
+          protocol = "both6";
+          domain = me;
+          nsname = me;
+          nsadmin = builtins.replaceStrings [ "@" ] [ "." ] config.security.acme.defaults.email;
+          records = [
+            "${me}. AAAA ${net-acmeip}"
+            "${me}. NS ${me}."
+          ];
+        };
+        api = {
+          ip = "[${net-acmeip}]";
+          tls = "letsencrypt";
+          port = 443;
+          notification-email = config.security.acme.defaults.email;
+        };
+      };
+  };
+
   security.acme = {
     defaults = {
       email = "alan@alanpearce.eu";
-      dnsProvider = "pdns";
-      dnsResolver = "1.1.1.1:53";
+      dnsProvider = "acme-dns";
       credentialsFile = config.age.secrets.acme.path;
       reloadServices = [ "caddy" ];
       validMinDays = 32;
@@ -597,6 +660,9 @@ in
       reloadServices = map (x: "kresd@${toString x}") (range 1 config.services.kresd.instances);
       group = "knot-resolver";
     };
+    certs."stats.alanpearce.eu" = {
+      extraDomainNames = [ "*.stats.alanpearce.eu" ];
+    };
   };
   users.groups.acme.members = [
     "caddy"
@@ -716,6 +782,7 @@ in
             ns = config.services.nix-serve;
           in
           {
+            useACMEHost = "alanpearce.eu";
             extraConfig = ''
               reverse_proxy ${ns.bindAddress}:${toString ns.port}
             '';
@@ -725,10 +792,31 @@ in
             srv = config.services.laminar;
           in
           {
+            useACMEHost = "alanpearce.eu";
             extraConfig = ''
               reverse_proxy ${srv.settings.bindHTTP}
             '';
           };
+        "stats.alanpearce.eu" =
+          let
+            srv = config.services.goatcounter;
+          in
+          {
+            useACMEHost = "stats.alanpearce.eu";
+            serverAliases = [ "*.stats.alanpearce.eu" ];
+            extraConfig = ''
+              reverse_proxy ${srv.listenAddress}:${toString srv.port}
+            '';
+          };
+        "go.alanpearce.eu" = {
+          useACMEHost = "alanpearce.eu";
+          extraConfig = ''
+            encode zstd gzip
+            ${security-headers {}}
+            root * /srv/http/go
+            file_server
+          '';
+        };
       };
   };
   systemd.services.caddy.serviceConfig = {
@@ -926,17 +1014,17 @@ in
             {
               script-src = [
                 (baseURL + "/static/")
-                "https://gc.zgo.at"
+                "https://searchix.stats.alanpearce.eu"
                 "https://js-de.sentry-cdn.com"
                 "https://browser.sentry-cdn.com"
               ];
               img-src = [
                 self
-                "https://gc.zgo.at"
+                "https://searchix.stats.alanpearce.eu"
               ];
               connect-src = [
                 self
-                "https://searchix.goatcounter.com/count"
+                "https://searchix.stats.alanpearce.eu/count"
                 "*.sentry.io"
               ];
               worker-src = [
@@ -947,8 +1035,8 @@ in
             <script async
               src="https://js-de.sentry-cdn.com/d735e99613a86e1625fb85d0e8e762de.min.js"
               crossorigin="anonymous"></script>
-            <script data-goatcounter="https://searchix.goatcounter.com/count"
-                    async src="//gc.zgo.at/count.v4.js"
+            <script data-goatcounter="https://searchix.stats.alanpearce.eu/count"
+                    async src="//searchix.stats.alanpearce.eu/count.v4.js"
                     crossorigin="anonymous"
                     integrity="sha384-nRw6qfbWyJha9LhsOtSb2YJDyZdKvvCFh0fJYlkquSFjUxp9FVNugbfy8q1jdxI+"></script>
           '';
@@ -997,7 +1085,7 @@ in
     enable = true;
     path = with pkgs; [
       bash
-      stdenv
+      coreutils
       git
       cached-nix-shell
       nix