Skip to content

Commit 8c90cbe

Browse files
authored
feat(wrapperModules.quickshell): init (#544)
1 parent e7ed7a1 commit 8c90cbe

2 files changed

Lines changed: 193 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
pkgs,
3+
self,
4+
tlib,
5+
...
6+
}:
7+
let
8+
inherit (tlib)
9+
isDirectory
10+
isFile
11+
test
12+
;
13+
in
14+
test { wrapper = "quickshell"; } {
15+
"wrapper should output correct version" =
16+
let
17+
wrapper = self.wrappers.quickshell.wrap {
18+
inherit pkgs;
19+
};
20+
in
21+
''
22+
"${wrapper}/bin/quickshell" --version |
23+
grep -q "${wrapper.version}"
24+
'';
25+
26+
"wrapper should create config dir" =
27+
let
28+
wrapper = self.wrappers.quickshell.wrap {
29+
inherit pkgs;
30+
};
31+
in
32+
isDirectory "${wrapper}/${wrapper.passthru.configuration.binName}-config";
33+
34+
"file tests" =
35+
let
36+
baseWrapper = self.wrappers.quickshell.apply {
37+
inherit pkgs;
38+
39+
env.LANG = "C.utf8";
40+
env.LC_ALL = "C.utf8";
41+
env.XDG_RUNTIME_DIR = "/tmp";
42+
};
43+
44+
shellContent = ''
45+
Scope {
46+
Bar {}
47+
}
48+
'';
49+
barContent = ''
50+
import Quickshell // for PanelWindow
51+
import QtQuick // for Text
52+
53+
PanelWindow {
54+
anchors {
55+
top: true
56+
left: true
57+
right: true
58+
}
59+
60+
implicitHeight: 30
61+
62+
Text {
63+
anchors.centerIn: parent
64+
text: "hello world"
65+
}
66+
}
67+
'';
68+
69+
isShellPresent =
70+
wrapper: isFile "${wrapper}/${wrapper.passthru.configuration.binName}-config/shell.qml";
71+
isBarPresent =
72+
wrapper: isFile "${wrapper}/${wrapper.passthru.configuration.binName}-config/Bar.qml";
73+
isCorrectConfig = wrapper: ''
74+
logs=$("${wrapper}/bin/quickshell" 2>&1)
75+
echo "$logs" | grep -q "Launching config: \"${wrapper}/${wrapper.passthru.configuration.binName}-config/shell.qml\""
76+
'';
77+
in
78+
{
79+
"wrapper should load shell.qml and components" =
80+
let
81+
wrapper = baseWrapper.wrap {
82+
configFile = shellContent;
83+
components.bar = barContent;
84+
};
85+
in
86+
[
87+
(isShellPresent wrapper)
88+
(isBarPresent wrapper)
89+
(isCorrectConfig wrapper)
90+
];
91+
92+
"wrapper should load external files" =
93+
let
94+
wrapper = baseWrapper.wrap {
95+
configFile = pkgs.writeText "quickshell-test-shell.qml" shellContent;
96+
components.bar = pkgs.writeText "quickshell-test-bar.qml" barContent;
97+
};
98+
in
99+
[
100+
(isShellPresent wrapper)
101+
(isBarPresent wrapper)
102+
(isCorrectConfig wrapper)
103+
];
104+
};
105+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
config,
3+
lib,
4+
wlib,
5+
pkgs,
6+
...
7+
}:
8+
let
9+
inherit (lib)
10+
mapAttrs'
11+
mkDefault
12+
mkIf
13+
mkOption
14+
types
15+
;
16+
17+
isLinkable = wlib.types.linkable.check;
18+
makeForce = lib.mkOverride 0;
19+
in
20+
{
21+
imports = [ wlib.modules.default ];
22+
options = {
23+
configFile = mkOption {
24+
type = types.either wlib.types.linkable types.lines;
25+
default = "";
26+
description = ''
27+
The quickshell shell.qml configuration file.
28+
29+
Provide either inlined configuration or reference an external file.
30+
It is used by quickshell using `--path`.
31+
'';
32+
};
33+
components = mkOption {
34+
type = types.attrsOf (types.either wlib.types.linkable types.lines);
35+
default = { };
36+
description = "Quickshell components to include in the configuration";
37+
};
38+
generated.output = mkOption {
39+
type = types.str;
40+
default = config.outputName;
41+
description = "The constructed file's output";
42+
};
43+
generated.placeholder = mkOption {
44+
type = types.str;
45+
readOnly = true;
46+
default = "${placeholder config.generated.output}/${config.binName}-config";
47+
description = "A placeholder for the generated config dir";
48+
};
49+
};
50+
51+
config.package = mkDefault pkgs.quickshell;
52+
config.flags."--path" = config.generated.placeholder;
53+
54+
config.passthru.generatedConfigDir = "${
55+
config.wrapper.${config.generated.output}
56+
}/${config.binName}-config";
57+
58+
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
77+
// {
78+
generatedConfig = {
79+
content = mkIf (!isLinkable config.configFile) config.configFile;
80+
builder = mkIf (isLinkable config.configFile) ''ln -s ${config.configFile} "$2"'';
81+
output = makeForce config.generated.output;
82+
relPath = makeForce "${config.binName}-config/shell.qml";
83+
};
84+
};
85+
86+
config.meta.maintainers = [ wlib.maintainers.ormoyo ];
87+
config.meta.platforms = lib.platforms.linux;
88+
}

0 commit comments

Comments
 (0)