From daa7ed85f3b5e36bf48a0bb5ab29fa38e845f47f Mon Sep 17 00:00:00 2001 From: kpbaks Date: Sat, 30 Nov 2024 21:49:28 +0100 Subject: [PATCH] starship: add option to use community presets Presets are community-submitted configurations for starship. See: https://starship.rs/presets/#presets --- modules/lib/maintainers.nix | 6 ++++ modules/programs/starship.nix | 52 +++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 91ecb47be..455c3bd61 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -628,4 +628,10 @@ keys = [{ fingerprint = "BC82 4BB5 1656 D144 285E A0EC D382 C4AF EECE AA90"; }]; }; + kpbaks = { + name = "Kristoffer Plagborg Bak Sørensen"; + email = "kristoffer.pbs@gmail.com"; + github = "kpbaks"; + githubId = 57013304; + }; } diff --git a/modules/programs/starship.nix b/modules/programs/starship.nix index 9ccff7fcf..f69280aba 100644 --- a/modules/programs/starship.nix +++ b/modules/programs/starship.nix @@ -11,7 +11,7 @@ let starshipCmd = "${config.home.profileDirectory}/bin/starship"; in { - meta.maintainers = [ ]; + meta.maintainers = [ maintainers.kpbaks ]; options.programs.starship = { enable = mkEnableOption "starship"; @@ -23,6 +23,34 @@ in { description = "The package to use for the starship binary."; }; + preset = mkOption { + # generated with `starship preset --list` + type = types.enum [ + null + "bracketed-segments" + "gruvbox-rainbow" + "jetpack" + "nerd-font-symbols" + "no-empty-icons" + "no-nerd-font" + "no-runtime-versions" + "pastel-powerline" + "plain-text-symbols" + "pure-preset" + "tokyo-night" + ]; + default = null; + example = "jetpack"; + description = '' + The community-submitted configuration preset to use. + + See for previews + of each preset. + + Mutually exclusive with programs.starship.settings + ''; + }; + settings = mkOption { type = tomlFormat.type; default = { }; @@ -48,6 +76,8 @@ in { See for the full list of options. + + Mutually exclusive with programs.starship.preset ''; }; @@ -88,9 +118,25 @@ in { config = mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."starship.toml" = mkIf (cfg.settings != { }) { + warnings = lib.optional (cfg.preset != null && cfg.settings != { }) + "programs.starship.settings has no effect when programs.starship.preset != null"; + + xdg.configFile."starship.toml" = if cfg.preset != null then + let + starshipGithub = pkgs.fetchFromGitHub { + owner = "starship"; + repo = "starship"; + rev = "61c860e1293d446d515203ac44055f7bef77d14a"; + hash = "sha256-pl3aW4zCM6CcYOL0dUwE56aTC7BJdvdRyo/GudvX7fQ="; + }; + in { + text = builtins.readFile + "${starshipGithub}/docs/public/presets/toml/${cfg.preset}.toml"; + } + else if cfg.settings != { } then { source = tomlFormat.generate "starship-config" cfg.settings; - }; + } else + { }; programs.bash.initExtra = mkIf cfg.enableBashIntegration '' if [[ $TERM != "dumb" ]]; then