aboutsummaryrefslogtreecommitdiff
path: root/modules/services
diff options
context:
space:
mode:
authorsefidel <contact@sefidel.net>2023-12-04 19:32:56 +0900
committersefidel <contact@sefidel.net>2023-12-04 20:10:33 +0900
commita1d4df15182a160adeb411623c8bd29d60c7b7cf (patch)
tree7735ad2eeb839a391adcdcd130706b51aff51d63 /modules/services
parentb2afda8202e5316d9e5310792b555941cadb5d5f (diff)
downloadinfra-a1d4df15182a160adeb411623c8bd29d60c7b7cf.zip
feat(modules/obsidian-livesync): init
Diffstat (limited to 'modules/services')
-rw-r--r--modules/services/obsidian-livesync.nix63
1 files changed, 63 insertions, 0 deletions
diff --git a/modules/services/obsidian-livesync.nix b/modules/services/obsidian-livesync.nix
new file mode 100644
index 0000000..3377069
--- /dev/null
+++ b/modules/services/obsidian-livesync.nix
@@ -0,0 +1,63 @@
+ { config, lib, ... }:
+
+ with lib;
+ let
+ cfg = config.modules.services.obsidian-livesync;
+
+ port = 5984;
+ in
+ {
+ options.modules.services.obsidian-livesync = {
+ enable = mkEnableOption "obsidian-livesync server";
+
+ domain = mkOption { type = types.str; };
+ realHost = mkOption { type = types.str; default = "obsidian-livesync.${cfg.domain}"; };
+ };
+
+ config = mkIf cfg.enable {
+ services.couchdb = {
+ enable = true;
+ configFile = "/var/lib/couchdb/config";
+
+ extraConfig = ''
+ [couchdb]
+ single_node=true
+ max_document_size = 50000000
+
+ [admins]
+ admin = please-change-me
+
+ [chttpd]
+ require_valid_user = true
+ max_http_request_size = 4294967296
+ enable_cors = true
+
+ [chttpd_auth]
+ require_valid_user = true
+ authentication_redirect = /_utils/session.html
+
+ [httpd]
+ WWW-Authenticate = Basic realm="couchdb"
+ bind_address = 127.0.0.1
+ port = ${toString port}
+
+ [cors]
+ origins = app://obsidian.md, capacitor://localhost, http://localhost
+ credentials = true
+ headers = accept, authorization, content-type, origin, referer
+ methods = GET,PUT,POST,HEAD,DELETE
+ max_age = 3600
+ '';
+ };
+
+ environment.persistence."/persist".directories = [
+ "/var/lib/couchdb"
+ ];
+
+ services.nginx.virtualHosts.${cfg.realHost} = {
+ useACMEHost = cfg.domain;
+ forceSSL = true;
+ locations."/".proxyPass = "http://localhost:${toString port}";
+ };
+ };
+}