vdirsyncer: add urlCommand and userNameCommand options
This commit is contained in:
parent
1c2acec999
commit
19b87b9ae6
|
@ -58,15 +58,6 @@ let
|
||||||
description = "User name for authentication.";
|
description = "User name for authentication.";
|
||||||
};
|
};
|
||||||
|
|
||||||
# userNameCommand = mkOption {
|
|
||||||
# type = types.nullOr (types.listOf types.str);
|
|
||||||
# default = null;
|
|
||||||
# example = [ "~/get-username.sh" ];
|
|
||||||
# description = ''
|
|
||||||
# A command that prints the user name to standard output.
|
|
||||||
# '';
|
|
||||||
# };
|
|
||||||
|
|
||||||
passwordCommand = mkOption {
|
passwordCommand = mkOption {
|
||||||
type = types.nullOr (types.listOf types.str);
|
type = types.nullOr (types.listOf types.str);
|
||||||
default = null;
|
default = null;
|
||||||
|
|
|
@ -10,6 +10,20 @@ in {
|
||||||
options.vdirsyncer = {
|
options.vdirsyncer = {
|
||||||
enable = mkEnableOption "synchronization using vdirsyncer";
|
enable = mkEnableOption "synchronization using vdirsyncer";
|
||||||
|
|
||||||
|
urlCommand = mkOption {
|
||||||
|
type = types.nullOr (types.listOf types.str);
|
||||||
|
default = null;
|
||||||
|
example = [ "~/get-url.sh" ];
|
||||||
|
description = "A command that prints the URL of the storage.";
|
||||||
|
};
|
||||||
|
|
||||||
|
userNameCommand = mkOption {
|
||||||
|
type = types.nullOr (types.listOf types.str);
|
||||||
|
default = null;
|
||||||
|
example = [ "~/get-username.sh" ];
|
||||||
|
description = "A command that prints the user name to standard output.";
|
||||||
|
};
|
||||||
|
|
||||||
collections = mkOption {
|
collections = mkOption {
|
||||||
type = types.nullOr (types.listOf collection);
|
type = types.nullOr (types.listOf collection);
|
||||||
default = null;
|
default = null;
|
||||||
|
|
|
@ -32,27 +32,25 @@ let
|
||||||
});
|
});
|
||||||
|
|
||||||
remoteStorage = a:
|
remoteStorage = a:
|
||||||
filterAttrs (_: v: v != null) ((getAttrs [
|
filterAttrs (_: v: v != null)
|
||||||
"type"
|
((getAttrs [ "type" "url" "userName" "passwordCommand" ] a.remote)
|
||||||
"url"
|
// (if a.vdirsyncer == null then
|
||||||
"userName"
|
{ }
|
||||||
#"userNameCommand"
|
else
|
||||||
"passwordCommand"
|
getAttrs [
|
||||||
] a.remote) // (if a.vdirsyncer == null then
|
"urlCommand"
|
||||||
{ }
|
"userNameCommand"
|
||||||
else
|
"itemTypes"
|
||||||
getAttrs [
|
"verify"
|
||||||
"itemTypes"
|
"verifyFingerprint"
|
||||||
"verify"
|
"auth"
|
||||||
"verifyFingerprint"
|
"authCert"
|
||||||
"auth"
|
"userAgent"
|
||||||
"authCert"
|
"tokenFile"
|
||||||
"userAgent"
|
"clientIdCommand"
|
||||||
"tokenFile"
|
"clientSecretCommand"
|
||||||
"clientIdCommand"
|
"timeRange"
|
||||||
"clientSecretCommand"
|
] a.vdirsyncer));
|
||||||
"timeRange"
|
|
||||||
] a.vdirsyncer));
|
|
||||||
|
|
||||||
pair = a:
|
pair = a:
|
||||||
with a.vdirsyncer;
|
with a.vdirsyncer;
|
||||||
|
@ -77,6 +75,8 @@ let
|
||||||
''post_hook = "${v}"''
|
''post_hook = "${v}"''
|
||||||
else if (n == "url") then
|
else if (n == "url") then
|
||||||
''url = "${v}"''
|
''url = "${v}"''
|
||||||
|
else if (n == "urlCommand") then
|
||||||
|
"url.fetch = ${listString (map wrap ([ "command" ] ++ v))}"
|
||||||
else if (n == "timeRange") then ''
|
else if (n == "timeRange") then ''
|
||||||
start_date = "${v.start}"
|
start_date = "${v.start}"
|
||||||
end_date = "${v.end}"'' else if (n == "itemTypes") then
|
end_date = "${v.end}"'' else if (n == "itemTypes") then
|
||||||
|
@ -196,6 +196,9 @@ in {
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
assertions = let
|
assertions = let
|
||||||
|
|
||||||
|
mutuallyExclusiveOptions =
|
||||||
|
[ [ "url" "urlCommand" ] [ "userName" "userNameCommand" ] ];
|
||||||
|
|
||||||
requiredOptions = t:
|
requiredOptions = t:
|
||||||
if (t == "caldav" || t == "carddav" || t == "http") then
|
if (t == "caldav" || t == "carddav" || t == "http") then
|
||||||
[ "url" ]
|
[ "url" ]
|
||||||
|
@ -213,6 +216,7 @@ in {
|
||||||
|
|
||||||
allowedOptions = let
|
allowedOptions = let
|
||||||
remoteOptions = [
|
remoteOptions = [
|
||||||
|
"urlCommand"
|
||||||
"userName"
|
"userName"
|
||||||
"userNameCommand"
|
"userNameCommand"
|
||||||
"password"
|
"password"
|
||||||
|
@ -264,7 +268,16 @@ in {
|
||||||
Storage ${n} is of type ${v.type}, but required
|
Storage ${n} is of type ${v.type}, but required
|
||||||
option ${a} is not set.
|
option ${a} is not set.
|
||||||
'';
|
'';
|
||||||
}]) required)) (removeAttrs v [ "type" "_module" ]);
|
}]) required) ++ map (attrs:
|
||||||
|
let
|
||||||
|
defined = attrNames (filterAttrs (n: v: v != null)
|
||||||
|
(genAttrs attrs (a: v.${a} or null)));
|
||||||
|
in {
|
||||||
|
assertion = length defined <= 1;
|
||||||
|
message = "Storage ${n} has mutually exclusive options: ${
|
||||||
|
concatStringsSep ", " defined
|
||||||
|
}";
|
||||||
|
}) mutuallyExclusiveOptions) (removeAttrs v [ "type" "_module" ]);
|
||||||
|
|
||||||
storageAssertions = flatten (mapAttrsToList assertStorage localStorages)
|
storageAssertions = flatten (mapAttrsToList assertStorage localStorages)
|
||||||
++ flatten (mapAttrsToList assertStorage remoteStorages);
|
++ flatten (mapAttrsToList assertStorage remoteStorages);
|
||||||
|
|
Loading…
Reference in a new issue