Configuring Starship Config Format

Hey everyone-I have been working on trying to get my starship format in place. Here is what I have so far:

{
  config,
  lib,
  ...
}: {
  programs = {
    starship = {
      enable = true;
      enableBashIntegration = config.programs.bash.enable;
      enableFishIntegration = config.programs.fish.enable;
      enableZshIntegration = config.programs.zsh.enable;
      settings = {
        add_newline = false;
        continuation_prompt = "'▶▶";
        command_timeout = 1000;
                #format = lib.concatStrings [
        format = lib.concatStrings [
          ""
          "$directory"
          "$git_branch$git_commit$git_state $git_status"
          "$character"];
        right_format = lib.concatStrings [
        "$python"
        "$rust"
        "$terraform"
        "$memory_usage"
        "$aws"
        "$custom"
        "$status"
        "$os"
        "$time"];
        directory = {
            disabled = false;
            format = "[$path](bold fg:#8be9fd)";
            truncate_to_repo = false;
        };
        git_branch = {
        format = " [  $branch](fg:#9198a1)";
        };
        git_status = {
        ahead = "⇡${count}";
        behind = "⇣${count}";
        diverged = "⇕⇡${ahead_count}⇣${behind_count}";
        format = "[[( $all_status$ahead_behind )](fg:#769ff0)]($style)";
        style = "bg:#394260";
        };
        time = {
        disabled = false;
        format = "[[  $time ](fg:#a0a9cb )]($style)";
        time_format = "%R";
        };
        python = {
        format = "[${symbol}](${virtualenv}) ${version}]($style)";
        style = "bold bright-yellow";
        symbol = "[ ](bold bright-blue)";
        version_format = "${raw}";
        };
        rust = {
        style = "bold bright-red";
        format = " rs(italic) $symbol($style)";
        symbol = " ";
        };
        aws = {
        format = " [aws](italic) [$symbol $profile $region]($style)";
        style = "bold blue";
        symbol = " ";
        };

        memory_usage = {
        style = "bold bright-cyan";
        format = " mem [${ram}( ${swap})]($style)";
        symbol = "▪▫▪ ";
        };

        nix_shell = {
        format = "[$symbol nix⎪$state⎪]($style) [$name](italic dimmed white)";
        impure_msg = "[⌽](bold dimmed red)";
        pure_msg = "[⌾](bold dimmed green)";
        style = "bold italic dimmed blue";
        symbol = " ";
        unknown_msg = "[◌](bold dimmed ellow)";
        };
        kubernetes = {
        style = "bold bright-cyan";
        format = " [kubernetes](italic) [$symbol]($style)";
        symbol = " ";
        };
        helm = {
        style = "bold bright-yellow";
        format = " [helm](italic) [$symbol]($style)";
        symbol = "helm ";
        };
        terraform = {
        style = "bold bright-cyan";
        format = " [terraform](italic) [$symbol]($style)";
        symbol = "terraform ";
        };
        };
    };
  };
}

When I rebuild, I get the error below:

       error: undefined variable 'symbol'

I know what it is referring to, but I know other nix flakes have had variables like ${count} or ${symbol} in their format but I imagine they are doing something else that I am not seeing? Any suggestions?

I was using Martin’s nix-flake as reference:

"$symbol" is non-interpolated (no substitution by Nix) and places the string $symbol as-is in the resulting yaml config file. This is good because Starship performs the substitution of this config variable at runtime. It’s a Starship variable, not a Nix variable.

"${symbol}" is an interpolated string where the value of Nix variable symbol is substituted into the string at build time. This is probably not what you want because there is no Nix variable symbol defined in your config and it’s not what the reference config you linked to is doing.

In short, you should be able to ditch the curlies and be mostly fine.

https://nix.dev/manual/nix/2.18/language/string-interpolation

1 Like

Noted. I’ll take a look later and see if this does the trick. Thank you!

This was exactly it! When I was working on this initially, I had a feeling I should have just removed the brackets because I could tell (in Zed) that the variables were being seen as nix variables. I should have paid more attention-thank you for the advice!

1 Like