From 2ce482d187d5acc4c00e9482fa8ab8a9af04e379 Mon Sep 17 00:00:00 2001 From: Karl Hallsby Date: Sat, 27 Jun 2020 02:14:20 +0200 Subject: [PATCH] mbsync: create nested-let function to generate channel pattern This pattern is required to either NOT be present, which means the master pattern is used to match, or it has a list of patterns to use beneath the master maildir to match against. This function checks to ensure that if patterns is not empty, ONLY then is the `Pattern` keyword printed. Otherwise, there are many, many problems. If there IS a list of patterns, then we use proper escaping methods to ensure that the exact string is constructed. --- modules/programs/mbsync.nix | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/programs/mbsync.nix b/modules/programs/mbsync.nix index 14dc8ab6..a44d009c 100644 --- a/modules/programs/mbsync.nix +++ b/modules/programs/mbsync.nix @@ -87,10 +87,22 @@ let # Given the name of the group this channel is part of and the channel # itself, generate the string for the desired configuration. genChannelString = groupName: channel: + let + escapeValue = escape [ ''\"'' ]; + hasSpace = v: builtins.match ".* .*" v != null; + # Given a list of patterns, will return the string requested. + # Only prints if the pattern is NOT the empty list, the default. + genChannelPatterns = patterns: if (length patterns) != 0 then + "Pattern " + concatStringsSep " " (map + (pat: if hasSpace pat then escapeValue pat else pat) patterns) + "\n" + else ""; + in genSection "Channel ${groupName}-${channel.name}" ({ Master = ":${storeName}-remote:${channel.masterPattern}"; Slave = ":${storeName}-local:${channel.slavePattern}"; - }) + "\n"; + } // channel.extraConfig) + + genChannelPatterns channel.patterns + + "\n"; # Given the group name, and a attr set of channels within that group, # Generate a list of strings for each channels' configuration. genChannelStrings = groupName: channels: