nix-community / dconf2nix

:feet: Convert dconf files (e.g. GNOME Shell) to Nix, as expected by Home Manager [maintainer=@jtojnar]
Apache License 2.0
228 stars 6 forks source link

Syntax error when using world clocks #33

Closed johanbrandhorst closed 3 years ago

johanbrandhorst commented 3 years ago

Thanks for this great tool! I installed from master using

$ nix-env -i -f https://github.com/gvolpe/dconf2nix/archive/master.tar.gz

And when I ran it, it produce the following incorrect line:

"org/gnome/clocks" = {
  world-clocks = ""[{'location': <(uint32 2, <('San Francisco', 'KOAK', true, [(0.65832848982162007, -2.133408063190589)], [(0.659296885757089, -2.1366218601153339)])>)>}, {'location': <(uint32 2, <('London', 'EGWU', true, [(0.89971722940307675, -0.007272211034407213)], [(0.89884456477707964, -0.0020362232784242244)])>)>}, {'location': <(uint32 2, <('Stockholm', 'ESSB', true, [(1.0358529110586345, 0.31328660073298215)], [(1.0355620170322046, 0.31503192998497648)])>)>}]"";
};

The double quotes cause a parsing error.

I also ran into #31, though that issue was closed, so I'm a little confused what happened there.

gvolpe commented 3 years ago

@johanbrandhorst are you sure the double quotes are necessary? The protocol does not mention this at all.

gvolpe commented 3 years ago

Or are you suggesting dconf2nix produces the double quotes? In such case, could you please provide the input to the program?

johanbrandhorst commented 3 years ago

Yes, dconf2nix produced the double quotes. I can't reproduce right now, but I think the key looked like this:

[org/gnome/shell/extensions/dash-to-panel]
panel-element-positions="'{"0":[{"element":"showAppsButton","visible":false,"position":"stackedTL"},{"element":"activitiesButton","visible":false,"position":"stackedTL"},{"element":"leftBox","visible":true,"position":"stackedTL"},{"element":"taskbar","visible":true,"position":"stackedTL"},{"element":"centerBox","visible":true,"position":"stackedBR"},{"element":"rightBox","visible":true,"position":"stackedBR"},{"element":"systemMenu","visible":true,"position":"stackedBR"},{"element":"dateMenu","visible":true,"position":"stackedBR"},{"element":"desktopButton","visible":false,"position":"stackedBR"}]}'"

Which produces

# Generated via dconf2nix: https://github.com/gvolpe/dconf2nix
{ lib, ... }:

let
  mkTuple = lib.hm.gvariant.mkTuple;
in
{
  dconf.settings = {
    "org/gnome/shell/extensions/dash-to-panel" = {
      panel-element-positions = ""'{"0":[{"element":"showAppsButton","visible":false,"position":"stackedTL"},{"element":"activitiesButton","visible":false,"position":"stackedTL"},{"element":"leftBox","visible":true,"position":"stackedTL"},{"element":"taskbar","visible":true,"position":"stackedTL"},{"element":"centerBox","visible":true,"position":"stackedBR"},{"element":"rightBox","visible":true,"position":"stackedBR"},{"element":"systemMenu","visible":true,"position":"stackedBR"},{"element":"dateMenu","visible":true,"position":"stackedBR"},{"element":"desktopButton","visible":false,"position":"stackedBR"}]}'"";
    };

  };
}
gvolpe commented 3 years ago

I wonder if that's a valid input at all. Was that generated by dconf? I can see how the dconf2nix parser gets confused with the double quotes, as they are not escaped.

johanbrandhorst commented 3 years ago

The original error was produced using dconf dump | dconf2nix, yeah. I went through the process of manually configuring all my settings imperatively before dumping it, and it produced the double quotes, so I think that's the format that dash-to-panel saves the state in when configured manually.

gvolpe commented 3 years ago

Usually, dconf generates such values wraped in single quotes, I'm quite suspicious of that value wrapped in both double and single quotes.

