From b0be47978de5cfd729a79c3f57ace4c86364ff45 Mon Sep 17 00:00:00 2001 From: Lord-Valen <46138807+Lord-Valen@users.noreply.github.com> Date: Wed, 8 Mar 2023 09:24:16 -0500 Subject: [PATCH] [Backport release-22.11] starship: add nushell integration #3701 (#3697) * starship: add nushell integration support (cherry picked from commit 7ae7250df8f38c4efc8cd6669a36272ab7a575ed) * starship: fix nushell integration Overwrite starship/init.nu if already exists, since this is a cache file for sourcing in `init.nu`. (cherry picked from commit 646ac0ad17e295c2dbe338ff62c18f78d54f3d40) * starship: re-add ion integration which was apparently mistakenly removed in commit 7ae7250 (cherry picked from commit a62e4c88d7b84ac54a96084f3490703ba34bdd2e) * starship: Use mkEnableOption (#3701) --------- Co-authored-by: Philipp Mildenberger Co-authored-by: Aidan Gauland Co-authored-by: Marcel Transier <34482842+marceltransier@users.noreply.github.com> --- modules/programs/starship.nix | 45 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/modules/programs/starship.nix b/modules/programs/starship.nix index 58ec518a..31136d7e 100644 --- a/modules/programs/starship.nix +++ b/modules/programs/starship.nix @@ -58,36 +58,24 @@ in { ''; }; - enableBashIntegration = mkOption { + enableBashIntegration = mkEnableOption "Bash integration" // { default = true; - type = types.bool; - description = '' - Whether to enable Bash integration. - ''; }; - enableZshIntegration = mkOption { + enableZshIntegration = mkEnableOption "Zsh integration" // { default = true; - type = types.bool; - description = '' - Whether to enable Zsh integration. - ''; }; - enableFishIntegration = mkOption { + enableFishIntegration = mkEnableOption "Fish integration" // { default = true; - type = types.bool; - description = '' - Whether to enable Fish integration. - ''; }; - enableIonIntegration = mkOption { + enableIonIntegration = mkEnableOption "Ion integration" // { + default = true; + }; + + enableNushellIntegration = mkEnableOption "Nushell integration" // { default = true; - type = types.bool; - description = '' - Whether to enable Ion integration. - ''; }; }; @@ -121,5 +109,22 @@ in { eval $(${starshipCmd} init ion) end ''; + + programs.nushell = mkIf cfg.enableNushellIntegration { + # Unfortunately nushell doesn't allow conditionally sourcing nor + # conditionally setting (global) environment variables, which is why the + # check for terminal compatibility (as seen above for the other shells) is + # not done here. + extraEnv = '' + let starship_cache = "${config.xdg.cacheHome}/starship" + if not ($starship_cache | path exists) { + mkdir $starship_cache + } + ${starshipCmd} init nu | save --force ${config.xdg.cacheHome}/starship/init.nu + ''; + extraConfig = '' + source ${config.xdg.cacheHome}/starship/init.nu + ''; + }; }; }