2021-10-05 23:05:22 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.atuin;
|
2024-11-16 22:20:52 +01:00
|
|
|
daemonCfg = cfg.daemon;
|
2021-10-05 23:05:22 +02:00
|
|
|
|
|
|
|
tomlFormat = pkgs.formats.toml { };
|
|
|
|
|
2024-10-08 21:39:25 +02:00
|
|
|
inherit (pkgs.stdenv) isLinux isDarwin;
|
2021-10-05 23:05:22 +02:00
|
|
|
in {
|
2024-10-08 23:34:09 +02:00
|
|
|
meta.maintainers = [ maintainers.hawkw maintainers.water-sucks ];
|
2021-10-05 23:05:22 +02:00
|
|
|
|
|
|
|
options.programs.atuin = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "atuin";
|
2021-10-05 23:05:22 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.atuin;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.atuin";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The package to use for atuin.";
|
2021-10-05 23:05:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enableBashIntegration = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-10-05 23:05:22 +02:00
|
|
|
Whether to enable Atuin's Bash integration. This will bind
|
2023-07-01 01:30:13 +02:00
|
|
|
`ctrl-r` to open the Atuin history.
|
2021-10-05 23:05:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-01 09:48:09 +02:00
|
|
|
enableZshIntegration = mkOption {
|
|
|
|
type = types.bool;
|
2021-10-05 23:05:22 +02:00
|
|
|
default = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-10-05 23:05:22 +02:00
|
|
|
Whether to enable Atuin's Zsh integration.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
If enabled, this will bind `ctrl-r` and the up-arrow
|
2021-10-05 23:05:22 +02:00
|
|
|
key to open the Atuin history.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-01-20 23:07:29 +01:00
|
|
|
enableFishIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-01-20 23:07:29 +01:00
|
|
|
Whether to enable Atuin's Fish integration.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
2022-01-20 23:07:29 +01:00
|
|
|
If enabled, this will bind the up-arrow key to open the Atuin history.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-03-15 11:52:48 +01:00
|
|
|
flags = mkOption {
|
|
|
|
default = [ ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
example = [ "--disable-up-arrow" "--disable-ctrl-r" ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-03-15 11:52:48 +01:00
|
|
|
Flags to append to the shell hook.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-10-05 23:05:22 +02:00
|
|
|
settings = mkOption {
|
|
|
|
type = with types;
|
|
|
|
let
|
|
|
|
prim = oneOf [ bool int str ];
|
|
|
|
primOrPrimAttrs = either prim (attrsOf prim);
|
|
|
|
entry = either prim (listOf primOrPrimAttrs);
|
|
|
|
entryOrAttrsOf = t: either entry (attrsOf t);
|
|
|
|
entries = entryOrAttrsOf (entryOrAttrsOf entry);
|
|
|
|
in attrsOf entries // { description = "Atuin configuration"; };
|
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-10-05 23:05:22 +02:00
|
|
|
{
|
|
|
|
auto_sync = true;
|
|
|
|
sync_frequency = "5m";
|
|
|
|
sync_address = "https://api.atuin.sh";
|
|
|
|
search_mode = "prefix";
|
|
|
|
}
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-10-05 23:05:22 +02:00
|
|
|
Configuration written to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/atuin/config.toml`.
|
|
|
|
|
|
|
|
See <https://atuin.sh/docs/config/> for the full list
|
2021-10-05 23:05:22 +02:00
|
|
|
of options.
|
|
|
|
'';
|
|
|
|
};
|
2023-04-03 15:48:47 +02:00
|
|
|
|
|
|
|
enableNushellIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-04-03 15:48:47 +02:00
|
|
|
Whether to enable Nushell integration.
|
|
|
|
'';
|
|
|
|
};
|
2024-10-08 21:39:25 +02:00
|
|
|
|
2024-11-16 22:20:52 +01:00
|
|
|
daemon = {
|
|
|
|
enable = mkEnableOption "Atuin daemon";
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
|
|
|
default = null;
|
|
|
|
type =
|
|
|
|
types.nullOr (types.enum [ "trace" "debug" "info" "warn" "error" ]);
|
|
|
|
description = ''
|
|
|
|
Verbosity of Atuin daemon logging.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2021-10-05 23:05:22 +02:00
|
|
|
};
|
|
|
|
|
2023-03-15 11:52:48 +01:00
|
|
|
config = let flagsStr = escapeShellArgs cfg.flags;
|
2024-10-08 21:39:25 +02:00
|
|
|
in mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
# Always add the configured `atuin` package.
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
# If there are user-provided settings, generate the config file.
|
|
|
|
xdg.configFile."atuin/config.toml" = mkIf (cfg.settings != { }) {
|
|
|
|
source = tomlFormat.generate "atuin-config" cfg.settings;
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
'';
|
2021-10-05 23:05:22 +02:00
|
|
|
|
2024-10-08 21:39:25 +02:00
|
|
|
programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
|
|
|
|
if [[ $options[zle] = on ]]; then
|
|
|
|
eval "$(${lib.getExe cfg.package} init zsh ${flagsStr})"
|
|
|
|
fi
|
2023-04-03 15:48:47 +02:00
|
|
|
'';
|
2024-10-08 21:39:25 +02:00
|
|
|
|
|
|
|
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
|
|
|
|
${lib.getExe cfg.package} init fish ${flagsStr} | source
|
2023-04-03 15:48:47 +02:00
|
|
|
'';
|
2024-10-08 21:39:25 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-11-16 22:20:52 +01:00
|
|
|
(mkIf daemonCfg.enable (mkMerge [
|
2024-10-08 21:39:25 +02:00
|
|
|
{
|
2024-10-20 01:59:15 +02:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = versionAtLeast cfg.package.version "18.2.0";
|
|
|
|
message = ''
|
2024-11-16 22:12:25 +01:00
|
|
|
The Atuin daemon requires at least version 18.2.0 or later.
|
2024-10-20 01:59:15 +02:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = isLinux || isDarwin;
|
|
|
|
message =
|
2024-11-16 22:12:25 +01:00
|
|
|
"The Atuin daemon can only be configured on either Linux or macOS.";
|
2024-10-20 01:59:15 +02:00
|
|
|
}
|
|
|
|
];
|
2024-10-08 21:39:25 +02:00
|
|
|
|
|
|
|
programs.atuin.settings = { daemon = { enabled = true; }; };
|
|
|
|
}
|
|
|
|
(mkIf isLinux {
|
|
|
|
programs.atuin.settings = { daemon = { systemd_socket = true; }; };
|
|
|
|
|
|
|
|
systemd.user.services.atuin-daemon = {
|
|
|
|
Unit = {
|
2024-11-16 22:12:25 +01:00
|
|
|
Description = "Atuin daemon";
|
2024-10-08 21:39:25 +02:00
|
|
|
Requires = [ "atuin-daemon.socket" ];
|
|
|
|
};
|
|
|
|
Install = {
|
|
|
|
Also = [ "atuin-daemon.socket" ];
|
|
|
|
WantedBy = [ "default.target" ];
|
|
|
|
};
|
|
|
|
Service = {
|
|
|
|
ExecStart = "${lib.getExe cfg.package} daemon";
|
2024-11-16 22:20:52 +01:00
|
|
|
Environment = lib.optionals (daemonCfg.logLevel != null)
|
|
|
|
[ "ATUIN_LOG=${daemonCfg.logLevel}" ];
|
2024-10-08 21:39:25 +02:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSteps = 3;
|
|
|
|
RestartMaxDelaySec = 6;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.user.sockets.atuin-daemon = {
|
2024-11-16 22:12:25 +01:00
|
|
|
Unit = { Description = "Atuin daemon socket"; };
|
2024-10-08 21:39:25 +02:00
|
|
|
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" ];
|
2024-11-16 22:20:52 +01:00
|
|
|
EnvironmentVariables =
|
|
|
|
lib.optionalAttrs (daemonCfg.logLevel != null) {
|
|
|
|
ATUIN_LOG = daemonCfg.logLevel;
|
|
|
|
};
|
2024-10-08 21:39:25 +02:00
|
|
|
KeepAlive = {
|
|
|
|
Crashed = true;
|
|
|
|
SuccessfulExit = false;
|
|
|
|
};
|
|
|
|
ProcessType = "Background";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]))
|
|
|
|
]);
|
2021-10-05 23:05:22 +02:00
|
|
|
}
|