36a53d9f26
This process was automated by [my fork of `nix-doc-munge`]. All conversions were automatically checked to produce the same DocBook result when converted back, modulo minor typographical/formatting differences on the acceptable-to-desirable spectrum. To reproduce this commit, run: $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \ nix shell nixpkgs#coreutils \ -c find . -name '*.nix' \ -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \ {} + $ ./format [my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
164 lines
4.3 KiB
Nix
164 lines
4.3 KiB
Nix
{ config, lib, pkgs, ... }:
|
||
|
||
with lib;
|
||
|
||
let
|
||
|
||
cfg = config.accounts.calendar;
|
||
|
||
localModule = name:
|
||
types.submodule {
|
||
options = {
|
||
path = mkOption {
|
||
type = types.str;
|
||
default = "${cfg.basePath}/${name}";
|
||
defaultText = "‹accounts.calendar.basePath›/‹name›";
|
||
description = lib.mdDoc "The path of the storage.";
|
||
};
|
||
|
||
type = mkOption {
|
||
type = types.enum [ "filesystem" "singlefile" ];
|
||
description = lib.mdDoc "The type of the storage.";
|
||
};
|
||
|
||
fileExt = mkOption {
|
||
type = types.nullOr types.str;
|
||
default = null;
|
||
description = lib.mdDoc "The file extension to use.";
|
||
};
|
||
|
||
encoding = mkOption {
|
||
type = types.nullOr types.str;
|
||
default = null;
|
||
description = lib.mdDoc ''
|
||
File encoding for items, both content and file name.
|
||
Defaults to UTF-8.
|
||
'';
|
||
};
|
||
};
|
||
};
|
||
|
||
remoteModule = types.submodule {
|
||
options = {
|
||
type = mkOption {
|
||
type = types.enum [ "caldav" "http" "google_calendar" ];
|
||
description = lib.mdDoc "The type of the storage.";
|
||
};
|
||
|
||
url = mkOption {
|
||
type = types.nullOr types.str;
|
||
default = null;
|
||
description = lib.mdDoc "The URL of the storage.";
|
||
};
|
||
|
||
userName = mkOption {
|
||
type = types.nullOr types.str;
|
||
default = null;
|
||
description = lib.mdDoc "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 {
|
||
type = types.nullOr (types.listOf types.str);
|
||
default = null;
|
||
example = [ "pass" "caldav" ];
|
||
description = lib.mdDoc ''
|
||
A command that prints the password to standard output.
|
||
'';
|
||
};
|
||
};
|
||
};
|
||
|
||
calendarOpts = { name, config, ... }: {
|
||
options = {
|
||
name = mkOption {
|
||
type = types.str;
|
||
readOnly = true;
|
||
description = lib.mdDoc ''
|
||
Unique identifier of the calendar. This is set to the
|
||
attribute name of the calendar configuration.
|
||
'';
|
||
};
|
||
|
||
primary = mkOption {
|
||
type = types.bool;
|
||
default = false;
|
||
description = lib.mdDoc ''
|
||
Whether this is the primary account. Only one account may be
|
||
set as primary.
|
||
'';
|
||
};
|
||
|
||
primaryCollection = mkOption {
|
||
type = types.str;
|
||
description = lib.mdDoc ''
|
||
The primary collection of the account. Required when an
|
||
account has multiple collections.
|
||
'';
|
||
};
|
||
|
||
local = mkOption {
|
||
type = types.nullOr (localModule name);
|
||
default = null;
|
||
description = lib.mdDoc ''
|
||
Local configuration for the calendar.
|
||
'';
|
||
};
|
||
|
||
remote = mkOption {
|
||
type = types.nullOr remoteModule;
|
||
default = null;
|
||
description = lib.mdDoc ''
|
||
Remote configuration for the calendar.
|
||
'';
|
||
};
|
||
};
|
||
|
||
config = { name = name; };
|
||
};
|
||
|
||
in {
|
||
options.accounts.calendar = {
|
||
basePath = mkOption {
|
||
type = types.str;
|
||
apply = p:
|
||
if hasPrefix "/" p then p else "${config.home.homeDirectory}/${p}";
|
||
description = lib.mdDoc ''
|
||
The base directory in which to save calendars. May be a
|
||
relative path, in which case it is relative the home
|
||
directory.
|
||
'';
|
||
};
|
||
|
||
accounts = mkOption {
|
||
type = types.attrsOf (types.submodule [
|
||
calendarOpts
|
||
(import ../programs/vdirsyncer-accounts.nix)
|
||
(import ../programs/khal-accounts.nix)
|
||
(import ../programs/khal-calendar-accounts.nix)
|
||
]);
|
||
default = { };
|
||
description = lib.mdDoc "List of calendars.";
|
||
};
|
||
};
|
||
config = mkIf (cfg.accounts != { }) {
|
||
assertions = let
|
||
primaries =
|
||
catAttrs "name" (filter (a: a.primary) (attrValues cfg.accounts));
|
||
in [{
|
||
assertion = length primaries <= 1;
|
||
message = "Must have at most one primary calendar account but found "
|
||
+ toString (length primaries) + ", namely "
|
||
+ concatStringsSep ", " primaries;
|
||
}];
|
||
};
|
||
}
|