1 { config, lib, pkgs, ... }:
4 cfg = config.programs.starship;
6 settingsFormat = pkgs.formats.toml { };
8 userSettingsFile = settingsFormat.generate "starship.toml" cfg.settings;
10 settingsFile = if cfg.presets == [] then userSettingsFile else pkgs.runCommand "starship.toml"
12 nativeBuildInputs = [ pkgs.yq ];
14 tomlq -s -t 'reduce .[] as $item ({}; . * $item)' \
15 ${lib.concatStringsSep " " (map (f: "${cfg.package}/share/starship/presets/${f}.toml") cfg.presets)} \
21 if cfg.interactiveOnly then
28 options.programs.starship = {
29 enable = lib.mkEnableOption "the Starship shell prompt";
31 package = lib.mkPackageOption pkgs "starship" { };
33 interactiveOnly = lib.mkEnableOption ''
34 starship only when the shell is interactive.
35 Some plugins require this to be set to false to function correctly
36 '' // { default = true; };
38 presets = lib.mkOption {
40 example = [ "nerd-font-symbols" ];
41 type = with lib.types; listOf str;
43 Presets files to be merged with settings in order.
47 settings = lib.mkOption {
48 inherit (settingsFormat) type;
51 Configuration included in `starship.toml`.
53 See https://starship.rs/config/#prompt for documentation.
58 config = lib.mkIf cfg.enable {
59 programs.bash.${initOption} = ''
60 if [[ $TERM != "dumb" ]]; then
61 # don't set STARSHIP_CONFIG automatically if there's a user-specified
62 # config file. starship appears to use a hardcoded config location
63 # rather than one inside an XDG folder:
64 # https://github.com/starship/starship/blob/686bda1706e5b409129e6694639477a0f8a3f01b/src/configure.rs#L651
65 if [[ ! -f "$HOME/.config/starship.toml" ]]; then
66 export STARSHIP_CONFIG=${settingsFile}
68 eval "$(${cfg.package}/bin/starship init bash)"
72 programs.fish.${initOption} = ''
73 if test "$TERM" != "dumb"
74 # don't set STARSHIP_CONFIG automatically if there's a user-specified
75 # config file. starship appears to use a hardcoded config location
76 # rather than one inside an XDG folder:
77 # https://github.com/starship/starship/blob/686bda1706e5b409129e6694639477a0f8a3f01b/src/configure.rs#L651
78 if not test -f "$HOME/.config/starship.toml";
79 set -x STARSHIP_CONFIG ${settingsFile}
81 eval (${cfg.package}/bin/starship init fish)
85 programs.zsh.${initOption} = ''
86 if [[ $TERM != "dumb" ]]; then
87 # don't set STARSHIP_CONFIG automatically if there's a user-specified
88 # config file. starship appears to use a hardcoded config location
89 # rather than one inside an XDG folder:
90 # https://github.com/starship/starship/blob/686bda1706e5b409129e6694639477a0f8a3f01b/src/configure.rs#L651
91 if [[ ! -f "$HOME/.config/starship.toml" ]]; then
92 export STARSHIP_CONFIG=${settingsFile}
94 eval "$(${cfg.package}/bin/starship init zsh)"
99 meta.maintainers = pkgs.starship.meta.maintainers;