Skip to content

Commit ef59977

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

2 files changed

Lines changed: 65 additions & 23 deletions

File tree

wrapperModules/q/quickshell/check.nix

Lines changed: 24 additions & 4 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,20 +88,37 @@ test { wrapper = "quickshell"; } {
8588
in
8689
[
8790
(isShellPresent wrapper)
88-
(isBarPresent wrapper)
91+
(isBarPresent wrapper null)
8992
(isCorrectConfig wrapper)
9093
];
9194

9295
"wrapper should load external files" =
9396
let
9497
wrapper = baseWrapper.wrap {
9598
configFile = pkgs.writeText "quickshell-test-shell.qml" shellContent;
96-
components.bar = pkgs.writeText "quickshell-test-bar.qml" barContent;
99+
components.bar.data = pkgs.writeText "quickshell-test-bar.qml" barContent;
100+
components.bar.name = "Bar.qml";
97101
};
98102
in
99103
[
100104
(isShellPresent wrapper)
101-
(isBarPresent wrapper)
105+
(isBarPresent wrapper null)
106+
(isCorrectConfig wrapper)
107+
];
108+
109+
"wrapper should keep correct hierachy with component modules" =
110+
let
111+
wrapper = baseWrapper.wrap {
112+
configFile = "import qs.foo.boo\n" + shellContent;
113+
components.bar = {
114+
data = barContent;
115+
module = "foo.boo";
116+
};
117+
};
118+
in
119+
[
120+
(isShellPresent wrapper)
121+
(isBarPresent wrapper "foo/boo")
102122
(isCorrectConfig wrapper)
103123
];
104124
};

wrapperModules/q/quickshell/module.nix

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@ let
1616

1717
isLinkable = wlib.types.linkable.check;
1818
makeForce = lib.mkOverride 0;
19+
20+
componentModule =
21+
{ name, config, ... }:
22+
{
23+
options = {
24+
name = mkOption {
25+
type = types.str;
26+
default =
27+
let
28+
firstChar = builtins.substring 0 1 name;
29+
rest = builtins.substring 1 (-1) name;
30+
in
31+
if (isLinkable config.data) then
32+
(builtins.baseNameOf config.data)
33+
else
34+
(lib.toUpper firstChar) + rest + ".qml";
35+
description = "The name of this component (either filename or directory name)";
36+
};
37+
data = mkOption {
38+
type = types.either wlib.types.linkable types.lines;
39+
description = "The component's inlined text or path";
40+
};
41+
module = mkOption {
42+
type = types.nullOr types.str;
43+
default = null;
44+
description = "The component's module, to be imported by `import qs.<module>`";
45+
};
46+
};
47+
};
1948
in
2049
{
2150
imports = [ wlib.modules.default ];
@@ -31,7 +60,7 @@ in
3160
'';
3261
};
3362
components = mkOption {
34-
type = types.attrsOf (types.either wlib.types.linkable types.lines);
63+
type = types.attrsOf (wlib.types.spec componentModule);
3564
default = { };
3665
description = "Quickshell components to include in the configuration";
3766
};
@@ -56,24 +85,17 @@ in
5685
}/${config.binName}-config";
5786

5887
config.constructFiles =
59-
mapAttrs' (
60-
name: val:
61-
let
62-
firstChar = builtins.substring 0 1 name;
63-
rest = builtins.substring 1 (-1) name;
64-
capitalizedName = (lib.toUpper firstChar) + rest;
65-
linkable = isLinkable val;
66-
in
67-
{
68-
name = "${name}Component";
69-
value = {
70-
content = mkIf (!linkable) val;
71-
builder = mkIf linkable ''ln -s ${val} "$2"'';
72-
output = makeForce config.generated.output;
73-
relPath = makeForce "${config.binName}-config/${capitalizedName}.qml";
74-
};
75-
}
76-
) config.components
88+
mapAttrs' (name: val: {
89+
name = "${name}Component";
90+
value = {
91+
content = mkIf (!isLinkable val.data) val.data;
92+
builder = mkIf (isLinkable val.data) ''ln -s ${val.data} "$2"'';
93+
output = makeForce config.generated.output;
94+
relPath = makeForce "${config.binName}-config/${
95+
if val.module != null then "${lib.replaceString "." "/" val.module}/" else ""
96+
}${val.name}";
97+
};
98+
}) config.components
7799
// {
78100
generatedConfig = {
79101
content = mkIf (!isLinkable config.configFile) config.configFile;

0 commit comments

Comments
 (0)