at 23.11-pre 1.8 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.programs.starship; 7 8 settingsFormat = pkgs.formats.toml { }; 9 10 settingsFile = settingsFormat.generate "starship.toml" cfg.settings; 11 12 initOption = 13 if cfg.interactiveOnly then 14 "promptInit" 15 else 16 "shellInit"; 17 18in 19{ 20 options.programs.starship = { 21 enable = mkEnableOption (lib.mdDoc "the Starship shell prompt"); 22 23 interactiveOnly = mkOption { 24 default = true; 25 example = false; 26 type = types.bool; 27 description = lib.mdDoc '' 28 Whether to enable starship only when the shell is interactive. 29 Some plugins require this to be set to false to function correctly. 30 ''; 31 }; 32 33 settings = mkOption { 34 inherit (settingsFormat) type; 35 default = { }; 36 description = lib.mdDoc '' 37 Configuration included in `starship.toml`. 38 39 See https://starship.rs/config/#prompt for documentation. 40 ''; 41 }; 42 }; 43 44 config = mkIf cfg.enable { 45 programs.bash.${initOption} = '' 46 if [[ $TERM != "dumb" && (-z $INSIDE_EMACS || $INSIDE_EMACS == "vterm") ]]; then 47 export STARSHIP_CONFIG=${settingsFile} 48 eval "$(${pkgs.starship}/bin/starship init bash)" 49 fi 50 ''; 51 52 programs.fish.${initOption} = '' 53 if test "$TERM" != "dumb" -a \( -z "$INSIDE_EMACS" -o "$INSIDE_EMACS" = "vterm" \) 54 set -x STARSHIP_CONFIG ${settingsFile} 55 eval (${pkgs.starship}/bin/starship init fish) 56 end 57 ''; 58 59 programs.zsh.${initOption} = '' 60 if [[ $TERM != "dumb" && (-z $INSIDE_EMACS || $INSIDE_EMACS == "vterm") ]]; then 61 export STARSHIP_CONFIG=${settingsFile} 62 eval "$(${pkgs.starship}/bin/starship init zsh)" 63 fi 64 ''; 65 }; 66 67 meta.maintainers = pkgs.starship.meta.maintainers; 68}