about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2024-10-17 09:25:38 +0200
committerPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2024-10-17 09:25:38 +0200
commit4de7acbf631e6be8fa5b7de9673b81dbe99a1895 (patch)
treefb20c48cac7e7e84c45d5503be5a4b6c7901f9e2
parentc118fd723fd75ea88b37f42cc0881d57537feacc (diff)
downloaddots-4de7acbf631e6be8fa5b7de9673b81dbe99a1895.tar.gz
dots-4de7acbf631e6be8fa5b7de9673b81dbe99a1895.zip
Add obsidian-livesync module
-rw-r--r--flake.nix1
-rw-r--r--modules/obsidian-livesync.nix57
2 files changed, 58 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
index c00fd1e..30a179c 100644
--- a/flake.nix
+++ b/flake.nix
@@ -73,6 +73,7 @@
 				}
 
 			];
+			srv3 = nixosSystem "x86_64-linux" "srv3" [];
 		};
 	};
 }
diff --git a/modules/obsidian-livesync.nix b/modules/obsidian-livesync.nix
new file mode 100644
index 0000000..0afb9c1
--- /dev/null
+++ b/modules/obsidian-livesync.nix
@@ -0,0 +1,57 @@
+{ config, lib, ... }:
+let
+	cfg = config.services.obsidian-livesync;
+in
+{
+	options = {
+		services.obsidian-livesync = {
+			enable = lib.mkEnableOption "Obsidian Livesync Host";
+
+			domain = lib.mkOption {
+			    type = lib.types.str;
+			    description = "This option is required and must be set by the user.";
+			    default = lib.mkDefault null;
+			};
+
+			couchdb.adminPass = lib.mkOption {
+				description = "Couchdb password.";
+				default = "";
+				type = lib.types.str;
+			};
+
+			couchdb.databaseDir = lib.mkOption {
+				description = "Specifies location of CouchDB database files (*.couch named). This location should be writable and readable for the user the CouchDB service runs as (couchdb by default).";
+				default = "/srv/couchdb";
+				type = lib.types.path;
+			};
+		};
+	};
+
+	config = lib.mkIf cfg.enable (
+	lib.mkIf (cfg.domain == null)
+	(throw "You must set `services.obsidian-livesync.domain` to use this service")
+	{
+		services.couchdb = {
+			enable = true;
+			adminPass = cfg.couchdb.adminPass;
+			databaseDir = cfg.couchdb.databaseDir;
+		};
+
+		services.nginx = {
+			enable = true;
+			virtualHost.${cfg.domain} = {
+				enableACME = true;
+				forceSSL = true;
+				locations."/" = {
+					proxyPass = "http://127.0.0.1:${config.services.couchdb.port}";
+				        proxySetHeader = {
+						  Host = "$host";
+						  X-Real-IP = "$remote_addr";
+						  X-Forwarded-For = "$proxy_add_x_forwarded_for";
+						  X-Forwarded-Proto = "$scheme";
+					};
+				};
+			};
+		};
+	});
+}