summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--system/services/default.nix1
-rw-r--r--system/services/nginx/default.nix16
-rw-r--r--system/services/nginx/redirects.nix6
-rw-r--r--system/services/redirects/default.nix12
4 files changed, 21 insertions, 14 deletions
diff --git a/system/services/default.nix b/system/services/default.nix
index 974bb40..9998e43 100644
--- a/system/services/default.nix
+++ b/system/services/default.nix
@@ -14,7 +14,6 @@
     ./nix
     ./nix-sync
     ./openssh
-    ./redirects
     ./rust-motd
     ./snapper
     ./taskserver
diff --git a/system/services/nginx/default.nix b/system/services/nginx/default.nix
index 8544475..cc633ed 100644
--- a/system/services/nginx/default.nix
+++ b/system/services/nginx/default.nix
@@ -1,5 +1,17 @@
 {...}: let
   domains = import ./hosts.nix {};
+  importedRedirects = import ./redirects.nix {};
+  mkRedirect = {
+    key,
+    value,
+  }: {
+    name = key;
+    value = {
+      forceSSL = false;
+      enableACME = false;
+      locations."/".return = "301 ${value}";
+    };
+  };
   mkVirtHost = {
     domain,
     root,
@@ -27,6 +39,7 @@
 
   virtHosts = builtins.listToAttrs (builtins.map mkVirtHost domains);
   nixSyncRepositories = builtins.listToAttrs (builtins.map mkNixSyncRepository domains);
+  redirects = builtins.listToAttrs (builtins.map mkRedirect importedRedirects);
 in {
   security.acme = {
     acceptTerms = true;
@@ -41,7 +54,8 @@ in {
   };
   services.nginx = {
     enable = true;
-    virtualHosts = virtHosts;
+    # The merge here is fine, as no domain should be specified twice
+    virtualHosts = virtHosts // redirects;
   };
 
   services.nix-sync = {
diff --git a/system/services/nginx/redirects.nix b/system/services/nginx/redirects.nix
new file mode 100644
index 0000000..a021e72
--- /dev/null
+++ b/system/services/nginx/redirects.nix
@@ -0,0 +1,6 @@
+{...}: [
+  {
+    key = "source.vhack.eu";
+    value = "https://codeberg.org/vhack.eu/nixos-server";
+  }
+]
diff --git a/system/services/redirects/default.nix b/system/services/redirects/default.nix
deleted file mode 100644
index 2e175ea..0000000
--- a/system/services/redirects/default.nix
+++ /dev/null
@@ -1,12 +0,0 @@
-{...}: {
-  services.nginx = {
-    enable = true;
-    virtualHosts."source.vhack.eu" = {
-      # Redirect all request to the codeberg source
-      locations."/".return = "301 https://codeberg.org/vhack.eu/nixos-server";
-
-      enableACME = false;
-      forceSSL = false;
-    };
-  };
-}