From 82264461e530e55af670c1d92a38eb8a63b5f4fb Mon Sep 17 00:00:00 2001 From: Karl Hallsby Date: Sat, 27 Jun 2020 15:26:11 +0200 Subject: [PATCH] mbsync: only generate group/channel configuration if channels present Typically, when a group is specified, channels will be specified as well. However, if due to error or mistake, the user forgets to specify ANY channels for a group, we should not generate that group's information. This means that no channels are specified (which maps the remote master to local slave). In addition, the `Group ` block (which brings the separate channels together) is also not generated. Another thing to consider is that a user might specify a group and a channel, but perform no additional configuration of the channel. In a configuration, this would be realized by `accounts.email.accounts..mbsync.groups..channels.;` This creates the channel with the name `` and the `masterPattern`, `slavePattern`, and `patterns` fields use their defaults. By definitions set within mbsync, these defaults actually specify that the remote master's `INBOX` mail directory is synchronized to the local slave's `INBOX` directory. So, if there is a channel that has no fields specified, then we DO want to generate its configuration. But if there is a group that has no channels, then we do NOT generate it. --- modules/programs/mbsync.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/programs/mbsync.nix b/modules/programs/mbsync.nix index ba51d90b..7bfc4826 100644 --- a/modules/programs/mbsync.nix +++ b/modules/programs/mbsync.nix @@ -99,8 +99,8 @@ let + "\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: - mapAttrsToList (channelName: info: genChannelString groupName info) channels; + genChannelStrings = groupName: channels: optionals (channels != { }) + (mapAttrsToList (channelName: info: genChannelString groupName info) channels); # Given a group, return a string that configures all the channels within # the group. genGroupsChannels = group: concatStrings @@ -117,11 +117,11 @@ let # make "Channel -" for each channel to list os strings genChannelStrings = groupName: channels: mapAttrsToList (name: info: "Channel ${groupName}-${name}") channels; - # Take in 1 group, construct the "Group " header, and construct - # each of the channels. - genGroupChannelString = group: - [("Group " + group.name)] ++ - (genChannelStrings group.name group.channels); + # Take in 1 group, construct the "Group " header, and if the group + # is NOT empty, construct each of the channels. + genGroupChannelString = group: optionals (groups != { }) + ([("Group " + group.name)] ++ + (genChannelStrings group.name group.channels)); # Given set of groups, generates list of strings, where each string is one # of the groups and its consituent channels. genGroupsStrings = mapAttrsToList (name: info: concatStringsSep "\n"