aboutsummaryrefslogtreecommitdiff
path: root/modules/plato.nix
diff options
context:
space:
mode:
authorChris Wells <chris@mathematicaster.org>2024-01-24 14:56:56 -0600
committerChris Wells <chris@mathematicaster.org>2024-01-24 14:56:56 -0600
commitd6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6 (patch)
tree7ead1c89bf2490114129d51560280e29b174aaa6 /modules/plato.nix
downloadkobo-manager-d6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6.tar
kobo-manager-d6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6.tar.gz
kobo-manager-d6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6.tar.bz2
kobo-manager-d6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6.tar.lz
kobo-manager-d6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6.tar.xz
kobo-manager-d6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6.tar.zst
kobo-manager-d6949fe35c1b4c7a9e93d1430e5c1b1d5dd4d9c6.zip
Getting a whole kobo distribution together!
Diffstat (limited to 'modules/plato.nix')
-rw-r--r--modules/plato.nix257
1 files changed, 257 insertions, 0 deletions
diff --git a/modules/plato.nix b/modules/plato.nix
new file mode 100644
index 0000000..afa7486
--- /dev/null
+++ b/modules/plato.nix
@@ -0,0 +1,257 @@
+{ config, pkgs, lib, ... }:
+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" ] {};
+
+ generate = mkOption {
+ type = types.lines;
+ default = "";
+ description = "Script used to generate the Plato config";
+ };
+
+ path = mkOption {
+ type = types.str;
+ default = ".adds/plato";
+ description = "Relative path to Plato within src";
+ };
+
+ hyphenation = mkEnableOption "hyphenation" // { default = true; };
+
+ config = mkOption {
+ type = types.lines;
+ default = "";
+ description = "Plato config.sh";
+ };
+
+ 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";
+ };
+
+ remove = mkOption {
+ type = with types; listOf str;
+ default = [];
+ description = "Remote these dictionaries from plato";
+ };
+
+ generate = mkOption {
+ type = types.lines;
+ default = "";
+ description = "Script used to setup dictionaries";
+ };
+ };
+
+ fonts = {
+ packages = mkOption {
+ type = with types; listOf package;
+ default = [];
+ description = "Fonts to install for plato";
+ };
+
+ sporadic = mkOption {
+ type = with types; listOf str;
+ default = [];
+ description = "Extra paths to font files";
+ };
+
+ 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";
+ };
+ };
+
+ 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";
+ };
+
+ 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 = "";
+ };
+ };
+ down = {
+ pre = mkOption {
+ type = types.lines;
+ default = "";
+ };
+ post = mkOption {
+ type = types.lines;
+ default = "";
+ };
+ };
+
+ generate = mkOption {
+ type = types.lines;
+ default = "";
+ description = "Script used to setup wifi scripts";
+ };
+ };
+
+ };
+
+ 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
+ ''}
+ '';
+ };
+}