aboutsummaryrefslogtreecommitdiff
path: root/modules/kobo.nix
blob: 21f79956f580588b71d76907fccbeb159cb7a0dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{ config, pkgs, lib, options, ... }:
with builtins // lib;
let
  cfg = config.kobo;
  ini = pkgs.formats.ini {};
in {
  options.kobo = {
    enable = mkEnableOption "main configurations";

    path = mkOption {
      type = types.str;
      default = ".kobo/Kobo";
      description = "Relative path to main Kobo config";
    };

    file = mkOption {
      type = options.file.type;
      default = {};
      description = "Files relative to ${cfg.path}";
    };

    manifest = mkOption {
      type = options.manifest.type;
      default = {};
      description = "Manifest relative to ${cfg.path}";
    };

    config = mkOption {
      type = ini.type;
      default = {};
      description = "https://wiki.mobileread.com/wiki/Kobo_Configuration_Options";
    };

    # src = mkOption {
    #   type = types.package;
    #   description = "The base source files to use";
    #   default = with pkgs.kobo.src;
    #     if config.plato.enable && config.koreader.enable then KOReader-Plato
    #     else if config.plato.enable then Plato
    #     else if config.koreader.enable then KOReader
    #     else if config.kfmon.enable then KFMon
    #     else error "At least one of plato, koreader or kfmon must be enabled in order to use a default package";
    # };

  };

  config = {
    file = mapAttrs' (n: v: {
      name = "kobo-${n}";
      value = v // {
        target = "${cfg.path}/${v.target}";
      };
    }) cfg.file;

    manifest = mapAttrs' (n: v: {
      name = "kobo-${n}";
      value = v // {
        targets = map (x: "${cfg.path}/${x}") v.targets;
      };
    }) cfg.manifest;

    kobo = {
      config = {
        FeatureSettings = {
          ExcludeSyncFolders = ''(\.(?!kobo|adobe).+|([^.][^/]*/)+\..+)'';
        };
        ApplicationPreferences = {
          QuickTourShown = true;
        };
      };
      file = mkMerge [
        (mkIf (cfg.config != {}) {
          "Kobo eReader.conf".text = generators.toINI {} cfg.config;
        })
      ];

      manifest = {
        "Kobo eReader.conf".mergeTool = local: remote: ''
          ${getBin pkgs.crudini}/bin/crudini --merge "${remote}" < "${local}" > "${remote}"
        '';
      };
    };


  }