1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-30 06:59:45 +01:00

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