aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-10-26 18:45:17 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-10-26 18:45:17 +0100
commitdacaadfdd38f09f6c119f4dad6ad5080afb7f3c5 (patch)
tree2133b1a998ab4c2eb05ad4c723a1926a6450f2e5
parentdirenv: Switch to `pre_cache` dev shell implementation (diff)
downloadatuin-dacaadfdd38f09f6c119f4dad6ad5080afb7f3c5.zip
nix/module.hm.nix: Add auto-sync service option
Otherwise, nothing is automatically syncing?
-rw-r--r--nix/module.hm.nix94
1 files changed, 66 insertions, 28 deletions
diff --git a/nix/module.hm.nix b/nix/module.hm.nix
index 1891abb6..5cafe037 100644
--- a/nix/module.hm.nix
+++ b/nix/module.hm.nix
@@ -20,6 +20,17 @@ in {
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 [
@@ -93,36 +104,63 @@ in {
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;
+ };
+ };
- 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;
+ };
+ };
- systemd.user.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"];
+ };
+ };
};
};
};