Merge pull request #267440 from linsui/starship
nixos/starship: add presets
This commit is contained in:
commit
76a31fdb5c
1 changed files with 25 additions and 8 deletions
|
@ -1,13 +1,21 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.programs.starship;
|
cfg = config.programs.starship;
|
||||||
|
|
||||||
settingsFormat = pkgs.formats.toml { };
|
settingsFormat = pkgs.formats.toml { };
|
||||||
|
|
||||||
settingsFile = settingsFormat.generate "starship.toml" cfg.settings;
|
userSettingsFile = settingsFormat.generate "starship.toml" cfg.settings;
|
||||||
|
|
||||||
|
settingsFile = if cfg.presets == [] then userSettingsFile else pkgs.runCommand "starship.toml"
|
||||||
|
{
|
||||||
|
nativeBuildInputs = [ pkgs.yq ];
|
||||||
|
} ''
|
||||||
|
tomlq -s -t 'reduce .[] as $item ({}; . * $item)' \
|
||||||
|
${lib.concatStringsSep " " (map (f: "${pkgs.starship}/share/starship/presets/${f}.toml") cfg.presets)} \
|
||||||
|
${userSettingsFile} \
|
||||||
|
> $out
|
||||||
|
'';
|
||||||
|
|
||||||
initOption =
|
initOption =
|
||||||
if cfg.interactiveOnly then
|
if cfg.interactiveOnly then
|
||||||
|
@ -18,19 +26,28 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.programs.starship = {
|
options.programs.starship = {
|
||||||
enable = mkEnableOption (lib.mdDoc "the Starship shell prompt");
|
enable = lib.mkEnableOption (lib.mdDoc "the Starship shell prompt");
|
||||||
|
|
||||||
interactiveOnly = mkOption {
|
interactiveOnly = lib.mkOption {
|
||||||
default = true;
|
default = true;
|
||||||
example = false;
|
example = false;
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
description = lib.mdDoc ''
|
description = lib.mdDoc ''
|
||||||
Whether to enable starship only when the shell is interactive.
|
Whether to enable starship only when the shell is interactive.
|
||||||
Some plugins require this to be set to false to function correctly.
|
Some plugins require this to be set to false to function correctly.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
settings = mkOption {
|
presets = lib.mkOption {
|
||||||
|
default = [ ];
|
||||||
|
example = [ "nerd-font-symbols" ];
|
||||||
|
type = with lib.types; listOf str;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
Presets files to be merged with settings in order.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = lib.mkOption {
|
||||||
inherit (settingsFormat) type;
|
inherit (settingsFormat) type;
|
||||||
default = { };
|
default = { };
|
||||||
description = lib.mdDoc ''
|
description = lib.mdDoc ''
|
||||||
|
@ -41,7 +58,7 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
programs.bash.${initOption} = ''
|
programs.bash.${initOption} = ''
|
||||||
if [[ $TERM != "dumb" ]]; then
|
if [[ $TERM != "dumb" ]]; then
|
||||||
# don't set STARSHIP_CONFIG automatically if there's a user-specified
|
# don't set STARSHIP_CONFIG automatically if there's a user-specified
|
||||||
|
|
Loading…
Reference in a new issue