aboutsummaryrefslogtreecommitdiff
path: root/modules/nickel/default.nix
blob: c5736f070139e27851594a04ce3336f6d26cf257 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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)
      ];
    };
  };
}