Getting the daemon working on NixOS

I recently decided to try out the new atuin daemon since I have been having some trouble with timeouts on zfs.

atuin daemon works fine when launched from the console, however, I’ve been struggling to get it to work as a systemd service. I’ve never set one up before so there’s a good chance I’m getting a few things wrong.

I set up the service with the following NixOS configuration:

systemd.services.atuin = {
  enable = true;

  environment = {
    HOME = "/home/ethan";
    ATUIN_LOG = "info";
  };
  serviceConfig = {
    ExecStart = "${pkgs.atuin}/bin/atuin daemon";
  };
  wantedBy = [ "multi-user.target" ];
  wants = [ "network.target" ];
};

And this atuin/config.toml:

[daemon]
enabled = true
socket_path = "/home/ethan/.local/share/atuin/atuin.sock"

The service starts successfully:

● atuin.service
     Loaded: loaded (/etc/systemd/system/atuin.service; enabled; preset: enabled)
     Active: active (running) since Thu 2024-05-23 22:10:17 BST; 13min ago
   Main PID: 343103 (atuin)
         IP: 19.1K in, 4.0K out
         IO: 0B read, 0B written
      Tasks: 4 (limit: 38415)
     Memory: 8.2M (peak: 8.9M)
        CPU: 89ms
     CGroup: /system.slice/atuin.service
             └─343103 /nix/store/h29ks5ll84qrc8pr56adk4k6xhb96mi7-atuin/bin/atuin daemon

May 23 22:10:17 nixos-desktop systemd[1]: Started atuin.service.
May 23 22:10:17 nixos-desktop atuin[343103]: 2024-05-23T21:10:17.038017Z  INFO atuin_daemon::server: listening on unix socket "/home/ethan/.local/share/atuin/atuin.sock"
May 23 22:10:17 nixos-desktop atuin[343103]: 2024-05-23T21:10:17.038084Z  INFO atuin_daemon::server::sync: booting sync worker
May 23 22:10:17 nixos-desktop atuin[343103]: 2024-05-23T21:10:17.039188Z  INFO atuin_daemon::server::sync: sync worker tick
May 23 22:10:17 nixos-desktop atuin[343103]: 2024-05-23T21:10:17.191047Z  INFO atuin_daemon::server::sync: sync complete uploaded=0 downloaded=[]

However I’m still getting errors after every command:

Error: failed to connect to local atuin daemon. Is it running?

Location:
    /build/source/crates/atuin-daemon/src/client.rs:31:26

Is there something I’m configuring incorrectly?

1 Like

You’re starting the daemon as a system service; you want it as a user service under your userid. The client failure will be file permissions on the socket.

3 Likes

Oh I see. Thanks that helped.

One other thing I was missing was that I needed to run systemctl status with --user.

In case anyone finds this post with the same struggle, here’s the working configuration I ended up with.

systemd.user.services.atuind = {
  enable = true;

  environment = {
    ATUIN_LOG = "info";
  };
  serviceConfig = {
    ExecStart = "${pkgs.atuin}/bin/atuin daemon";
  };
  after = [ "network.target" ];
  wantedBy = [ "default.target" ];
};
4 Likes