fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , pkgs , lib , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . atuin ; 8 9tomlFormat = pkgs . formats . toml { }; 10 11in { 12meta . maintainers = [ maintainers . hawkw ]; 13 14options . programs . atuin = { 15enable = mkEnableOption "atuin" ; 16 17package = mkOption { 18type = types . package ; 19default = pkgs . atuin ; 20defaultText = literalExpression "pkgs.atuin" ; 21description = "The package to use for atuin." ; 22}; 23 24enableBashIntegration = mkOption { 25type = types . bool ; 26default = true ; 27description = '' 28Whether to enable Atuin's Bash integration. This will bind 29`ctrl-r` to open the Atuin history. 30'' ; 31}; 32 33enableZshIntegration = mkOption { 34type = types . bool ; 35default = true ; 36description = '' 37Whether to enable Atuin's Zsh integration. 38 39If enabled, this will bind `ctrl-r` and the up-arrow 40key to open the Atuin history. 41'' ; 42}; 43 44enableFishIntegration = mkOption { 45default = true ; 46type = types . bool ; 47description = '' 48Whether to enable Atuin's Fish integration. 49 50If enabled, this will bind the up-arrow key to open the Atuin history. 51'' ; 52}; 53 54flags = mkOption { 55default = [ ]; 56type = types . listOf types . str ; 57example = [ "--disable-up-arrow" "--disable-ctrl-r" ]; 58description = '' 59Flags to append to the shell hook. 60'' ; 61}; 62 63settings = mkOption { 64type = with types ; 65let 66prim = oneOf [ bool int str ]; 67primOrPrimAttrs = either prim ( attrsOf prim ); 68entry = either prim ( listOf primOrPrimAttrs ); 69entryOrAttrsOf = t :either entry ( attrsOf t ); 70entries = entryOrAttrsOf ( entryOrAttrsOf entry ); 71in attrsOf entries // { description = "Atuin configuration" ; }; 72default = { }; 73example = literalExpression '' 74{ 75auto_sync = true; 76sync_frequency = "5m"; 77sync_address = "https://api.atuin.sh"; 78search_mode = "prefix"; 79} 80'' ; 81description = '' 82Configuration written to 83{file}`$XDG_CONFIG_HOME/atuin/config.toml`. 84 85See <https://atuin.sh/docs/config/> for the full list 86of options. 87'' ; 88}; 89 90enableNushellIntegration = mkOption { 91default = true ; 92type = types . bool ; 93description = '' 94Whether to enable Nushell integration. 95'' ; 96}; 97}; 98 99config = let flagsStr = escapeShellArgs cfg . flags ; 100in mkIf cfg . enable { 101 102# Always add the configured `atuin` package. 103home . packages = [ cfg . package ]; 104 105# If there are user-provided settings, generate the config file. 106xdg . configFile . "atuin/config.toml" = mkIf ( cfg . settings != { }) { 107source = tomlFormat . generate "atuin-config" cfg . settings ; 108}; 109 110programs . bash . initExtra = mkIf cfg . enableBashIntegration '' 111if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then 112source " ${ pkgs . bash-preexec } /share/bash/bash-preexec.sh" 113eval "$( ${ cfg . package } /bin/atuin init bash ${ flagsStr } )" 114fi 115'' ; 116 117programs . zsh . initExtra = mkIf cfg . enableZshIntegration '' 118if [[ $options[zle] = on ]]; then 119eval "$( ${ cfg . package } /bin/atuin init zsh ${ flagsStr } )" 120fi 121'' ; 122 123programs . fish . interactiveShellInit = mkIf cfg . enableFishIntegration '' 124${ cfg . package } /bin/atuin init fish ${ flagsStr } | source 125'' ; 126 127programs . nushell = mkIf cfg . enableNushellIntegration { 128extraEnv = '' 129let atuin_cache = " ${ config . xdg . cacheHome } /atuin" 130if not ($atuin_cache | path exists) { 131mkdir $atuin_cache 132} 133${ cfg . package } /bin/atuin init nu ${ flagsStr } | save --force ${ config . xdg . cacheHome } /atuin/init.nu 134'' ; 135extraConfig = '' 136source ${ config . xdg . cacheHome } /atuin/init.nu 137'' ; 138}; 139}; 140}