aboutsummaryrefslogtreecommitdiff
path: root/modules/koreader/default.nix
blob: db1221906e2cad5602c6a7a9f4ef7aeafee77abf (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
{ config, pkgs, lib, ... }:
with builtins // lib;
let
  cfg = config.koreader;
in {
  options.koreader = {
    enable = mkEnableOption "KOReader";

    package = mkPackageOption pkgs "kobo-koreader" {};

    _allFiles = mkOption {
      type = types.package;
      readOnly = true;
      internal = true;
      default = (pkgs.callPackage ../lib/merge-files.nix {}) ([
        cfg.package
      ] ++ attrValues cfg.file);
    };

    path = mkOption {
      type = types.str;
      readOnly = true;
      internal = true;
      default = ".adds/koreader";
    };

    devicePath = mkOption {
      type = types.str;
      readOnly = true;
      internal = true;
      default = "/mnt/onboard/${cfg.path}";
    };

    file = mkOption {
      default = {};
      type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {}));
    };

    nickel = {
      enable = mkEnableOption "Add NickelMenu entry" // { default = true; };
    };
  };

  config = {
    nickel.menu.item = mkIf (cfg.enable && cfg.nickel.enable) {
      koreader = singleton {
        location = "main";
        label = "KOReader";
        action = "cmd_spawn";
        arg = [
          "quiet"
          "exec ${cfg.devicePath}/koreader.sh";
        ];
      };
    };
  };
}