From 849bdb056feb8e064396970f79c8962b20b0c07f Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 3 Sep 2024 12:13:30 -0500 Subject: Re-doing a bunch of this --- modules/nickel/default.nix | 153 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 modules/nickel/default.nix (limited to 'modules/nickel') diff --git a/modules/nickel/default.nix b/modules/nickel/default.nix new file mode 100644 index 0000000..c5736f0 --- /dev/null +++ b/modules/nickel/default.nix @@ -0,0 +1,153 @@ +{ 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" {}; + + _allFiles = mkOption { + type = types.package; + readOnly = true; + internal = true; + default = (pkgs.callPackage ../lib/merge-files.nix {}) (atrValues cfg.file); + }; + + path = mkOption { + type = types.str; + default = ".adds/nm"; + readOnly = true; + internal = true; + # description = "Relative path to nickelMenu within src"; + }; + + 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 {}); + }; + + 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 = { + 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) + ]; + }; + }; +} -- cgit v1.2.3