diff --git a/modules/misc/news/2025/11/2025-11-25_18-16-22.nix b/modules/misc/news/2025/11/2025-11-25_18-16-22.nix new file mode 100644 index 000000000000..5991db52bae4 --- /dev/null +++ b/modules/misc/news/2025/11/2025-11-25_18-16-22.nix @@ -0,0 +1,8 @@ +{ config, ... }: +{ + time = "2025-11-25T17:16:22+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 bundled presets. + ''; +} diff --git a/modules/programs/starship.nix b/modules/programs/starship.nix index 2d2e3506e153..378ccdfb6ca3 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 ''