summary refs log tree commit diff
path: root/host/Spacebar-nginx
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-02-19 06:16:55 +0100
committerRory& <root@rory.gay>2024-06-05 17:25:16 +0200
commitdb8f1c592903e1ac600d21b9448ded5bc46d3a77 (patch)
tree90ebec32a5a8c9af8cdc9c9c133ed2826eb88e35 /host/Spacebar-nginx
parentSwitch containers to nginx mainline (diff)
downloadSpacebar-Open-Infrastructure-db8f1c592903e1ac600d21b9448ded5bc46d3a77.tar.xz
Spacebar import - use variables
Diffstat (limited to 'host/Spacebar-nginx')
-rwxr-xr-xhost/Spacebar-nginx/configuration.nix7
-rw-r--r--host/Spacebar-nginx/containers/spacebar-server-dev-nix/import.nix71
2 files changed, 46 insertions, 32 deletions
diff --git a/host/Spacebar-nginx/configuration.nix b/host/Spacebar-nginx/configuration.nix
index 434b2ff..15c8ffc 100755
--- a/host/Spacebar-nginx/configuration.nix
+++ b/host/Spacebar-nginx/configuration.nix
@@ -4,7 +4,12 @@
   imports =
     [
       ../../modules/base.nix
-      (import ./containers/spacebar-server-dev-nix/import.nix { inherit config lib pkgs secrets; spacebar-server = spacebarchat-server-dev-nix; })
+      (import ./containers/spacebar-server-dev-nix/import.nix { 
+        inherit config lib pkgs secrets;
+        spacebar-server = spacebarchat-server-dev-nix;
+        containerName = "spacebar-server-dev-nix";
+        rootDomain = "dev-nix.server.spacebar.chat";
+      })
     ];
 
   networking = {
diff --git a/host/Spacebar-nginx/containers/spacebar-server-dev-nix/import.nix b/host/Spacebar-nginx/containers/spacebar-server-dev-nix/import.nix
index 5daacfb..7cc8763 100644
--- a/host/Spacebar-nginx/containers/spacebar-server-dev-nix/import.nix
+++ b/host/Spacebar-nginx/containers/spacebar-server-dev-nix/import.nix
@@ -1,41 +1,50 @@
-{ config, pkgs, lib, spacebar-server, secrets, ... }:
+{ 
+  config,
+  pkgs,
+  lib,
+  secrets,
+  spacebar-server,
+  containerName,
+  rootDomain,
+  ...
+}:
 
 {
-    containers."spacebarchat-server-dev-nix" = import ./container.nix {
-      inherit pkgs lib spacebar-server;
-    };
+  containers."${containerName}" = import ./container.nix {
+    inherit pkgs lib spacebar-server;
+  };
 
-    security.acme.certs."dev-nix.server.spacebar.chat" = {
-      domain = "dev-nix.server.spacebar.chat";
-      extraDomainNames = [ "*.dev-nix.server.spacebar.chat" ];
-      group = "nginx";
-      dnsProvider = "cloudflare";
-      credentialsFile = pkgs.writeTextFile {
-        name = "cloudflare-credentials";
-        text = ''
-          # Cloudflare API credentials used by lego
-          # https://go-acme.github.io/lego/dns/cloudflare/
-          CLOUDFLARE_DNS_API_TOKEN=${secrets.secret_keys.cloudflare_dns}
-        '';
-      };
+  security.acme.certs."${rootDomain}" = {
+    domain = "${rootDomain}";
+    extraDomainNames = [ "*.${rootDomain}" ];
+    group = "nginx";
+    dnsProvider = "cloudflare";
+    credentialsFile = pkgs.writeTextFile {
+      name = "cloudflare-credentials";
+      text = ''
+        # Cloudflare API credentials used by lego
+        # https://go-acme.github.io/lego/dns/cloudflare/
+        CLOUDFLARE_DNS_API_TOKEN=${secrets.secret_keys.cloudflare_dns}
+      '';
     };
+  };
 
-    services.nginx.virtualHosts."*.dev-nix.server.spacebar.chat" = {
-      serverName = "*.dev-nix.server.spacebar.chat";
-      useACMEHost = "dev-nix.server.spacebar.chat";
-      forceSSL = true;
-      locations."/" = {
-        proxyPass = "http://192.168.100.1";
-      };
+  services.nginx.virtualHosts."*.${rootDomain}" = {
+    serverName = "*.${rootDomain}";
+    useACMEHost = "${rootDomain}";
+    forceSSL = true;
+    locations."/" = {
+      proxyPass = "http://${containerName}.containers";
     };
-    services.nginx.virtualHosts."dev-nix.server.spacebar.chat" = {
-      serverName = "dev-nix.server.spacebar.chat";
-      useACMEHost = "dev-nix.server.spacebar.chat";
-      forceSSL = true;
-      locations."/" = {
-        proxyPass = "http://192.168.100.1";
-      };
+  };
+  services.nginx.virtualHosts."${rootDomain}" = {
+    serverName = "${rootDomain}";
+    useACMEHost = "${rootDomain}";
+    forceSSL = true;
+    locations."/" = {
+      proxyPass = "http://${containerName}.containers";
     };
+  };
 
   system.stateVersion = "22.11"; # DO NOT EDIT!
 }
\ No newline at end of file