From d6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 24 Jan 2024 14:56:56 -0600 Subject: Getting a whole kobo distribution together! --- modules/redux/plato.nix | 179 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 modules/redux/plato.nix (limited to 'modules/redux/plato.nix') diff --git a/modules/redux/plato.nix b/modules/redux/plato.nix new file mode 100644 index 0000000..6735133 --- /dev/null +++ b/modules/redux/plato.nix @@ -0,0 +1,179 @@ +{ config, pkgs, lib, options, ... }: +with builtins // lib; +let + cfg = config.plato; + toml = pkgs.formats.toml {}; +in { + imports = [ + ./nickle.nix + ]; + + options.plato = { + enable = mkEnableOpiton "Plato"; + + path = mkOption { + type = types.srt; + default = ".adds/plato"; + description = "Relative path to Plato within src"; + }; + + file = mkOption { + type = options.file.type; + default = {}; + description = "Files relative to ${cfg.path}"; + }; + + nickleEntry = mkEnableOption "Launch Plato directly from NickleMenu"; + + 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; + }; + } + ]; + }; + + file = mapAttrs' (n: v: { + name = "plato-${n}"; + value = v // { + target = "${cfg.path}/${v.target}"; + }; + }) cfg.file; + + nickle.menuItems = mkIf cfg.nickleEntry { + "plato" = [ + "main" + "Plato" + "cmd_spawn" + "quiet" + "exec /mnt/onboard/${cfg.path}/plato.sh" + ]; + } + + }; +} -- cgit v1.2.3