|
16 | 16 |
|
17 | 17 | isLinkable = wlib.types.linkable.check; |
18 | 18 | 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 | + }; |
19 | 48 | in |
20 | 49 | { |
21 | 50 | imports = [ wlib.modules.default ]; |
|
31 | 60 | ''; |
32 | 61 | }; |
33 | 62 | components = mkOption { |
34 | | - type = types.attrsOf (types.either wlib.types.linkable types.lines); |
| 63 | + type = types.attrsOf (wlib.types.spec componentModule); |
35 | 64 | default = { }; |
36 | 65 | description = "Quickshell components to include in the configuration"; |
37 | 66 | }; |
|
56 | 85 | }/${config.binName}-config"; |
57 | 86 |
|
58 | 87 | 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 |
77 | 99 | // { |
78 | 100 | generatedConfig = { |
79 | 101 | content = mkIf (!isLinkable config.configFile) config.configFile; |
|
0 commit comments