1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-25 03:09:47 +01:00

atuin: configure daemon using systemd and launchd

This configures the atuin daemon for Linux and Darwin systems using
systemd and launchd, respectively. For systemd, a socket is also
automatically configured to exist at atuin's default socket location.
This commit is contained in:
Varun Narravula 2024-10-08 12:39:25 -07:00 committed by Robert Helgesson
parent bf23fe4108
commit 092b81b956
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED

View file

@ -8,6 +8,7 @@ let
tomlFormat = pkgs.formats.toml { };
inherit (pkgs.stdenv) isLinux isDarwin;
in {
meta.maintainers = [ maintainers.hawkw ];
@ -94,11 +95,13 @@ in {
Whether to enable Nushell integration.
'';
};
daemon.enable = mkEnableOption "atuin daemon";
};
config = let flagsStr = escapeShellArgs cfg.flags;
in mkIf cfg.enable {
in mkIf cfg.enable (mkMerge [
{
# Always add the configured `atuin` package.
home.packages = [ cfg.package ];
@ -138,5 +141,63 @@ in {
source ${config.xdg.cacheHome}/atuin/init.nu
'';
};
}
(mkIf cfg.daemon.enable (mkMerge [
{
assertions = [{
assertion = isLinux || isDarwin;
message =
"The atuin daemon can only be configured on either Linux or macOS.";
}];
programs.atuin.settings = { daemon = { enabled = true; }; };
}
(mkIf isLinux {
programs.atuin.settings = { daemon = { systemd_socket = true; }; };
systemd.user.services.atuin-daemon = {
Unit = {
Description = "atuin daemon";
Requires = [ "atuin-daemon.socket" ];
};
Install = {
Also = [ "atuin-daemon.socket" ];
WantedBy = [ "default.target" ];
};
Service = {
ExecStart = "${lib.getExe cfg.package} daemon";
Environment = [ "ATUIN_LOG=info" ];
Restart = "on-failure";
RestartSteps = 3;
RestartMaxDelaySec = 6;
};
};
systemd.user.sockets.atuin-daemon = {
Unit = { Description = "atuin daemon socket"; };
Install = { WantedBy = [ "sockets.target" ]; };
Socket = {
ListenStream = "%h/.local/share/atuin/atuin.sock";
SocketMode = "0600";
RemoveOnStop = true;
};
};
})
(mkIf isDarwin {
launchd.agents.atuin-daemon = {
enable = true;
config = {
ProgramArguments = [ "${lib.getExe cfg.package}" "daemon" ];
EnvironmentVariables = { ATUIN_LOG = "info"; };
KeepAlive = {
Crashed = true;
SuccessfulExit = false;
};
ProcessType = "Background";
};
};
})
]))
]);
}