From ec4e1159d973ca289ad5b50bf2cef286800b4a7d Mon Sep 17 00:00:00 2001 From: bandithedoge Date: Tue, 25 Nov 2025 18:24:47 +0100 Subject: [PATCH] starship: add presets option --- .../misc/news/2026/01/2026-01-11_16-02-12.nix | 9 +++++ modules/programs/starship.nix | 37 +++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 modules/misc/news/2026/01/2026-01-11_16-02-12.nix diff --git a/modules/misc/news/2026/01/2026-01-11_16-02-12.nix b/modules/misc/news/2026/01/2026-01-11_16-02-12.nix new file mode 100644 index 00000000..bd15551d --- /dev/null +++ b/modules/misc/news/2026/01/2026-01-11_16-02-12.nix @@ -0,0 +1,9 @@ +{ config, ... }: +{ + time = "2026-01-11T16:02:12+00:00"; + condition = config.programs.starship.enable; + message = '' + The starship module has a new option, programs.starship.presets, which + allows for merging user configuration with Starship's bundled presets. + ''; +} diff --git a/modules/programs/starship.nix b/modules/programs/starship.nix index 559e68f2..04a67eba 100644 --- a/modules/programs/starship.nix +++ b/modules/programs/starship.nix @@ -49,6 +49,17 @@ in ''; }; + presets = mkOption { + type = with types; listOf str; + default = [ ]; + example = [ "nerd-font-symbols" ]; + description = '' + Preset files to be merged with settings in order. + + See for the full list of available presets. + ''; + }; + enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; enableFishIntegration = lib.hm.shell.mkFishIntegrationOption { inherit config; }; @@ -99,9 +110,29 @@ in sessionVariables.STARSHIP_CONFIG = cfg.configPath; - file.${cfg.configPath} = mkIf (cfg.settings != { }) { - source = tomlFormat.generate "starship-config" cfg.settings; - }; + file.${cfg.configPath} = + let + settingsFile = tomlFormat.generate "starship-config" cfg.settings; + in + if cfg.presets == [ ] then + { source = settingsFile; } + else + { + source = + pkgs.runCommand "starship.toml" + { + nativeBuildInputs = [ pkgs.yq ]; + } + '' + tomlq -s -t 'reduce .[] as $item ({}; . * $item)' \ + ${ + lib.concatStringsSep " " (map (f: "${cfg.package}/share/starship/presets/${f}.toml") cfg.presets) + } \ + ${settingsFile} \ + > $out + ''; + }; + }; programs.bash.initExtra = mkIf cfg.enableBashIntegration (