builtins.readFile to read a config file for Waybar?

Is it possible to use builtins.readFile to read a config file for Waybar?
If yes, does anyone have an example of a Waybar config file that is read this way?

When I do this:
programs.waybar.settings = (builtins.readFile ./config.default);

I get the error:
...programs.waybar.settings is not of type (list of (JSON value)) or attrubute set of (JSON value).

The content of config.default is based on the the example config, converted to valid JSON:

{
    "mainBar": {
        "layer": "top",
        "position": "top",
        "height": 30,
        "output": [
            "eDP-1",
            "HDMI-A-1"
        ],
        "modules-left": [
            "sway/workspaces",
            "sway/mode",
            "wlr/taskbar"
        ],
        "modules-center": [
            "sway/window"
        ],
        "modules-right": [
            "mpd",
            "custom/mymodule#with-css-id",
            "temperature"
        ],
        "sway/workspaces": {
            "disable-scroll": true,
            "all-outputs": true
        }
    }
}

Doing it like this does not work because builtins.readFile returns a string, and you need to pass programs.waybar.settings an actual attribute set or list of the settings.

You have two options here:

  1. Read the config files as json using programs.waybar.settings = lib.importJSON ./config.default;
  2. Not setting programs.waybar.settings, and setting xdg.configFile."waybar/config".source = ./config.default;
1 Like

@lelgenio

Thank you!