feat: Add nginx module
Change-Id: I34fbb926c4b7eab344c1c14de4e4b5f82c6c30eb
Reviewed-on: https://git.clicks.codes/c/Infra/NixFiles/+/785
Reviewed-by: Samuel Shuert <coded@clicks.codes>
Tested-by: Skyler Grey <minion@clicks.codes>
diff --git a/lib/nginx/http/default.nix b/lib/nginx/http/default.nix
new file mode 100644
index 0000000..ad0e822
--- /dev/null
+++ b/lib/nginx/http/default.nix
@@ -0,0 +1,53 @@
+# SPDX-FileCopyrightText: 2024 Clicks Codes
+#
+# SPDX-License-Identifier: GPL-3.0-only
+
+{ lib, inputs, ... }:
+{
+ nginx.http = let
+ _directory = listContents: root: {
+ inherit root listContents;
+ _type = "directory";
+ headers = null;
+ };
+ _redirect = permanent: to: {
+ inherit to permanent;
+ _type = "redirect";
+ headers = null;
+ };
+ _reverseProxy = protocol: host: port: {
+ inherit protocol host port;
+ _type = "reverseProxy";
+ headers = null;
+ };
+ in {
+ # Header Manipulation
+ addHeader = name: value: content: {
+ inherit name value content;
+ _type = "header";
+ };
+ unsafeAddCrossOriginHeader = lib.clicks.nginx.http.addHeader "Access-Control-Allow-Origin" "*";
+
+ # Location translatable directives
+
+ directory = _directory true;
+ privateDirectory = _directory false;
+
+ file = path: {
+ inherit path;
+ _type = "file";
+ };
+
+ redirect = _redirect false;
+ redirectPermanent = _redirect true;
+
+ reverseProxySecure = _reverseProxy "https";
+ reverseProxy = _reverseProxy "http";
+
+ status = code: {
+ inherit code;
+ _type = "status";
+ headers = null;
+ };
+ };
+}