Skip to content

Commit

Permalink
Add adminsFile to obsidian
Browse files Browse the repository at this point in the history
  • Loading branch information
pniedzwiedzinski committed Oct 17, 2024
1 parent d4b09c5 commit 696ab47
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions modules/obsidian-livesync.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, ... }:
{ config, lib, pkgs, ... }:
let
cfg = config.services.obsidian-livesync;
couchdb-port = config.services.couchdb.port or 5984;
Expand All @@ -13,10 +13,13 @@ in
description = "This option is required and must be set by the user.";
};

couchdb.adminPass = lib.mkOption {
description = "Couchdb password.";
default = "";
type = lib.types.str;
adminsFile = lib.mkOption {
type = lib.types.path;
description = "File with authentication data";
example = ''
[admins]
admin = strongPassword
'';
};

couchdb.databaseDir = lib.mkOption {
Expand All @@ -30,17 +33,24 @@ in
config = lib.mkIf cfg.enable {
services.couchdb = {
enable = true;
adminPass = cfg.couchdb.adminPass;
databaseDir = cfg.couchdb.databaseDir;
configFile = cfg.adminsFile;
extraConfig = ''
[couchdb]
database_dir = ${cfg.couchdb.databaseDir}
single_node=true
max_document_size = 50000000
uri_file = ${config.services.couchdb.uriFile}
view_index_dir = ${config.services.couchdb.viewIndexDir}
[log]
file = ${config.services.couchdb.logFile}
[chttpd]
require_valid_user = true
max_http_request_size = 4294967296
enable_cors = true
port = ${toString config.services.couchdb.port}
bind_address = ${config.services.couchdb.bindAddress}
[chttpd_auth]
require_valid_user = true
Expand Down Expand Up @@ -76,6 +86,14 @@ in
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
add_header Access-Control-Allow-Credentials "true";
add_header Access-Control-Max-Age 86400;
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin "app://obsidian.md";
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
add_header Access-Control-Allow-Credentials "true";
return 204;
}
'';
};
};
Expand Down

0 comments on commit 696ab47

Please sign in to comment.