{ 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.symlinkJoin { name = "koreader-files"; paths = mapAttrsToList (_: v: v._package) cfg.file ++ [ cfg.package ]; }; }; 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 {})); apply = filterAttrs (_: v: v.enable); }; nickel = { enable = mkEnableOption "Add NickelMenu entry" // { default = true; }; }; }; config = mkIf cfg.enable { koboroot.include = [ (pkgs.linkFarm [{ name = cfg.devicePath; path = cfg._allFiles; }) cfg.package.KoboRoot ]; nickel.menu.item = mkIf cfg.nickel.enable { koreader = singleton { location = "main"; label = "KOReader"; action = "cmd_spawn"; arg = [ "quiet" "exec ${cfg.devicePath}/koreader.sh"; ]; }; }; }; }