From 5cb16c34a8c5b803ec723934c1dc828c0e8e3bad Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 10 Sep 2024 11:52:55 -0500 Subject: Trying to get everything to actually work --- modules/plato/default.nix | 126 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 98 insertions(+), 28 deletions(-) (limited to 'modules/plato/default.nix') diff --git a/modules/plato/default.nix b/modules/plato/default.nix index 1886662..ac0c5d7 100644 --- a/modules/plato/default.nix +++ b/modules/plato/default.nix @@ -10,6 +10,26 @@ in { 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; @@ -24,18 +44,52 @@ in { 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.symlinkJoin { + name = "plato-package"; + paths = [ + cfg._createdFiles + # (pkgs.linkFarm "plato-files" [{ + # name = removePrefix "/" cfg.devicePath; + # path = cfg.package.out; + # }]) + (pkgs.runCommandLocal "plato-files" {} '' + mkdir -p "$(dirname "$out${cfg.devicePath}")" + cp -r "${cfg.package.out}" "$out${cfg.devicePath}" + '') + cfg.package.KoboRoot + ]; + }; + }; + _allFiles = mkOption { type = types.package; readOnly = true; internal = true; - default = (pkgs.callPackage ../lib/merge-files.nix {}) ([ - cfg.package - ] ++ attrValues cfg.file); + default = pkgs.symlinkJoin { + name = "plato-files"; + paths = mapAttrsToList (_: v: v._package) cfg.file ++ [ cfg.package ]; + }; }; file = mkOption { default = {}; type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {})); + apply = filterAttrs (_: v: v.enable); }; nickel = { @@ -51,15 +105,23 @@ in { ''; }; - 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 = ""; - }; + 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 = ""; @@ -100,9 +162,9 @@ in { default = let copyFonts = pkg: '' - find ${pkg}/share/fonts/truetype/ -type f -regex '.*\.\(ttf\|otf\)' -exec cp -v {} $out/ \; + find ${pkg}/share/fonts/ -type f -regex '.*\.\(ttf\|otf\)' -exec cp -v {} $out/ \; ''; - in pkgs.runCommandLocal {} '' + in pkgs.runCommandLocal "plato-fonts" {} '' mkdir $out ${concatMapStringsSep "\n" copyFonts cfg.fonts} ''; @@ -116,17 +178,21 @@ in { source = toml.generate "Settings.toml" cfg.settings; }; - "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; + "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; @@ -137,8 +203,15 @@ in { source = cfg._fontsCombined; }; }; - - nickel.menu.item = mkIf (cfg.enable && cfg.nickel.enable) { + } + (mkIf cfg.enable { + koboroot.include = singleton cfg._finalPackage; + # singleton (pkgs.linkFarm [{ + # name = cfg.devicePath; + # path = cfg._allFiles; + # }]); + + nickel.menu.item = mkIf cfg.nickel.enable { plato = singleton { location = "main"; label = "Plato"; @@ -149,10 +222,7 @@ in { ]; }; }; - } - # (mkIf (cfg.enable && cfg.nickelEntry.enable { - # nickel.menu.item = - # }) + }) ]; } -- cgit v1.2.3