Skip to content

Commit 23b8770

Browse files
feat(wrapperModules.tofi): init (#387)
add tofi wrapper module
1 parent 24e250b commit 23b8770

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

maintainers/default.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,10 @@
5050
github = "boundless-recursion";
5151
githubId = 59110523;
5252
};
53+
nikitawootten = {
54+
email = "me@nikita.computer";
55+
github = "nikitawootten";
56+
githubId = 8916363;
57+
name = "Nikita Wootten";
58+
};
5359
}

wrapperModules/t/tofi/module.nix

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
wlib,
3+
lib,
4+
pkgs,
5+
config,
6+
...
7+
}:
8+
{
9+
imports = [ wlib.modules.default ];
10+
options = {
11+
settings = lib.mkOption {
12+
type =
13+
with lib.types;
14+
attrsOf (oneOf [
15+
bool
16+
int
17+
float
18+
wlib.types.stringable
19+
]);
20+
default = { };
21+
description = ''
22+
Settings for {command}`tofi`.
23+
See {manpage}`tofi(5)` for available options.
24+
'';
25+
example = {
26+
width = "100%";
27+
height = "100%";
28+
num-results = 5;
29+
border-width = 0;
30+
outline-width = 0;
31+
padding-left = "35%";
32+
padding-top = "35%";
33+
result-spacing = 25;
34+
background-color = "#000A";
35+
};
36+
};
37+
};
38+
config = {
39+
package = lib.mkDefault pkgs.tofi;
40+
41+
constructFiles.generatedConfig = {
42+
relPath = "${config.binName}-config";
43+
content =
44+
let
45+
valueToString =
46+
v:
47+
if builtins.isBool v then
48+
lib.boolToString v
49+
else if builtins.isPath v then
50+
"${v}"
51+
else
52+
toString v;
53+
keyValueToLine = k: v: "${k} = ${valueToString v}\n";
54+
settingsWithoutInclude = builtins.removeAttrs config.settings [ "include" ];
55+
lines = lib.mapAttrsToList keyValueToLine settingsWithoutInclude;
56+
# If set the "include" option should be last so that included options are not overwritten
57+
includeLine = lib.optional (config.settings ? include) (
58+
keyValueToLine "include" config.settings.include
59+
);
60+
in
61+
lib.concatStrings (lines ++ includeLine);
62+
};
63+
64+
flags = {
65+
"--config" = config.constructFiles.generatedConfig.path;
66+
};
67+
68+
meta.maintainers = [ wlib.maintainers.nikitawootten ];
69+
};
70+
}

0 commit comments

Comments
 (0)