From 25a6a6d2984e70c9a07c8f8a69ebe24e6c700abf Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sat, 3 Apr 2021 17:47:40 -0600 Subject: [PATCH] neomutt: support list in binds.map (#1885) * neomutt: support list in binds.map Closes #1245 Adds support for specifying programs.neomutt.binds[].map as a list. If specified as a list, then the binds will be concatenated with a ",". * neomutt: add deprecation warning for (binds|macros).map as string Added note that specifying 'programs.neomutt.(binds|macros).map' as a string is deprecated. Instead, use the list form. * neomutt: note deprecation warning in release notes Added note that specifying 'programs.neomutt.(binds|macros).map' as a single string is deprecated in favor of specifying it as a list * neomutt: add assertion that map is not empty Added an assertion that each 'programs.neomutt.(binds|macros).map' list contains at least one element. --- doc/release-notes/rl-2105.adoc | 4 ++ modules/programs/neomutt.nix | 59 ++++++++++----- tests/modules/programs/neomutt/default.nix | 4 ++ .../neomutt/neomutt-with-binds-expected.conf | 34 +++++++++ .../neomutt-with-binds-invalid-settings.nix | 27 +++++++ .../neomutt-with-binds-with-warning.nix | 71 +++++++++++++++++++ .../programs/neomutt/neomutt-with-binds.nix | 67 +++++++++++++++++ 7 files changed, 247 insertions(+), 19 deletions(-) create mode 100644 tests/modules/programs/neomutt/neomutt-with-binds-expected.conf create mode 100644 tests/modules/programs/neomutt/neomutt-with-binds-invalid-settings.nix create mode 100644 tests/modules/programs/neomutt/neomutt-with-binds-with-warning.nix create mode 100644 tests/modules/programs/neomutt/neomutt-with-binds.nix diff --git a/doc/release-notes/rl-2105.adoc b/doc/release-notes/rl-2105.adoc index 2cda4a3d9..3ca917e13 100644 --- a/doc/release-notes/rl-2105.adoc +++ b/doc/release-notes/rl-2105.adoc @@ -129,6 +129,10 @@ https://github.com/jonls/redshift/blob/master/redshift.conf.sample[redshift.conf https://gitlab.com/chinstrap/gammastep/-/blob/master/gammastep.conf.sample[gammastep.conf.sample] for the available additional options in each program. +* Specifying `programs.neomutt.binds.map` or `programs.neomutt.macros.map` as a + single string is now deprecated in favor of specfiying it as a list of + strings. + * The `programs.neovim.configure` is deprecated in favor of other `programs.neovim` options; please use the other options at your disposal: + diff --git a/modules/programs/neomutt.nix b/modules/programs/neomutt.nix index 96360cb28..b8c793f8f 100644 --- a/modules/programs/neomutt.nix +++ b/modules/programs/neomutt.nix @@ -54,21 +54,23 @@ let bindModule = types.submodule { options = { map = mkOption { - type = types.enum [ - "alias" - "attach" - "browser" - "compose" - "editor" - "generic" - "index" - "mix" - "pager" - "pgp" - "postpone" - "query" - "smime" - ]; + type = let + menus = [ + "alias" + "attach" + "browser" + "compose" + "editor" + "generic" + "index" + "mix" + "pager" + "pgp" + "postpone" + "query" + "smime" + ]; + in with types; either (enum menus) (listOf (enum menus)); default = "index"; description = "Select the menu to bind the command to."; }; @@ -154,11 +156,16 @@ let set sidebar_format = '${cfg.sidebar.format}' ''; - bindSection = concatMapStringsSep "\n" - (bind: ''bind ${bind.map} ${bind.key} "${bind.action}"'') cfg.binds; + genBindMapper = bindType: + concatMapStringsSep "\n" (bind: + '' + ${bindType} ${ + concatStringsSep "," (toList bind.map) + } ${bind.key} "${bind.action}"''); - macroSection = concatMapStringsSep "\n" - (bind: ''macro ${bind.map} ${bind.key} "${bind.action}"'') cfg.macros; + bindSection = (genBindMapper "bind") cfg.binds; + + macroSection = (genBindMapper "macro") cfg.macros; mailCheckSection = '' set mail_check_stats @@ -316,5 +323,19 @@ in { source ${accountFilename primary} ''; }; + + assertions = [{ + assertion = + ((filter (b: (length (toList b.map)) == 0) (cfg.binds ++ cfg.macros)) + == [ ]); + message = + "The 'programs.neomutt.(binds|macros).map' list must contain at least one element."; + }]; + + warnings = + let hasOldBinds = binds: (filter (b: !(isList b.map)) binds) != [ ]; + in mkIf (hasOldBinds (cfg.binds ++ cfg.macros)) [ + "Specifying 'programs.neomutt.(binds|macros).map' as a string is deprecated, use a list of strings instead. See https://github.com/nix-community/home-manager/pull/1885." + ]; }; } diff --git a/tests/modules/programs/neomutt/default.nix b/tests/modules/programs/neomutt/default.nix index 5a13c9168..40ca4b024 100644 --- a/tests/modules/programs/neomutt/default.nix +++ b/tests/modules/programs/neomutt/default.nix @@ -2,4 +2,8 @@ neomutt-simple = ./neomutt.nix; neomutt-with-msmtp = ./neomutt-with-msmtp.nix; neomutt-not-primary = ./neomutt-not-primary.nix; + neomutt-with-binds = ./neomutt-with-binds.nix; + neomutt-with-binds-with-warning = ./neomutt-with-binds-with-warning.nix; + neomutt-with-binds-invalid-settings = + ./neomutt-with-binds-invalid-settings.nix; } diff --git a/tests/modules/programs/neomutt/neomutt-with-binds-expected.conf b/tests/modules/programs/neomutt/neomutt-with-binds-expected.conf new file mode 100644 index 000000000..21ae55a92 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-binds-expected.conf @@ -0,0 +1,34 @@ +# Generated by Home Manager. +set header_cache = "/home/hm-user/.cache/neomutt/headers/" +set message_cachedir = "/home/hm-user/.cache/neomutt/messages/" +set editor = "$EDITOR" +set implicit_autoview = yes + +alternative_order text/enriched text/plain text + +set delete = yes + +# Binds +bind editor "complete-query" +bind index,pager \Cp "sidebar-prev" + +# Macros +macro index s "?" +macro index,pager c "?^K=" + + + +# Extra configuration + + + + +# Register accounts +# register account hm@example.com +mailboxes "/home/hm-user/Mail/hm@example.com/Inbox" +folder-hook /home/hm-user/Mail/hm@example.com/ " \ + source /home/hm-user/.config/neomutt/hm@example.com " + + +# Source primary account +source /home/hm-user/.config/neomutt/hm@example.com diff --git a/tests/modules/programs/neomutt/neomutt-with-binds-invalid-settings.nix b/tests/modules/programs/neomutt/neomutt-with-binds-invalid-settings.nix new file mode 100644 index 000000000..deaf021f7 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-binds-invalid-settings.nix @@ -0,0 +1,27 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.neomutt = { + enable = true; + + binds = [{ + action = "complete-query"; + key = ""; + map = [ ]; + }]; + + macros = [{ + action = "?^K="; + key = "c"; + map = [ ]; + }]; + }; + + test.asserts.assertions.expected = [ + "The 'programs.neomutt.(binds|macros).map' list must contain at least one element." + ]; + }; +} diff --git a/tests/modules/programs/neomutt/neomutt-with-binds-with-warning.nix b/tests/modules/programs/neomutt/neomutt-with-binds-with-warning.nix new file mode 100644 index 000000000..529d28475 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-binds-with-warning.nix @@ -0,0 +1,71 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + accounts.email.accounts = { + "hm@example.com" = { + notmuch.enable = true; + neomutt = { + enable = true; + extraConfig = '' + color status cyan default + ''; + }; + imap.port = 993; + }; + }; + + programs.neomutt = { + enable = true; + vimKeys = false; + + binds = [ + { + action = "complete-query"; + key = ""; + map = "editor"; + } + { + action = "sidebar-prev"; + key = "\\Cp"; + map = [ "index" "pager" ]; + } + ]; + + macros = [ + { + action = "?"; + key = "s"; + map = "index"; + } + { + action = "?^K="; + key = "c"; + map = [ "index" "pager" ]; + } + ]; + }; + + nixpkgs.overlays = + [ (self: super: { neomutt = pkgs.writeScriptBin "dummy-neomutt" ""; }) ]; + + test.asserts.warnings.expected = [ + "Specifying 'programs.neomutt.(binds|macros).map' as a string is deprecated, use a list of strings instead. See https://github.com/nix-community/home-manager/pull/1885." + ]; + + nmt.script = '' + assertFileExists home-files/.config/neomutt/neomuttrc + assertFileExists home-files/.config/neomutt/hm@example.com + assertFileContent home-files/.config/neomutt/neomuttrc ${ + ./neomutt-with-binds-expected.conf + } + assertFileContent home-files/.config/neomutt/hm@example.com ${ + ./hm-example.com-expected + } + ''; + }; +} diff --git a/tests/modules/programs/neomutt/neomutt-with-binds.nix b/tests/modules/programs/neomutt/neomutt-with-binds.nix new file mode 100644 index 000000000..bd40cd893 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-binds.nix @@ -0,0 +1,67 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + accounts.email.accounts = { + "hm@example.com" = { + notmuch.enable = true; + neomutt = { + enable = true; + extraConfig = '' + color status cyan default + ''; + }; + imap.port = 993; + }; + }; + + programs.neomutt = { + enable = true; + vimKeys = false; + + binds = [ + { + action = "complete-query"; + key = ""; + map = [ "editor" ]; + } + { + action = "sidebar-prev"; + key = "\\Cp"; + map = [ "index" "pager" ]; + } + ]; + + macros = [ + { + action = "?"; + key = "s"; + map = [ "index" ]; + } + { + action = "?^K="; + key = "c"; + map = [ "index" "pager" ]; + } + ]; + }; + + nixpkgs.overlays = + [ (self: super: { neomutt = pkgs.writeScriptBin "dummy-neomutt" ""; }) ]; + + nmt.script = '' + assertFileExists home-files/.config/neomutt/neomuttrc + assertFileExists home-files/.config/neomutt/hm@example.com + assertFileContent home-files/.config/neomutt/neomuttrc ${ + ./neomutt-with-binds-expected.conf + } + assertFileContent home-files/.config/neomutt/hm@example.com ${ + ./hm-example.com-expected + } + ''; + }; +}