[org/gnome/shell/extensions/dash-to-panel]
panel-element-positions='{"0":[{"element":"showAppsButton","visible":false,"position":"stackedTL"},{"element":"activitiesButton","visible":false,"position":"stackedTL"},{"element":"leftBox","visible":true,"position":"stackedTL"},{"element":"taskbar","visible":true,"position":"stackedTL"},{"element":"centerBox","visible":true,"position":"stackedBR"},{"element":"rightBox","visible":true,"position":"stackedBR"},{"element":"systemMenu","visible":true,"position":"stackedBR"},{"element":"dateMenu","visible":true,"position":"stackedBR"},{"element":"desktopButton","visible":false,"position":"stackedBR"}]}'

Parsing this content, dconf2nix generates the following output, which is valid nix.

# Generated via dconf2nix: https://github.com/gvolpe/dconf2nix
{ lib, ... }:

let
  mkTuple = lib.hm.gvariant.mkTuple;
in
{
  dconf.settings = {
    "org/gnome/shell/extensions/dash-to-panel" = {
      panel-element-positions = "'{"0":[{"element":"showAppsButton","visible":false,"position":"stackedTL"},{"element":"activitiesButton","visible":false,"position":"stackedTL"},{"element":"leftBox","visible":true,"position":"stackedTL"},{"element":"taskbar","visible":true,"position":"stackedTL"},{"element":"centerBox","visible":true,"position":"stackedBR"},{"element":"rightBox","visible":true,"position":"stackedBR"},{"element":"systemMenu","visible":true,"position":"stackedBR"},{"element":"dateMenu","visible":true,"position":"stackedBR"},{"element":"desktopButton","visible":false,"position":"stackedBR"}]}'";
    };

  };
}

Can you check if this works for you? Not sure how HM will process this result back to dconf. If this is the case, then that solves the problem :)

Otherwise, I'd need more proof that a value can be wrapped in double and single quotes at the same time. FWIW this can be solved too in the Nix generator (the parser does not have issues with it) but I want to make sure there is a problem to solve first.

johanbrandhorst commented 3 years ago

I don't know where the double quote came from, but it was there when I debugged it. I fixed it manually already and I don't disagree that dconf2nix does the right thing with that input, but I am certain that I didn't manually insert any double quotes into the initial dconf database values. It's up to you whether you want to handle this strange corner case or not, I just wanted to be a good citizen and raise an issue I had with the software.

gvolpe commented 3 years ago

Thanks for raising the issue. I'll close it for now but if it ever comes back, the (relevant) dconf dump should be shared immediately to be able to reproduce and properly fix.

johanbrandhorst commented 3 years ago

I can still reproduce this with v0.0.7. The following dconf.dump (abbreviated):

[org/gnome/clocks]
world-clocks="[{'location': <(uint32 2, <('San Francisco', 'KOAK', true, [(0.65832848982162007, -2.133408063190589)], [(0.659296885757089, -2.1366218601153339)])>)>}, {'location': <(uint32 2, <('London', 'EGWU', true, [(0.89971722940307675, -0.007272211034407213)], [(0.89884456477707964, -0.0020362232784242244)])>)>}, {'location': <(uint32 2, <('Stockholm', 'ESSB', true, [(1.0358529110586345, 0.31328660073298215)], [(1.0355620170322046, 0.31503192998497648)])>)>}]"

[org/gnome/shell/extensions/dash-to-panel]
panel-element-positions='{"0":[{"element":"showAppsButton","visible":false,"position":"stackedTL"},{"element":"activitiesButton","visible":false,"position":"stackedTL"},{"element":"leftBox","visible":true,"position":"stackedTL"},{"element":"taskbar","visible":true,"position":"stackedTL"},{"element":"centerBox","visible":true,"position":"stackedBR"},{"element":"rightBox","visible":true,"position":"stackedBR"},{"element":"systemMenu","visible":true,"position":"stackedBR"},{"element":"dateMenu","visible":true,"position":"stackedBR"},{"element":"desktopButton","visible":false,"position":"stackedBR"}]}'

Produces the following file:

# Generated via dconf2nix: https://github.com/gvolpe/dconf2nix
{ lib, ... }:

let
  mkTuple = lib.hm.gvariant.mkTuple;
