blob: 5cafe0373b9bbbc81e51977ed3fcf9263ac7aa4c (
plain) (
blame)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
{turtlePkg}: {
config,
pkgs,
lib,
...
}: let
cfg = config.programs.turtle;
tomlFormat = pkgs.formats.toml {};
inherit
(lib)
mkIf
mkOption
types
;
in {
options.programs.turtle = {
enable = lib.mkEnableOption "turtle";
package = (lib.mkPackageOption pkgs "turtle" {}) // {default = turtlePkg;};
syncFrequency = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = "*:0/5";
description = ''
How often to run `turtle sync perform`. If null, will not sync automatically at
all.
This value is passed to the systemd timer configuration as the `OnCalendar` option.
See {manpage}`systemd.time(7)` for more information about the format.
'';
};
settings = mkOption {
type = with types; let
prim = oneOf [
bool
int
str
];
primOrPrimAttrs = either prim (attrsOf prim);
entry = either prim (listOf primOrPrimAttrs);
entryOrAttrsOf = t: either entry (attrsOf t);
entries = entryOrAttrsOf (entryOrAttrsOf entry);
in
attrsOf entries // {description = "Turtle configuration";};
default = {};
example = lib.literalExpression ''
{
auto_sync = true;
sync_frequency = "5m";
sync_address = "https://api.atuin.sh";
search_mode = "prefix";
}
'';
description = ''
Configuration written to
{file}`$XDG_CONFIG_HOME/turtle/config.toml`.
'';
};
daemon = {
logLevel = mkOption {
default = null;
type = types.nullOr (
types.enum [
"trace"
"debug"
"info"
"warn"
"error"
]
);
description = ''
Verbosity of Turtle daemon logging.
'';
};
};
};
config = mkIf cfg.enable {
assertions = [
{
assertion = config.systemd.user.enable || config.launchd.enable;
message = "The Turtle daemon can only be configured on systems with systemd or launchd.";
}
];
# Always add the configured `turtle` package.
home.packages = [cfg.package];
# If there are user-provided settings, generate the config file.
xdg.configFile = lib.mkMerge [
(mkIf (cfg.settings != {}) {
"turtle/config.toml" = {
source = tomlFormat.generate "turtle-config" cfg.settings;
};
})
];
programs.turtle.settings.daemon = {
systemd_socket = config.systemd.user.enable;
socket_path = lib.mkIf (!config.systemd.user.enable) (
lib.mkDefault "${config.xdg.dataHome}/turtle/daemon.sock"
);
};
systemd = {
user = {
services.turtle-daemon = {
Unit = {
Description = "Turtle daemon";
Requires = ["turtle-daemon.socket"];
};
Install = {
Also = ["turtle-daemon.socket"];
WantedBy = ["default.target"];
};
Service = {
ExecStart = "${lib.getExe' cfg.package "turtle-daemon"} start";
Environment = lib.optionals (cfg.daemon.logLevel != null) ["ATUIN_LOG=${cfg.daemon.logLevel}"];
Restart = "on-failure";
RestartSteps = 3;
RestartMaxDelaySec = 6;
};
};
sockets.turtle-daemon = {
Unit = {
Description = "Turtle daemon socket";
};
Install = {
WantedBy = ["sockets.target"];
};
Socket = {
ListenStream = "%t/turtle.sock";
SocketMode = "0600";
RemoveOnStop = true;
};
};
services.turtle-sync = {
Unit = {
Description = "turtle sync";
};
Service = {
CPUSchedulingPolicy = "idle";
IOSchedulingClass = "idle";
ExecStart = "${lib.getExe' cfg.package "turtle"} sync perform";
};
};
timers.turtle-sync = {
Unit = {
Description = "Turtle periodic sync";
};
Timer = {
Unit = "turtle-sync.service";
OnCalendar = cfg.frequency;
};
Install = {
WantedBy = ["timers.target"];
};
};
};
};
};
}
|