nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
7.09k stars 1.83k forks source link

bug: i3status-rs weather block unusable due to unquoted curly braces in TOML configuration syntax #2834

Closed Slime90 closed 2 years ago

Slime90 commented 2 years ago

Is there an existing issue for this?

Issue description

I am unable to configure the Weather block using the i3status-rust.nix module, as the service line has formatting that results in nix failing to properly evaluate and generate the TOML. Formatting for this (required) line taken directly from the blocks.md documentation file in the i3status-rs repo.

        blocks = [
          {
            block = "focused_window";
            max_width = 50;
            show_marks ="visible";
          }
          {
            block = "weather";
            format = "{weather} ({location}) {temp}, {wind} m/s {direction}";
            service = { name = "openweathermap", api_key = "XXX", city_id = "5398563", units = "metric" };
          }
❯ switch
error: syntax error, unexpected ',', expecting ';', at /home/<username>/.config/nixpkgs/configs/i3status-rs.nix:18:48

Maintainer CC

@ncfavier @sephii @rycee @happysalada @workflow @ivan

System information

❯ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.101, NixOS, 21.11 (Porcupine)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.16`
 - channels(<username>): `"home-manager-21.11"`
 - channels(root): `"nixos-21.11.336103.40ef692a55b"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
ncfavier commented 2 years ago

Well you can't use TOML syntax in a Nix file.

Once you convert the line to valid Nix, you get a config file that looks like this:

[[block]]
block = "focused_window"
max_width = 50
show_marks = "visible"

[[block]]
block = "weather"
format = "{weather} ({location}) {temp}, {wind} m/s {direction}"

[block.service]
api_key = "XXX"
city_id = "5398563"
name = "openweathermap"
units = "metric"

Which I suppose should be equivalent to the TOML shown here.

Slime90 commented 2 years ago

What would the valid Nix expression be then for the weather block.service? Its not immediately clear to me, perhaps it would be of value to include it in the block example literalExpression?

ncfavier commented 2 years ago

There's no magic here: service should be a TOML table (set of key/value pairs), and the Nix equivalent of that is an attribute set, which you clearly know how to write since there are already two of them in the snippet you posted. The error message even tells you how to fix it.

workflow commented 2 years ago

What would the valid Nix expression be then for the weather block.service? Its not immediately clear to me, perhaps it would be of value to include it in the block example literalExpression?

Agree with @ncfavier, the weather block.service syntax you want should be equivalent to mappings in the literalExpression here:

                 {
                   block = "sound";
                   format = "{output_name} {volume}%";
                   on_click = "pavucontrol --tab=3";
                   mappings = {
                    "alsa_output.pci-0000_00_1f.3.analog-stereo" = "";
                    "bluez_sink.70_26_05_DA_27_A4.a2dp_sink" = "";
                   };
                 }
Slime90 commented 2 years ago

Thanks all, I got this working yesterday with similar syntax, I will have to do some more learning on how these mappings work. Closing.