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:
parent
bf23fe4108
commit
092b81b956
1 changed files with 99 additions and 38 deletions
|
@ -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";
|
||||
};
|
||||
};
|
||||
})
|
||||
]))
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue