From 3f1ef8fe14ed87c0999f2a5ce7a5a1b3c3b8d7ec Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Thu, 23 Dec 2021 22:22:39 +0000 Subject: [PATCH 1/2] nixos/starship: init --- .../from_md/release-notes/rl-2205.section.xml | 9 ++++ .../manual/release-notes/rl-2205.section.md | 3 ++ nixos/modules/module-list.nix | 1 + nixos/modules/programs/starship.nix | 51 +++++++++++++++++++ pkgs/tools/misc/starship/default.nix | 2 +- 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 nixos/modules/programs/starship.nix diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml index 2427ed6f3f3c..dd8266ef1ba6 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml @@ -424,6 +424,15 @@ renamed to linux-firmware. + + + A new module was added for the + Starship shell + prompt, providing the options + programs.starship.enable and + programs.starship.settings. + + diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md index 41ff367efb6b..7af73dbaf5a2 100644 --- a/nixos/doc/manual/release-notes/rl-2205.section.md +++ b/nixos/doc/manual/release-notes/rl-2205.section.md @@ -148,3 +148,6 @@ In addition to numerous new and upgraded packages, this release has the followin - The option `services.thelounge.plugins` has been added to allow installing plugins for The Lounge. Plugins can be found in `pkgs.theLoungePlugins.plugins` and `pkgs.theLoungePlugins.themes`. - The `firmwareLinuxNonfree` package has been renamed to `linux-firmware`. + +- A new module was added for the [Starship](https://starship.rs/) shell prompt, + providing the options `programs.starship.enable` and `programs.starship.settings`. diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 3d54810050a5..e67496c185d7 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -198,6 +198,7 @@ ./programs/ssmtp.nix ./programs/sysdig.nix ./programs/systemtap.nix + ./programs/starship.nix ./programs/steam.nix ./programs/sway.nix ./programs/system-config-printer.nix diff --git a/nixos/modules/programs/starship.nix b/nixos/modules/programs/starship.nix new file mode 100644 index 000000000000..83d2272003c6 --- /dev/null +++ b/nixos/modules/programs/starship.nix @@ -0,0 +1,51 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.starship; + + settingsFormat = pkgs.formats.toml { }; + + settingsFile = settingsFormat.generate "starship.toml" cfg.settings; + +in { + options.programs.starship = { + enable = mkEnableOption "the Starship shell prompt"; + + settings = mkOption { + inherit (settingsFormat) type; + default = { }; + description = '' + Configuration included in starship.toml. + + See https://starship.rs/config/#prompt for documentation. + ''; + }; + }; + + config = mkIf cfg.enable { + programs.bash.promptInit = '' + if [[ $TERM != "dumb" && (-z $INSIDE_EMACS || $INSIDE_EMACS == "vterm") ]]; then + export STARSHIP_CONFIG=${settingsFile} + eval "$(${pkgs.starship}/bin/starship init bash)" + fi + ''; + + programs.fish.promptInit = '' + if test "$TERM" != "dumb" -a \( -z "$INSIDE_EMACS" -o "$INSIDE_EMACS" = "vterm" \) + set -x STARSHIP_CONFIG ${settingsFile} + eval (${pkgs.starship}/bin/starship init fish) + end + ''; + + programs.zsh.promptInit = '' + if [[ $TERM != "dumb" && (-z $INSIDE_EMACS || $INSIDE_EMACS == "vterm") ]]; then + export STARSHIP_CONFIG=${settingsFile} + eval "$(${pkgs.starship}/bin/starship init zsh)" + fi + ''; + }; + + meta.maintainers = pkgs.starship.meta.maintainers; +} diff --git a/pkgs/tools/misc/starship/default.nix b/pkgs/tools/misc/starship/default.nix index 89d4bb662da7..25a6aaecd022 100644 --- a/pkgs/tools/misc/starship/default.nix +++ b/pkgs/tools/misc/starship/default.nix @@ -44,6 +44,6 @@ rustPlatform.buildRustPackage rec { description = "A minimal, blazing fast, and extremely customizable prompt for any shell"; homepage = "https://starship.rs"; license = licenses.isc; - maintainers = with maintainers; [ bbigras davidtwco Br1ght0ne Frostman marsam ]; + maintainers = with maintainers; [ bbigras danth davidtwco Br1ght0ne Frostman marsam ]; }; } From f366ae6429096615914dd24a3ae59d7215b34180 Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Fri, 24 Dec 2021 11:24:29 +0000 Subject: [PATCH 2/2] nixos/starship: add a test --- nixos/tests/all-tests.nix | 1 + nixos/tests/starship.nix | 31 ++++++++++++++++++++++++++++ pkgs/tools/misc/starship/default.nix | 5 +++++ 3 files changed, 37 insertions(+) create mode 100644 nixos/tests/starship.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 5ebe07ad3cb7..1282d62272e1 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -445,6 +445,7 @@ in sslh = handleTest ./sslh.nix {}; sssd = handleTestOn ["x86_64-linux"] ./sssd.nix {}; sssd-ldap = handleTestOn ["x86_64-linux"] ./sssd-ldap.nix {}; + starship = handleTest ./starship.nix {}; step-ca = handleTestOn ["x86_64-linux"] ./step-ca.nix {}; strongswan-swanctl = handleTest ./strongswan-swanctl.nix {}; sudo = handleTest ./sudo.nix {}; diff --git a/nixos/tests/starship.nix b/nixos/tests/starship.nix new file mode 100644 index 000000000000..f21da1e6e255 --- /dev/null +++ b/nixos/tests/starship.nix @@ -0,0 +1,31 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "starship"; + meta.maintainers = pkgs.starship.meta.maintainers; + + machine = { + programs = { + fish.enable = true; + zsh.enable = true; + + starship = { + enable = true; + settings.format = ""; + }; + }; + + services.getty.autologinUser = "root"; + }; + + testScript = '' + start_all() + machine.wait_for_unit("default.target") + + for shell in ["bash", "fish", "zsh"]: + machine.send_chars(f"script -c {shell} /tmp/{shell}.txt\n") + machine.wait_until_tty_matches(1, f"Script started.*{shell}.txt") + machine.send_chars("exit\n") + machine.wait_until_tty_matches(1, "Script done") + machine.sleep(1) + machine.succeed(f"grep -q '' /tmp/{shell}.txt") + ''; +}) diff --git a/pkgs/tools/misc/starship/default.nix b/pkgs/tools/misc/starship/default.nix index 25a6aaecd022..165ed45d7b7a 100644 --- a/pkgs/tools/misc/starship/default.nix +++ b/pkgs/tools/misc/starship/default.nix @@ -6,6 +6,7 @@ , openssl , installShellFiles , libiconv +, nixosTests , Security }: @@ -40,6 +41,10 @@ rustPlatform.buildRustPackage rec { HOME=$TMPDIR ''; + passthru.tests = { + inherit (nixosTests) starship; + }; + meta = with lib; { description = "A minimal, blazing fast, and extremely customizable prompt for any shell"; homepage = "https://starship.rs";