fork/home-manager
git clone https://git.julia.blue/fork/home-manager
6f882433
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . starship ; 8 9tomlFormat = pkgs . formats . toml { }; 10 11starshipCmd = " ${ config . home . profileDirectory } /bin/starship" ; 12 13in { 14meta . maintainers = [ ]; 15 16options . programs . starship = { 17enable = mkEnableOption "starship" ; 18 19package = mkOption { 20type = types . package ; 21default = pkgs . starship ; 22defaultText = literalExpression "pkgs.starship" ; 23description = "The package to use for the starship binary." ; 24}; 25 26settings = mkOption { 27type = with types ; 28let 29prim = either bool ( either int str ); 30primOrPrimAttrs = either prim ( attrsOf prim ); 31entry = either prim ( listOf primOrPrimAttrs ); 32entryOrAttrsOf = t :either entry ( attrsOf t ); 33entries = entryOrAttrsOf ( entryOrAttrsOf entry ); 34in attrsOf entries // { description = "Starship configuration" ; }; 35default = { }; 36example = literalExpression '' 37{ 38add_newline = false; 39format = lib.concatStrings [ 40"$line_break" 41"$package" 42"$line_break" 43"$character" 44]; 45scan_timeout = 10; 46character = { 47success_symbol = "➜"; 48error_symbol = "➜"; 49}; 50} 51'' ; 52description = '' 53Configuration written to 54{file}`$XDG_CONFIG_HOME/starship.toml`. 55 56See <https://starship.rs/config/> for the full list 57of options. 58'' ; 59}; 60 61enableBashIntegration = mkEnableOption "Bash integration" // { 62default = true ; 63}; 64 65enableZshIntegration = mkEnableOption "Zsh integration" // { 66default = true ; 67}; 68 69enableFishIntegration = mkEnableOption "Fish integration" // { 70default = true ; 71}; 72 73enableIonIntegration = mkEnableOption "Ion integration" // { 74default = true ; 75}; 76 77enableNushellIntegration = mkEnableOption "Nushell integration" // { 78default = true ; 79}; 80 81enableTransience = mkOption { 82type = types . bool ; 83default = false ; 84description = '' 85The TransientPrompt feature of Starship replaces previous prompts with a 86custom string. This is only a valid option for the Fish shell. 87 88For documentation on how to change the default replacement string and 89for more information visit 90https://starship.rs/advanced-config/#transientprompt-and-transientrightprompt-in-cmd 91'' ; 92}; 93}; 94 95config = mkIf cfg . enable { 96home . packages = [ cfg . package ]; 97 98xdg . configFile . "starship.toml" = mkIf ( cfg . settings != { }) { 99source = tomlFormat . generate "starship-config" cfg . settings ; 100}; 101 102programs . bash . initExtra = mkIf cfg . enableBashIntegration '' 103if [[ $TERM != "dumb" ]]; then 104eval "$( ${ starshipCmd } init bash --print-full-init)" 105fi 106'' ; 107 108programs . zsh . initExtra = mkIf cfg . enableZshIntegration '' 109if [[ $TERM != "dumb" ]]; then 110eval "$( ${ starshipCmd } init zsh)" 111fi 112'' ; 113 114programs . fish . interactiveShellInit = mkIf cfg . enableFishIntegration '' 115if test "$TERM" != "dumb" 116eval ( ${ starshipCmd } init fish) 117${ lib . optionalString cfg . enableTransience "enable_transience" } 118end 119'' ; 120 121programs . ion . initExtra = mkIf cfg . enableIonIntegration '' 122if test $TERM != "dumb" 123eval $( ${ starshipCmd } init ion) 124end 125'' ; 126 127programs . nushell = mkIf cfg . enableNushellIntegration { 128# Unfortunately nushell doesn't allow conditionally sourcing nor 129# conditionally setting (global) environment variables, which is why the 130# check for terminal compatibility (as seen above for the other shells) is 131# not done here. 132extraEnv = '' 133let starship_cache = " ${ config . xdg . cacheHome } /starship" 134if not ($starship_cache | path exists) { 135mkdir $starship_cache 136} 137${ starshipCmd } init nu | save --force ${ config . xdg . cacheHome } /starship/init.nu 138'' ; 139extraConfig = '' 140use ${ config . xdg . cacheHome } /starship/init.nu 141'' ; 142}; 143}; 144}