-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodule.nix
107 lines (90 loc) · 2.47 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{ config, options, lib, pkgs, ... }:
with lib;
let
cfg = config.services.zknotes;
opt = options.services.zknotes;
settingsFormat = pkgs.formats.toml { };
in
{
###### interface
options = {
services.zknotes = {
enable = mkEnableOption (lib.mdDoc "zknotes; markdown based multi user zettelkasten");
user = mkOption {
type = types.str;
default = "zknotes";
example = "zknotes-user";
description = "linux user account in which to run zknotes.";
};
group = lib.mkOption {
type = lib.types.str;
default = "zknotes";
description = lib.mdDoc "linux group under which zknotes runs.";
};
settings = lib.mkOption {
inherit (settingsFormat) type;
default = ''
ip = '127.0.0.1'
port = 8000
createdirs = true
altmainsite = []
file_tmp_path = './temp'
file_path = './files'
[orgauth_config]
mainsite = 'http://localhost:8000'
appname = 'zknotes'
emaildomain = 'zknotes.com'
db = './zknotes.db'
admin_email = '[email protected]'
regen_login_tokens = true
email_token_expiration_ms = 86400000
reset_token_expiration_ms = 86400000
invite_token_expiration_ms = 604800000
open_registration = false
send_emails = false
non_admin_invite = true
remote_registration = true
'';
description = ''
zknotes config.toml file.
'';
};
listenPort = mkOption {
type = types.nullOr types.int;
default = null;
example = 8011;
description = "Listen on a specific IP port.";
};
};
};
###### implementation
config = mkIf cfg.enable {
systemd.services.zknotes = {
description = "zknotes";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig.User = cfg.user;
serviceConfig.Group = cfg.group;
script = ''
cd "/home/${cfg.user}"
mkdir -p zknotes
cd zknotes
echo "${cfg.settings}" > config.toml
RUST_LOG=info ${pkgs.zknotes}/bin/zknotes-server -c config.toml
'';
};
users.groups = {
${cfg.group} = { };
};
users.users = lib.mkMerge [
(lib.mkIf (cfg.user == "zknotes") {
${cfg.user} = {
isSystemUser = true;
group = cfg.group;
home = "/home/${cfg.user}";
createHome = true;
};
})
];
};
}