summary refs log tree commit diff stats
path: root/system/services/nginx/default.nix
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-10-14 16:18:32 +0200
committerSoispha <soispha@vhack.eu>2023-10-14 16:34:14 +0200
commitc77d2f4dbab0a30f2db60bf56501af6b7060085d (patch)
tree259dcc27c7ec0e9dac0072072ab0a93a8aecebb1 /system/services/nginx/default.nix
parentfix(system/services/redirects): disable ssl (diff)
downloadnixos-server-c77d2f4dbab0a30f2db60bf56501af6b7060085d.tar.gz
nixos-server-c77d2f4dbab0a30f2db60bf56501af6b7060085d.zip
refactor(system/services/redirects): Move under the nginx directory
Diffstat (limited to 'system/services/nginx/default.nix')
-rw-r--r--system/services/nginx/default.nix16
1 files changed, 15 insertions, 1 deletions
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 = {