1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00: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 { }; tomlFormat = pkgs.formats.toml { };
inherit (pkgs.stdenv) isLinux isDarwin;
in { in {
meta.maintainers = [ maintainers.hawkw ]; meta.maintainers = [ maintainers.hawkw ];
@ -94,49 +95,109 @@ in {
Whether to enable Nushell integration. Whether to enable Nushell integration.
''; '';
}; };
daemon.enable = mkEnableOption "atuin daemon";
}; };
config = let flagsStr = escapeShellArgs cfg.flags; 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 ];
# Always add the configured `atuin` package. # If there are user-provided settings, generate the config file.
home.packages = [ cfg.package ]; xdg.configFile."atuin/config.toml" = mkIf (cfg.settings != { }) {
source = tomlFormat.generate "atuin-config" cfg.settings;
};
# If there are user-provided settings, generate the config file. programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
xdg.configFile."atuin/config.toml" = mkIf (cfg.settings != { }) { if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
source = tomlFormat.generate "atuin-config" cfg.settings; source "${pkgs.bash-preexec}/share/bash/bash-preexec.sh"
}; eval "$(${lib.getExe cfg.package} init bash ${flagsStr})"
fi
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
source "${pkgs.bash-preexec}/share/bash/bash-preexec.sh"
eval "$(${lib.getExe cfg.package} init bash ${flagsStr})"
fi
'';
programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
if [[ $options[zle] = on ]]; then
eval "$(${lib.getExe cfg.package} init zsh ${flagsStr})"
fi
'';
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
${lib.getExe cfg.package} init fish ${flagsStr} | source
'';
programs.nushell = mkIf cfg.enableNushellIntegration {
extraEnv = ''
let atuin_cache = "${config.xdg.cacheHome}/atuin"
if not ($atuin_cache | path exists) {
mkdir $atuin_cache
}
${
lib.getExe cfg.package
} init nu ${flagsStr} | save --force ${config.xdg.cacheHome}/atuin/init.nu
''; '';
extraConfig = ''
source ${config.xdg.cacheHome}/atuin/init.nu programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
if [[ $options[zle] = on ]]; then
eval "$(${lib.getExe cfg.package} init zsh ${flagsStr})"
fi
''; '';
};
}; programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
${lib.getExe cfg.package} init fish ${flagsStr} | source
'';
programs.nushell = mkIf cfg.enableNushellIntegration {
extraEnv = ''
let atuin_cache = "${config.xdg.cacheHome}/atuin"
if not ($atuin_cache | path exists) {
mkdir $atuin_cache
}
${
lib.getExe cfg.package
} init nu ${flagsStr} | save --force ${config.xdg.cacheHome}/atuin/init.nu
'';
extraConfig = ''
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";
};
};
})
]))
]);
} }