{ config, pkgs, lib, options, ... }: with builtins // lib; let cfg = config.nickel; importOption = p: (import p { inherit pkgs lib; } cfg.path).option; 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"; path = mkOption { type = types.str; default = ".adds/nm"; description = "Relative path to nickelMenu within src"; }; devPath = mkOption { type = types.str; default = "/mnt/onboard/${cfg.path}"; readOnly = true; internal = true; }; file = importOption ./lib/file.nix; manifest = importOption ./lib/manifest.nix; 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 = mkIf cfg.enable { nickel = { file = mkMerge [ (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) ]; }; # file = mapAttrs' (n: v: { # name = "nm-${n}"; # value = v // { # target = "${cfg.path}/${v.target}"; # }; # }) cfg.file; }; }