aboutsummaryrefslogtreecommitdiff
path: root/modules/plato.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/plato.nix')
-rw-r--r--modules/plato.nix366
1 files changed, 154 insertions, 212 deletions
diff --git a/modules/plato.nix b/modules/plato.nix
index afa7486..f274f00 100644
--- a/modules/plato.nix
+++ b/modules/plato.nix
@@ -1,36 +1,35 @@
-{ config, pkgs, lib, ... }:
+{ config, pkgs, lib, options, ... }:
with builtins // lib;
let
cfg = config.plato;
toml = pkgs.formats.toml {};
-
- bashList = concatMapStringsSep " " (x: ''"${toString x}"'');
-
in {
- options.plato = {
- enable = mkEnableOption "plato";
-
- # package = mkOption {
- # type = types.package;
- # readOnly = true;
- # default = pkgs.runCommand "generate-plato" cfg.generate;
- # };
-
- # src = mkPackageOption pkgs [ "kobo" "plato" ] {};
+ imports = [
+ ./nickel.nix
+ ];
- generate = mkOption {
- type = types.lines;
- default = "";
- description = "Script used to generate the Plato config";
- };
+ options.plato = {
+ enable = mkEnableOpiton "Plato";
path = mkOption {
- type = types.str;
+ type = types.srt;
default = ".adds/plato";
description = "Relative path to Plato within src";
};
- hyphenation = mkEnableOption "hyphenation" // { default = true; };
+ 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;
@@ -38,220 +37,163 @@ in {
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";
};
- dictionaries = {
- packages = mkOption {
- type = with types; listOf package;
- default = [];
- # default = with pkgs.dictdDBs; [
- # wordnet
- # wiktionary
- # ];
- description = "Dictionaries to install with plato";
- };
-
- sporadic = mkOption {
- type = with types; listOf str;
- default = [];
- description = "Extra paths to dictionary files";
- };
+ css = mkOption {
+ default = {};
+ type = with types; attrsOf lines;
+ description = ''
+ css style sheets.
+ Only use this for epub-user dictionary-user html-user
+ '';
+ };
- remove = mkOption {
- type = with types; listOf str;
- default = [];
- description = "Remote these dictionaries from plato";
- };
+ 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
- generate = mkOption {
- type = types.lines;
- default = "";
- description = "Script used to setup dictionaries";
- };
+ # ${text}
+ # '')
};
- fonts = {
- packages = mkOption {
- type = with types; listOf package;
- default = [];
- description = "Fonts to install for plato";
- };
+ dictionaries = mkOption {
+ type = with types; listOf package;
+ default = [];
+ };
- sporadic = mkOption {
- type = with types; listOf str;
- default = [];
- description = "Extra paths to font files";
- };
+ 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
+ );
- remove = mkOption {
- type = with types; listOf str;
- default = [];
- description = "Remove these fonts from plato";
- };
+ };
- generate = mkOption {
- type = types.lines;
- default = "";
- description = "Script used to setup fonts";
- };
+ fonts = mkOption {
+ type = with types; listOf package;
+ default = [];
};
- css = {
- epub = mkOption {
- type = types.lines;
- default = "";
- description = "epub css";
- };
- html = mkOption {
- type = types.lines;
- default = "";
- description = "html css";
- };
- dictionary = mkOption {
- type = types.lines;
- default = "";
- description = "dictionary css";
- };
+ 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
+ );
- generate = mkOption {
- type = types.lines;
- default = "";
- description = "Script used to setup css files";
- };
};
+ };
- wifi = {
- up = {
- pre = mkOption {
- type = types.lines;
- default = "";
- };
- post = mkOption {
- type = types.lines;
- default = "";
- };
+ 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'";
};
- down = {
- pre = mkOption {
- type = types.lines;
- default = "";
- };
- post = mkOption {
- type = types.lines;
- default = "";
- };
+ };
+
+ file = mapAttrs' (n: v: {
+ name = "plato-${n}";
+ value = v // {
+ target = "${cfg.path}/${v.target}";
};
+ }) cfg.file;
- generate = mkOption {
- type = types.lines;
- default = "";
- description = "Script used to setup wifi scripts";
+ 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 /mnt/onboard/${cfg.path}/plato.sh"
+ ];
};
};
};
-
- config.plato = {
- config = optionalString (!cfg.hyphenation) ''
- [ -d hyphenation-patterns ] && rm -rf hyphenation-patterns
- '';
-
- dictionaries.generate = mkBefore ''
- mkdir -pv $out/${cfg.path}/dictionaries
-
- ${optionalString (cfg.dictionaries.packages != []) ''
- echo "Adding dictionaries from packages..."
- for d in ${bashList cfg.dictionaries.packages}; do
- find $d/share/dictd/ -type f -regex '.*\.\(dict\(\.dz\)?\|index\)' -exec cp -v {} $out/${cfg.path}/dictionaries/ \;
- done
- ''}
-
- ${optionalString (cfg.dictionaries.sporadic != []) ''
- echo "Adding sporadic dictionaries..."
- for p in ${bashList cfg.dictionaries.sporadic}; do
- cp -v "$p" $out/${cfg.path}/dictionaries/
- done
- ''}
-
- ${optionalString (cfg.dictionaries.remove != []) ''
- echo "Removing unwanted dictionaries..."
- for p in ${bashList cfg.dictionaries.remove}; do
- rm -f "$out/${cfg.path}/dictionaries/$p"
- done
- ''}
- '';
-
- fonts.generate = mkBefore ''
- mkdir -pv $out/${cfg.path}/fonts
-
- ${optionalString (cfg.fonts.packages != []) ''
- echo "Adding fonts from packages..."
- for d in ${concatMapStringsSep " " toString cfg.fonts.packages}; do
- find $d/share/fonts/truetype/ -type f -regex '.*\.\(ttf\|otf\)' -exec cp -v {} $out/${cfg.path}/fonts/ \;
- done
- ''}
-
- ${optionalString (cfg.fonts.sporadic != []) ''
- echo "Adding sporadic fonts"
- for p in ${concatMapStringsSep " " (x: ''"${x}"'') cfg.fonts.sporadic}; do
- cp -v "$p" $out/${cfg.path}/fonts/
- done
- ''}
-
- ${optionalString (cfg.fonts.remove != []) ''
- echo "Removing unwanted fonts..."
- for p in ${bashList cfg.fonts.remove}; do
- rm -f "$out/${cfg.path}/fonts/$p"
- done
- ''}
- '';
-
- css.generate = mkBefore ''
- ${optionalString (cfg.css.epub != "") ''
- cp -v ${writeText "epub-user.css" cfg.css.epub} $out/${cfg.path}/css/epub-user.css
- ''}
-
- ${optionalString (cfg.css.html != "") ''
- cp -v ${pkgs.writeText "html-user.css" cfg.css.html} $out/${cfg.path}/css/html-user.css
- ''}
-
- ${optionalString (cfg.css.dictionary != "") ''
- cp -v ${pkgs.writeText "dictionary-user.css" cfg.css.dictionary} $out/${cfg.path}/css/dictionary-user.css
- ''}
- '';
-
- wifi.generate =
- let
- mkWifi = t: p: optionalString (cfg.wifi.${t}.${p} != "") ''
- cp -v ${pkgs.writeScript "wifi-${p}-${t}.sh" "#!/bin/sh\n${cfg.wifi.${t}.${p}}"} $out/${cfg.path}/scripts/wifi-${p}-${t}.sh
- '';
- in mkBefore (
- concatMapStringsSep "\n" ({ t, p }: mkWifi t p) (cartesianProductOfSets { t = [ "up" "down" ]; p = [ "pre" "post" ]; })
- );
-
-
- generate = mkBefore ''
- mkdir -p $out/${cfg.path}
-
- ${cfg.dictionaries.generate}
-
- ${cfg.fonts.generate}
-
- ${cfg.css.generate}
-
- ${cfg.wifi.generate}
-
- ${optionalString (cfg.settings != {}) ''
- cp -v ${toml.generate "Settings.toml" cfg.settings} $out/${cfg.path}/Settings.toml
- ''}
-
- ${optionalString (cfg.config != "") ''
- cp -v ${pkgs.writeScript "config.sh" cfg.config} $out/${cfg.path}/config.sh
- ''}
- '';
- };
}