2021-10-05 23:05:22 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.atuin;
|
|
|
|
|
|
|
|
tomlFormat = pkgs.formats.toml { };
|
|
|
|
|
|
|
|
in {
|
|
|
|
meta.maintainers = [ maintainers.hawkw ];
|
|
|
|
|
|
|
|
options.programs.atuin = {
|
|
|
|
enable = mkEnableOption "atuin";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.atuin;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.atuin";
|
2021-10-05 23:05:22 +02:00
|
|
|
description = "The package to use for atuin.";
|
|
|
|
};
|
|
|
|
|
|
|
|
enableBashIntegration = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Atuin's Bash integration. This will bind
|
|
|
|
<literal>ctrl-r</literal> to open the Atuin history.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-01 09:48:09 +02:00
|
|
|
enableZshIntegration = mkOption {
|
|
|
|
type = types.bool;
|
2021-10-05 23:05:22 +02:00
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Atuin's Zsh integration.
|
|
|
|
</para><para>
|
|
|
|
If enabled, this will bind <literal>ctrl-r</literal> and the up-arrow
|
|
|
|
key to open the Atuin history.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-01-20 23:07:29 +01:00
|
|
|
enableFishIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Atuin's Fish integration.
|
|
|
|
</para><para>
|
|
|
|
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" ];
|
|
|
|
description = ''
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration written to
|
2021-12-09 04:02:00 +01:00
|
|
|
<filename>$XDG_CONFIG_HOME/atuin/config.toml</filename>.
|
2021-10-05 23:05:22 +02:00
|
|
|
</para><para>
|
2023-05-07 23:44:22 +02:00
|
|
|
See <link xlink:href="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;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Nushell integration.
|
|
|
|
'';
|
|
|
|
};
|
2021-10-05 23:05:22 +02:00
|
|
|
};
|
|
|
|
|
2023-03-15 11:52:48 +01:00
|
|
|
config = let flagsStr = escapeShellArgs cfg.flags;
|
|
|
|
in mkIf cfg.enable {
|
2021-10-05 23:05:22 +02:00
|
|
|
|
|
|
|
# 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 ''
|
2022-02-19 05:20:00 +01:00
|
|
|
if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
|
|
|
|
source "${pkgs.bash-preexec}/share/bash/bash-preexec.sh"
|
2023-03-15 11:52:48 +01:00
|
|
|
eval "$(${cfg.package}/bin/atuin init bash ${flagsStr})"
|
2022-02-19 05:20:00 +01:00
|
|
|
fi
|
2021-10-05 23:05:22 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
|
2022-02-19 05:20:00 +01:00
|
|
|
if [[ $options[zle] = on ]]; then
|
2023-03-15 11:52:48 +01:00
|
|
|
eval "$(${cfg.package}/bin/atuin init zsh ${flagsStr})"
|
2022-02-19 05:20:00 +01:00
|
|
|
fi
|
2021-10-05 23:05:22 +02:00
|
|
|
'';
|
2022-01-20 23:07:29 +01:00
|
|
|
|
|
|
|
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
|
2023-03-15 11:52:48 +01:00
|
|
|
${cfg.package}/bin/atuin init fish ${flagsStr} | source
|
2022-01-20 23:07:29 +01:00
|
|
|
'';
|
2023-04-03 15:48:47 +02:00
|
|
|
|
|
|
|
programs.nushell = mkIf cfg.enableNushellIntegration {
|
|
|
|
extraEnv = ''
|
|
|
|
let atuin_cache = "${config.xdg.cacheHome}/atuin"
|
|
|
|
if not ($atuin_cache | path exists) {
|
|
|
|
mkdir $atuin_cache
|
|
|
|
}
|
2023-04-25 12:45:09 +02:00
|
|
|
${cfg.package}/bin/atuin init nu ${flagsStr} | save --force ${config.xdg.cacheHome}/atuin/init.nu
|
2023-04-03 15:48:47 +02:00
|
|
|
'';
|
|
|
|
extraConfig = ''
|
|
|
|
source ${config.xdg.cacheHome}/atuin/init.nu
|
|
|
|
'';
|
|
|
|
};
|
2021-10-05 23:05:22 +02:00
|
|
|
};
|
|
|
|
}
|