blob: 2fb101665d78cd0e9ac891d13dbc25d0bee404bf (
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
{ config, pkgs, lib, options, ... }:
with builtins // lib;
let
cfg = config.plato;
toml = pkgs.formats.toml {};
importOption = p: (import p { inherit pkgs lib; } cfg.path).option;
in {
imports = [
./nickel.nix
];
options.plato = {
enable = mkEnableOption "Plato";
path = mkOption {
type = types.srt;
default = ".adds/plato";
description = "Relative path to Plato within src";
};
file = importOption ./lib/file.nix;
manifest = importOption ./lib/manifest.nix;
# file = mkOption {
# type = options.file.type;
# default = {};
# description = "Files relative to ${cfg.path}";
# };
# manifest = mkOption {
# type = options.manifest.type;
# default = {};
# description = "Manifest relative to ${cfg.path}";
# };
nickelEntry = mkEnableOption "Launch Plato directly from nickelMenu";
config = mkOption {
type = types.lines;
default = "";
description = "Plato config.sh";
};
hyphenation = mkEnableOption "hyphenation" // { default = true; };
convertDictionaries = mkEnableOption "convert StarDict" // { default = true; };
setFramebufferDepth = mkEnableOption "set framebuffer's depth" // { default = true; };
settings = mkOption {
type = toml.type;
default = {};
description = "Plato Settings.toml";
};
css = mkOption {
default = {};
type = with types; attrsOf lines;
description = ''
css style sheets.
Only use this for epub-user dictionary-user html-user
'';
};
scripts = mkOption {
default = {};
type = with types; attrsOf lines;
description = ''
Only use this for wifi-post-up wifi-post-down wifi-pre-up wifi-pre-down.
'';
# apply = mapAttrs (_: text: ''
# #!/bin/sh
# ${text}
# '')
};
dictionaries = mkOption {
type = with types; listOf package;
default = [];
};
allDictionaries = mkOption {
type = types.package;
readOnly = true;
internal = true;
default = pkgs.runCommand "PlatoDictionaries" {} (''
mkdir -p $out
'' + concatMapStringsSep "\n" (pkg: ''
find ${pkg}/share/dictd/ -type f -regex '.*\.\(dict\(\.dz\)?\|index\)' -exec cp -v {} $out/ \;
'') cfg.dictionaries
);
};
fonts = mkOption {
type = with types; listOf package;
default = [];
};
allFonts = mkOption {
type = types.package;
readOnly = true;
internal = true;
default = pkgs.runCommand "PlatoFonts" {} (''
mkdir -p $out
'' + concatMapStringsSep "\n" (pkg: ''
find ${pkg}/share/fonts/truetype/ -type f -regex '.*\.\(ttf\|otf\)' -exec cp -v {} $out/ \;
'') cfg.fonts
);
};
};
config = mkIf cfg.enable {
plato = {
config = concatStringsSep "\n\n" (
optional (!cfg.convertDictionaries) ''
unset PLATO_CONVERT_DICTIONARIES
''
++
optional (!cfg.setFramebufferDepth) ''
unset PLATO_SET_FRAMEBUFFER_DEPTH
''
++
optional (!cfg.hyphenation) ''
[ -d hyphenation-patterns ] && rm -rf hyphenation-patterns
''
);
file = mkMerge [
(mkIf (cfg.settings != {}) {
"Settings.toml".source = toml.generate "Settings.toml" cfg.settings;
})
(mkIf (cfg.config != "") {
"config.sh".text = cfg.config;
})
(mapAttrs' (n: text:
let
n1 = if hasPrefix "css/" n then n else "css/${n}";
name = if hasSuffix ".css" n1 then n1 else "{n1}.css";
in {
inherit name;
value = { inherit text; };
}) cfg.css)
(mapAttrs' (n: t:
let
n1 = if hasPrefix "scripts/" n then n else "scripts/${n}";
name = if hasSuffix ".sh" n1 then n1 else "${n1}.sh";
text = if hasPrefix "#!/" t then t else "#!/bin/sh\n\n${t}";
in {
inherit name;
value = { inherit text; };
}) cfg.scripts)
{
dictionaries = {
# directory = true;
source = cfg.allDictionaries;
};
fonts = {
# directory = true;
source = cfg.allFonts;
};
}
];
manifest = {
"config-sample.sh".mergeTool = _: _: "echo 'not copying config-sample.sh'";
"Settings-sample.toml".mergeTool = _: _: "echo 'not copying Settings-sample.toml'";
};
};
# file = mapAttrs' (n: v: {
# name = "plato-${n}";
# value = v // {
# target = "${cfg.path}/${v.target}";
# };
# }) cfg.file;
# manifest = mapAttrs' (n: v: {
# name = "plato-${n}";
# value = v // {
# targets = map (x: "${cfg.path}/${x}") v.targets;
# };
# }) cfg.manifest;
nickel.menu.item = mkIf cfg.nickelEntry {
plato = singleton {
location = "main";
label = "Plato";
action = "cmd_spawn";
arg = [
"quiet"
"exec /mnt/onboard/${cfg.path}/plato.sh"
];
};
};
};
}
|