aboutsummaryrefslogtreecommitdiff
path: root/modules/kobo.nix
blob: d46da7e277593b30a1d4a85e5eb882d4c69ae9d0 (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
{ config, pkgs, lib, ... }:
with builtins // lib;
let
  cfg = config.kobo;
in {
  imports = [
    ./kfmon.nix
    ./koreader.nix
    ./plato.nix
  ];

  options.kobo = {
    package = mkOption {
      type = types.package;
      description = "The resulting kobo configuration";
      default = if cfg.generate == "" then cfg.src else pkgs.stdenvNoCC.mkDerivation {
        inherit (cfg) src;
        name = "kobo-config";

        dontBuild = true;
        dontFixup = true;
        dontConfigure = true;
        dontPatch = true;

        installPhase = ''
          mkdir -p $out
          cp -rv . $out

          ${cfg.generate}
        '';
      };
    };

    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";
    };

    generate = mkOption {
      type = types.lines;
      default = "";
      description = "Script used to generate the kobo config";
    };
  };

  config = {
    kobo = {
      generate = mkBefore (concatStringsSep "\n" (
        optional config.kfmon.enable config.kfmon.generate ++
        optional config.plato.enable config.plato.generate ++
        optional config.koreader.enable config.koreader.generate
      ));
    };
  };
}