From e469020cb0b3ca113065ee1b68d12315e679c7c3 Mon Sep 17 00:00:00 2001 From: Karl Hallsby Date: Fri, 26 Jun 2020 18:32:47 +0200 Subject: [PATCH] mbsync: write function to generate group-channel blocks This function takes in a set of groups, and their consituent channels and writes the appropriate .mbsyncrc block. The block is as shown below: Group groupName1 Channel channelName1 Channel channelName2 Group groupName2 Channel channelName3 Each group must have a unique name, no matter which account it is declared under. The same holds true for channels. However, if there is a group that shares the same name as the channel, the channel will effectively be "shadowed" by the group, and mbsync will default to working with the group in that case. --- modules/programs/mbsync.nix | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/programs/mbsync.nix b/modules/programs/mbsync.nix index f2814b39..2ed0c6d0 100644 --- a/modules/programs/mbsync.nix +++ b/modules/programs/mbsync.nix @@ -78,6 +78,27 @@ let Expunge = masterSlaveMapping.${mbsync.expunge}; SyncState = "*"; } // mbsync.extraConfig.channel) + "\n"; + # Given the attr set of groups, return a string of channels to put into each group. + # Given the attr set of groups, return a string which maps channels to groups + genAccountGroups = groups: + let + # Given the name of the group and the attribute set of channels, make + # 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); + # 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" + (genGroupChannelString groups.${name})) groups; + in (concatStringsSep "\n\n" genGroupsStrings) # Put all strings together. + # 2 \n needed in concatStringsSep because last element genGroupsStrings + # has no \n. + + "\n\n"; # Additional spacing after this account's group setup. genGroupConfig = name: channels: let