Skip to content

Commit 5bd3d08

Browse files
committed
feat(wrapperModules.quickshell): add option to set component's module
1 parent 8c90cbe commit 5bd3d08

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

wrapperModules/q/quickshell/check.nix

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ test { wrapper = "quickshell"; } {
6969
isShellPresent =
7070
wrapper: isFile "${wrapper}/${wrapper.passthru.configuration.binName}-config/shell.qml";
7171
isBarPresent =
72-
wrapper: isFile "${wrapper}/${wrapper.passthru.configuration.binName}-config/Bar.qml";
72+
wrapper: mod:
73+
isFile "${wrapper}/${wrapper.passthru.configuration.binName}-config/${
74+
if mod != null then "${mod}/" else ""
75+
}Bar.qml";
7376
isCorrectConfig = wrapper: ''
7477
logs=$("${wrapper}/bin/quickshell" 2>&1)
7578
echo "$logs" | grep -q "Launching config: \"${wrapper}/${wrapper.passthru.configuration.binName}-config/shell.qml\""
@@ -85,7 +88,7 @@ test { wrapper = "quickshell"; } {
8588
in
8689
[
8790
(isShellPresent wrapper)
88-
(isBarPresent wrapper)
91+
(isBarPresent wrapper "")
8992
(isCorrectConfig wrapper)
9093
];
9194

@@ -98,7 +101,23 @@ test { wrapper = "quickshell"; } {
98101
in
99102
[
100103
(isShellPresent wrapper)
101-
(isBarPresent wrapper)
104+
(isBarPresent wrapper "")
105+
(isCorrectConfig wrapper)
106+
];
107+
108+
"wrapper should keep correct hierachy with component modules" =
109+
let
110+
wrapper = baseWrapper.wrap {
111+
configFile = "import qs.foo.boo\n" + shellContent;
112+
components.bar = {
113+
data = barContent;
114+
module = "foo.boo";
115+
};
116+
};
117+
in
118+
[
119+
(isShellPresent wrapper)
120+
(isBarPresent wrapper "foo/boo")
102121
(isCorrectConfig wrapper)
103122
];
104123
};

wrapperModules/q/quickshell/module.nix

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ let
1616

1717
isLinkable = wlib.types.linkable.check;
1818
makeForce = lib.mkOverride 0;
19+
20+
componentModule = {
21+
options = {
22+
data = mkOption {
23+
type = types.either wlib.types.linkable types.lines;
24+
description = "The component's inlined text or path";
25+
};
26+
module = mkOption {
27+
type = types.nullOr types.str;
28+
default = null;
29+
description = "The component's module, to be imported by `import qs.<module>`";
30+
};
31+
};
32+
};
1933
in
2034
{
2135
imports = [ wlib.modules.default ];
@@ -31,7 +45,7 @@ in
3145
'';
3246
};
3347
components = mkOption {
34-
type = types.attrsOf (types.either wlib.types.linkable types.lines);
48+
type = types.attrsOf (wlib.types.spec componentModule);
3549
default = { };
3650
description = "Quickshell components to include in the configuration";
3751
};
@@ -62,15 +76,17 @@ in
6276
firstChar = builtins.substring 0 1 name;
6377
rest = builtins.substring 1 (-1) name;
6478
capitalizedName = (lib.toUpper firstChar) + rest;
65-
linkable = isLinkable val;
79+
linkable = isLinkable val.data;
6680
in
6781
{
6882
name = "${name}Component";
6983
value = {
70-
content = mkIf (!linkable) val;
71-
builder = mkIf linkable ''ln -s ${val} "$2"'';
84+
content = mkIf (!linkable) val.data;
85+
builder = mkIf linkable ''ln -s ${val.data} "$2"'';
7286
output = makeForce config.generated.output;
73-
relPath = makeForce "${config.binName}-config/${capitalizedName}.qml";
87+
relPath = makeForce "${config.binName}-config/${
88+
if val.module != null then "${lib.replaceString "." "/" val.module}/" else ""
89+
}${capitalizedName}.qml";
7490
};
7591
}
7692
) config.components

0 commit comments

Comments
 (0)