{ config, pkgs, lib, options, ... }: with builtins // lib; let cfg = config.plato; toml = pkgs.formats.toml {}; # importOption = p: (import p { inherit pkgs lib; } cfg.path).option; in { options.plato = { enable = mkEnableOption "Plato"; package = mkPackageOption pkgs "plato" {}; # _unpackage = mkOption { # type = types.package; # readOnly = true; # internal = true; # default = pkgs.buildEnv { # name = "plato-unpackage"; # paths = [ # (pkgs.runCommandLocal "plato-files" {} '' # mkdir -p "$out${cfg.devicePath}" # cp -r "${cfg.package.out}/" $out${cfg.devicePath} # '') # # (pkgs.linkFarm "plato-files" [{ # # name = removePrefix "/" cfg.devicePath; # # path = cfg.package.out; # # }]) # cfg.package.KoboRoot # ]; # }; # }; path = mkOption { type = types.str; readOnly = true; internal = true; default = ".adds/plato"; }; devicePath = mkOption { type = types.str; readOnly = true; internal = true; default = "/mnt/onboard/${cfg.path}"; }; _createdFiles = mkOption { type = types.package; internal = true; readOnly = true; default = pkgs.buildEnv { name = "plato-files-created"; paths = mapAttrsToList (_: v: v._package) cfg.file; extraPrefix = cfg.devicePath; }; }; finalPackage = mkOption { type = types.package; internal = true; readOnly = true; default = pkgs.mergePaths { name = "plato-package"; paths = [ (pkgs.linkFarm "plato" [{ name = removePrefix "/" cfg.devicePath; path = cfg.package.out; }]) cfg._createdFiles cfg.package.KoboRoot ]; }; }; file = mkOption { default = {}; type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {})); apply = filterAttrs (_: v: v.enable); }; nickel = { enable = mkEnableOption "Add NickelMenu option" // { default = ! config.kfmon.enable; }; }; settings = mkOption { type = toml.type; default = {}; description = '' Contents of Settings.toml ''; }; config = mkOption { type = types.lines; default = ""; description = '' Contents of config.sh ''; }; # config = { # hyphenation = mkEnableOption "hyphenation" // { default = true; }; # convertDictionaries = mkEnableOption "convert StartDict" // { default = true; }; # setFramebufferDepth = mkEnableOption "set framebuffer's depth" // { default = true; }; # extra = mkOption { # type = types.lines; # default = ""; # }; # }; # mkOption { # type = types.lines; # default = ""; # description = '' # Contents of config.sh # ''; # }; dictionaries = mkOption { type = with types; listOf package; default = []; }; _dictionariesCombined = mkOption { type = types.package; readOnly = true; internal = true; default = let copyDicts = pkg: '' find ${pkg}/ -type f -regex '^.*\.\(dict\(\.dz\)?\|index\)$' -exec cp -v {} $out/ \; ''; in pkgs.runCommandLocal "plato-dictionaries" {} '' mkdir $out ${concatMapStringsSep "\n" copyDicts cfg.dictionaries} ''; }; fonts = mkOption { type = with types; listOf package; default = []; }; _fontsCombined = mkOption { type = types.package; readOnly = true; internal = true; default = let copyFonts = pkg: '' find ${pkg}/ -type f -regex '^.*\.\(ttf\|otf\)$' -exec cp -v {} $out/ \; ''; in pkgs.runCommandLocal "plato-fonts" {} '' mkdir $out ${concatMapStringsSep "\n" copyFonts cfg.fonts} ''; }; }; config = mkMerge [ { info.plato = cfg.enable; plato.file = { "Settings.toml" = mkIf (cfg.settings != {}) { source = toml.generate "Settings.toml" cfg.settings; }; "config.sh" = mkIf (cfg.config != "") { text = cfg.config; }; # "config.sh" = # let # c = optional (!cfg.config.convertDictionaries) "unset PLATO_CONVERT_DICTIONARIES" # ++ optional (!cfg.config.setFramebufferDepth) "unset PLATO_SET_FRAMEBUFFER_DEPTH" # ++ optional (!cfg.config.hyphenation) "[ -d hyphenation-patters ] && rm -rf hyphenation-patterns" # ++ optional (cfg.config.extra != "") cfg.config.extra # ; # in mkIf (c != []) { # text = concatStringsSep "\n\n" c; # }; "_dictionaries" = { target = "dictionaries"; source = cfg._dictionariesCombined; }; "_fonts" = { target = "fonts"; source = cfg._fontsCombined; }; }; } (mkIf cfg.enable { koboroot.include = singleton cfg.finalPackage; nickel.menu.item = mkIf cfg.nickel.enable { plato = singleton { location = "main"; label = "Plato"; action = "cmd_spawn"; arg = [ "quiet" "exec ${cfg.devicePath}/plato.sh" ]; }; }; kfmon.configs.plato.watch = { filename = "/mnt/onboard/icons/plato.png"; action = "${cfg.devicePath}/plato.sh"; label = "Plato"; hidden = 0; block_spawns = 1; do_db_update = 0; db_title = "Plato"; db_author = "Baskerville"; db_comment = "A document reader"; }; }) ]; } # imports = [ # ./nickel.nix # ]; # options.plato = { # enable = mkEnableOption "Plato"; # path = mkOption { # type = types.str; # default = ".adds/plato"; # description = "Relative path to Plato within src"; # }; # devPath = mkOption { # type = types.str; # default = "/mnt/onboard/${cfg.path}"; # readOnly = true; # internal = true; # }; # file = importOption ./lib/file.nix; # manifest = importOption ./lib/manifest.nix; # # 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}"; # # }; # nickelEntry = mkEnableOption "Launch Plato directly from nickelMenu"; # config = mkOption { # type = types.lines; # default = ""; # description = "Plato config.sh"; # }; # hyphenation = mkEnableOption "hyphenation" // { default = true; }; # convertDictionaries = mkEnableOption "convert StarDict" // { default = true; }; # setFramebufferDepth = mkEnableOption "set framebuffer's depth" // { default = true; }; # settings = mkOption { # type = toml.type; # default = {}; # description = "Plato Settings.toml"; # }; # css = mkOption { # default = {}; # type = with types; attrsOf lines; # description = '' # css style sheets. # Only use this for epub-user dictionary-user html-user # ''; # }; # scripts = mkOption { # default = {}; # type = with types; attrsOf lines; # description = '' # Only use this for wifi-post-up wifi-post-down wifi-pre-up wifi-pre-down. # ''; # # apply = mapAttrs (_: text: '' # # #!/bin/sh # # ${text} # # '') # }; # dictionaries = mkOption { # type = with types; listOf package; # default = []; # }; # allDictionaries = mkOption { # type = types.package; # readOnly = true; # internal = true; # default = pkgs.runCommand "PlatoDictionaries" {} ('' # mkdir -p $out # '' + concatMapStringsSep "\n" (pkg: '' # find ${pkg}/share/dictd/ -type f -regex '.*\.\(dict\(\.dz\)?\|index\)' -exec cp -v {} $out/ \; # '') cfg.dictionaries # ); # }; # fonts = mkOption { # type = with types; listOf package; # default = []; # }; # allFonts = mkOption { # type = types.package; # readOnly = true; # internal = true; # default = pkgs.runCommand "PlatoFonts" {} ('' # mkdir -p $out # '' + concatMapStringsSep "\n" (pkg: '' # find ${pkg}/share/fonts/truetype/ -type f -regex '.*\.\(ttf\|otf\)' -exec cp -v {} $out/ \; # '') cfg.fonts # ); # }; # }; # config = mkIf cfg.enable { # plato = { # config = concatStringsSep "\n\n" ( # optional (!cfg.convertDictionaries) '' # unset PLATO_CONVERT_DICTIONARIES # '' # ++ # optional (!cfg.setFramebufferDepth) '' # unset PLATO_SET_FRAMEBUFFER_DEPTH # '' # ++ # optional (!cfg.hyphenation) '' # [ -d hyphenation-patterns ] && rm -rf hyphenation-patterns # '' # ); # file = mkMerge [ # (mkIf (cfg.settings != {}) { # "Settings.toml".source = toml.generate "Settings.toml" cfg.settings; # }) # (mkIf (cfg.config != "") { # "config.sh".text = cfg.config; # }) # (mapAttrs' (n: text: # let # n1 = if hasPrefix "css/" n then n else "css/${n}"; # name = if hasSuffix ".css" n1 then n1 else "{n1}.css"; # in { # inherit name; # value = { inherit text; }; # }) cfg.css) # (mapAttrs' (n: t: # let # n1 = if hasPrefix "scripts/" n then n else "scripts/${n}"; # name = if hasSuffix ".sh" n1 then n1 else "${n1}.sh"; # text = if hasPrefix "#!/" t then t else "#!/bin/sh\n\n${t}"; # in { # inherit name; # value = { inherit text; }; # }) cfg.scripts) # { # dictionaries = { # # directory = true; # source = cfg.allDictionaries; # }; # fonts = { # # directory = true; # source = cfg.allFonts; # }; # } # ]; # manifest = { # "config-sample.sh".mergeTool = _: _: "echo 'not copying config-sample.sh'"; # "Settings-sample.toml".mergeTool = _: _: "echo 'not copying Settings-sample.toml'"; # }; # }; # # file = mapAttrs' (n: v: { # # name = "plato-${n}"; # # value = v // { # # target = "${cfg.path}/${v.target}"; # # }; # # }) cfg.file; # # manifest = mapAttrs' (n: v: { # # name = "plato-${n}"; # # value = v // { # # targets = map (x: "${cfg.path}/${x}") v.targets; # # }; # # }) cfg.manifest; # nickel.menu.item = mkIf cfg.nickelEntry { # plato = singleton { # location = "main"; # label = "Plato"; # action = "cmd_spawn"; # arg = [ # "quiet" # "exec ${cfg.devPath}/plato.sh" # ]; # }; # }; # }; # }