in
{
  dconf.settings = {
    "org/gnome/clocks" = {
      world-clocks = ""[{'location': <(uint32 2, <('San Francisco', 'KOAK', true, [(0.65832848982162007, -2.133408063190589)], [(0.659296885757089, -2.1366218601153339)])>)>}, {'location': <(uint32 2, <('London', 'EGWU', true, [(0.89971722940307675, -0.007272211034407213)], [(0.89884456477707964, -0.0020362232784242244)])>)>}, {'location': <(uint32 2, <('Stockholm', 'ESSB', true, [(1.0358529110586345, 0.31328660073298215)], [(1.0355620170322046, 0.31503192998497648)])>)>}]"";
    };

    "org/gnome/shell/extensions/dash-to-panel" = {
      panel-element-positions = "'{"0":[{"element":"showAppsButton","visible":false,"position":"stackedTL"},{"element":"activitiesButton","visible":false,"position":"stackedTL"},{"element":"leftBox","visible":true,"position":"stackedTL"},{"element":"taskbar","visible":true,"position":"stackedTL"},{"element":"centerBox","visible":true,"position":"stackedBR"},{"element":"rightBox","visible":true,"position":"stackedBR"},{"element":"systemMenu","visible":true,"position":"stackedBR"},{"element":"dateMenu","visible":true,"position":"stackedBR"},{"element":"desktopButton","visible":false,"position":"stackedBR"}]}'";
    };

  };
}

Neither lines of which are valid nix as far as my home-manager switch is concerned (in conflict with your suggestion in https://github.com/gvolpe/dconf2nix/issues/33#issuecomment-839766599).

johanbrandhorst commented 3 years ago

The second part of this issue is still present in v0.0.8, the incorrect translation of the panel-element-positions. The following input:

[org/gnome/shell/extensions/dash-to-panel]
panel-element-positions='{"0":[{"element":"showAppsButton","visible":false,"position":"stackedTL"},{"element":"activitiesButton","visible":false,"position":"stackedTL"},{"element":"leftBox","visible":true,"position":"stackedTL"},{"element":"taskbar","visible":true,"position":"stackedTL"},{"element":"centerBox","visible":true,"position":"stackedBR"},{"element":"rightBox","visible":true,"position":"stackedBR"},{"element":"systemMenu","visible":true,"position":"stackedBR"},{"element":"dateMenu","visible":true,"position":"stackedBR"},{"element":"desktopButton","visible":false,"position":"stackedBR"}]}'

Produces the following output:

# Generated via dconf2nix: https://github.com/gvolpe/dconf2nix
{ lib, ... }:

let
  mkTuple = lib.hm.gvariant.mkTuple;
in
{
  dconf.settings = {
    "org/gnome/shell/extensions/dash-to-panel" = {
      panel-element-positions = "'{"0":[{"element":"showAppsButton","visible":false,"position":"stackedTL"},{"element":"activitiesButton","visible":false,"position":"stackedTL"},{"element":"leftBox","visible":true,"position":"stackedTL"},{"element":"taskbar","visible":true,"position":"stackedTL"},{"element":"centerBox","visible":true,"position":"stackedBR"},{"element":"rightBox","visible":true,"position":"stackedBR"},{"element":"dateMenu","visible":true,"position":"stackedBR"},{"element":"systemMenu","visible":true,"position":"stackedBR"},{"element":"desktopButton","visible":true,"position":"stackedBR"}],"1":[{"element":"showAppsButton","visible":false,"position":"stackedTL"},{"element":"activitiesButton","visible":false,"position":"stackedTL"},{"element":"leftBox","visible":true,"position":"stackedTL"},{"element":"taskbar","visible":true,"position":"stackedTL"},{"element":"centerBox","visible":true,"position":"stackedBR"},{"element":"rightBox","visible":true,"position":"stackedBR"},{"element":"dateMenu","visible":true,"position":"stackedBR"},{"element":"systemMenu","visible":true,"position":"stackedBR"},{"element":"desktopButton","visible":true,"position":"stackedBR"}]}'";
  };
}

The quotes inside of the double quotes should be escaped, I think.

gvolpe commented 3 years ago

That's fixed in master but it depends on whether HM supports JSON entries or not, see https://github.com/gvolpe/dconf2nix/issues/39