{ config, pkgs, lib, options, ... }: with builtins // lib; let cfg = config.nickel; action = mkOption { type = types.enum [ "cmd_spawn" "cmd_output" "dbg_syslog" "dbg_error" "dbg_msg" "dbg_toast" "kfmon" "nickel_setting" "nickel_extras" "nickel_browser" "nickel_misc" "nickel_open" "nickel_wifi" "nickel_orientation" "power" "skip" ]; }; location = mkOption { type = types.enum [ "main" "reader" "browser" "library" "selection" ]; }; createChainItem = { when, action, arg, ... }: concatStringsSep " : " ([ "chain_${when}" action ] ++ arg); createMenuItem = { location, label, action, arg, chain, ... }: concatStringsSep "\n" ( singleton ( concatStringsSep " : " ([ "menu_item" location label action ] ++ arg) ) ++ (map createChainItem chain) ); createExperimental = k: v: "experimental : ${k} : ${v}"; createGenerator = { location, generator }: concatStringsSep " : " ( [ "generator" ] ++ (if isInt generator then [ "_test" (toString generator) ] else splitString " " generator) ); in { options.nickel = { enable = mkEnableOption "nickelMenu"; package = mkPackageOption pkgs "nickel-menu" {}; _createdFiles = mkOption { type = types.package; readOnly = true; internal = true; default = pkgs.buildEnv { name = "nickel-files-created"; paths = mapAttrsToList (_: v: v._package) cfg.file; extraPrefix = cfg.devicePath; }; }; finalPackage = mkOption { type = types.package; readOnly = true; internal = true; default = pkgs.mergePaths { name = "nickel-menu-package"; paths = [ (pkgs.linkFarm "nickel-menu" [{ name = removePrefix "/" cfg.devicePath; path = cfg.package.out; }]) cfg._createdFiles cfg.package.KoboRoot ]; }; }; path = mkOption { type = types.str; default = ".adds/nm"; readOnly = true; internal = true; }; devicePath = mkOption { type = types.str; default = "/mnt/onboard/${cfg.path}"; readOnly = true; internal = true; }; file = mkOption { default = {}; type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {})); apply = filterAttrs (_: v: v.enable); }; menu = { item = mkOption { default = {}; description = "https://github.com/pgaskin/NickelMenu/blob/v0.5.4/res/doc"; type = with types; attrsOf (listOf (submodule { options = { inherit action location; label = mkOption { type = types.str; }; arg = mkOption { type = with types; nonEmptyListOf str; }; chain = mkOption { default = []; type = with types; listOf (submodule { options = { when = mkOption { type = types.enum [ "success" "failure" "always" ]; }; inherit action; arg = mkOption { type = with types; nonEmptyListOf str; }; }; }); }; }; })); }; experimental = mkOption { default = {}; description = "https://github.com/pgaskin/NickelMenu/blob/v0.5.4/res/doc"; type = with types; attrsOf (attrsOf str); }; generator = mkOption { default = {}; description = "https://github.com/pgaskin/NickelMenu/blob/v0.5.4/res/doc"; type = with types; attrsOf (listOf (submodule { options = { inherit location; generator = mkOption { type = with types; either (enum [ "kfmon" "kfmon all" "kfmon gui" ]) (ints.between 0 10); default = "kfmon"; }; }; })); }; }; }; config = mkMerge [ { info.nickel = cfg.enable; nickel = { file = (mapAttrs (_: v: { text = concatMapStringsSep "\n" createGenerator v; }) cfg.menu.generator) // (mapAttrs (_: v: { text = concatStringsSep "\n" (mapAttrsToList createExperimental v); }) cfg.menu.experimental) // (mapAttrs (_: v: { text = concatMapStringsSep "\n" createMenuItem v; }) cfg.menu.item) ; }; } (mkIf cfg.enable { koboroot.include = singleton cfg.finalPackage; }) ]; }