From acf106ced027e6566b525b31488f314f400f2391 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sat, 29 Feb 2020 22:17:47 +0100 Subject: [PATCH] starship: give `settings` option more specific type This more readily allows merging configurations. Fixes #1023 --- modules/programs/starship.nix | 17 ++++++- tests/default.nix | 1 + tests/modules/programs/starship/default.nix | 1 + .../programs/starship/settings-expected.toml | 27 ++++++++++ tests/modules/programs/starship/settings.nix | 49 +++++++++++++++++++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/modules/programs/starship/default.nix create mode 100644 tests/modules/programs/starship/settings-expected.toml create mode 100644 tests/modules/programs/starship/settings.nix diff --git a/modules/programs/starship.nix b/modules/programs/starship.nix index a38ce4d8b..cea9c49be 100644 --- a/modules/programs/starship.nix +++ b/modules/programs/starship.nix @@ -31,8 +31,23 @@ in { }; settings = mkOption { - type = types.attrs; + type = with types; + let + prim = either bool (either int str); + primOrPrimAttrs = either prim (attrsOf prim); + entry = either prim (listOf primOrPrimAttrs); + entryOrAttrsOf = t: either entry (attrsOf t); + entries = entryOrAttrsOf (entryOrAttrsOf entry); + in attrsOf entries // { description = "Starship configuration"; }; default = { }; + example = literalExample '' + { + add_newline = false; + prompt_order = [ "line_break" "package" "line_break" "character" ]; + scan_timeout = 10; + character.symbol = "➜"; + } + ''; description = '' Configuration written to ~/.config/starship.toml. diff --git a/tests/default.nix b/tests/default.nix index df69dc22a..51462fa30 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -37,6 +37,7 @@ import nmt { ./modules/programs/newsboat ./modules/programs/readline ./modules/programs/ssh + ./modules/programs/starship ./modules/programs/texlive ./modules/programs/tmux ./modules/programs/zsh diff --git a/tests/modules/programs/starship/default.nix b/tests/modules/programs/starship/default.nix new file mode 100644 index 000000000..814aed658 --- /dev/null +++ b/tests/modules/programs/starship/default.nix @@ -0,0 +1 @@ +{ starship-settings = ./settings.nix; } diff --git a/tests/modules/programs/starship/settings-expected.toml b/tests/modules/programs/starship/settings-expected.toml new file mode 100644 index 000000000..a4fb0ee55 --- /dev/null +++ b/tests/modules/programs/starship/settings-expected.toml @@ -0,0 +1,27 @@ +add_newline = false +prompt_order = ["line_break", "package", "line_break", "character"] +scan_timeout = 10 + +[aws] +disabled = true +style = "bold blue" + +[battery] +charging_symbol = "⚡️" + +[[battery.display]] +style = "bold red" +threshold = 10 + +[[battery.display]] +style = "bold yellow" +threshold = 30 + +[character] +symbol = "➜" + +[memory_usage] +threshold = -1 + +[package] +disabled = true diff --git a/tests/modules/programs/starship/settings.nix b/tests/modules/programs/starship/settings.nix new file mode 100644 index 000000000..e7a27733d --- /dev/null +++ b/tests/modules/programs/starship/settings.nix @@ -0,0 +1,49 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.starship = { + enable = true; + + settings = mkMerge [ + { + add_newline = false; + prompt_order = [ "line_break" "package" "line_break" "character" ]; + scan_timeout = 10; + character.symbol = "➜"; + package.disabled = true; + memory_usage.threshold = -1; + aws.style = "bold blue"; + battery = { + charging_symbol = "⚡️"; + display = [{ + threshold = 10; + style = "bold red"; + }]; + }; + } + + { + aws.disabled = true; + + battery.display = [{ + threshold = 30; + style = "bold yellow"; + }]; + } + ]; + }; + + nixpkgs.overlays = [ + (self: super: { starship = pkgs.writeScriptBin "dummy-starship" ""; }) + ]; + + nmt.script = '' + assertFileContent \ + home-files/.config/starship.toml \ + ${./settings-expected.toml} + ''; + }; +}