diff options
Diffstat (limited to 'modules/nickel.nix')
| -rw-r--r-- | modules/nickel.nix | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/modules/nickel.nix b/modules/nickel.nix new file mode 100644 index 0000000..948dbaf --- /dev/null +++ b/modules/nickel.nix @@ -0,0 +1,143 @@ +{ 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"; + + path = mkOption { + type = types.str; + default = ".adds/nm"; + description = "Relative path to nickelMenu within src"; + }; + + file = mkOption { + type = options.file.type; + default = {}; + description = "Files relative to ${cfg.path}"; + }; + + 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 + }; +} |
