mbsync: add some required assertions

This commit is contained in:
Nadrieril 2019-01-15 21:39:33 +01:00 committed by Robert Helgesson
parent 2410bc603b
commit 81ec856a0f
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -34,24 +34,24 @@ let
let
escapeValue = escape [ "\"" ];
hasSpace = v: builtins.match ".* .*" v != null;
genValue = v:
genValue = n: v:
if isList v
then concatMapStringsSep " " genValue v
then concatMapStringsSep " " (genValue n) v
else if isBool v then (if v then "yes" else "no")
else if isInt v then toString v
else if hasSpace v then "\"${escapeValue v}\""
else v;
else if isString v && hasSpace v then "\"${escapeValue v}\""
else if isString v then v
else
let prettyV = lib.generators.toPretty {} v;
in throw "mbsync: unexpected value for option ${n}: '${prettyV}'";
in
''
${header}
${concatStringsSep "\n"
(mapAttrsToList (n: v: "${n} ${genValue v}") entries)}
(mapAttrsToList (n: v: "${n} ${genValue n v}") entries)}
'';
genAccountConfig = account: with account;
if (imap == null || maildir == null)
then ""
else
genSection "IMAPAccount ${name}" (
{
Host = imap.host;
@ -144,28 +144,22 @@ in
};
config = mkIf cfg.enable {
assertions = [
(
assertions =
let
badAccounts = filter (a: a.maildir == null) mbsyncAccounts;
in
{
assertion = badAccounts == [];
message = "mbsync: Missing maildir configuration for accounts: "
+ concatMapStringsSep ", " (a: a.name) badAccounts;
}
)
(
checkAccounts = pred: msg:
let
badAccounts = filter (a: a.imap == null) mbsyncAccounts;
in
{
badAccounts = filter pred mbsyncAccounts;
in {
assertion = badAccounts == [];
message = "mbsync: Missing IMAP configuration for accounts: "
message = "mbsync: ${msg} for accounts: "
+ concatMapStringsSep ", " (a: a.name) badAccounts;
}
)
};
in
[
(checkAccounts (a: a.maildir == null) "Missing maildir configuration")
(checkAccounts (a: a.imap == null) "Missing IMAP configuration")
(checkAccounts (a: a.passwordCommand == null) "Missing passwordCommand")
(checkAccounts (a: a.userName == null) "Missing username")
];
home.packages = [ cfg.package ];