|
| 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