Write key:value using lib.hm.gvariant for home-manager

I want to write a dconf.settings block for the following (taken from dconf dump /).

[org/gnome/shell/extensions/gestureImprovements]
forward-back-application-keyboard-shortcuts={'firefox.desktop': (5, true)}

The problem is at the :. I think this is called a dictionary but I am not sure.

I tried the following:

dconf.settings = {
  "org/gnome/shell/extensions/gestureImprovements" = {
    forward-back-application-keyboard-shortcuts = lib.hm.gvariant.mkDictionaryEntry["firefox.desktop" (lib.hm.gvariant.mkTuple[5 true])];
  };
};

But that results in

forward-back-application-keyboard-shortcuts={'firefox.desktop', (5, true)}

i.e. the : is replaced with ‘,’.

I have tried dconf2nix and it just makes it a string.

Any help is appreciated.

I looked around a bit, it seems you can do this:

dconf.settings = {
  "org/gnome/shell/extensions/gestureImprovements" = {
    forward-back-application-keyboard-shortcuts = builtins.toJSON {
      "firefox.desktop": (lib.hm.gvariant.mkTuple [5 true])
    };
  };
};

No. Also the syntax seems wrong.

I tried this

forward-back-application-keyboard-shortcuts = builtins.toJSON {
  "firefox.desktop" = (lib.hm.gvariant.mkTuple[5 true]);
};

And it resulted in this

[org/gnome/shell/extensions/gestureImprovements]
forward-back-application-keyboard-shortcuts='{"firefox.desktop":"@(ib) (5,true)"}'

builtins.toJson will just create a JSON string so that will not work if the GSettings key expects a dictionary.

In GVariant, a dictionary is just an array of dictionary entries. So you can just wrap your entry in a list. Do not forget the parentheses.

Sorry I could not understand. Could you provide me an example?

Finally figured it out. The clue was here on this page, on the last part (or more specifically the last line) of the section.

So after some tries, I did this:

"org/gnome/shell/extensions/gestureImprovements" = {
  forward-back-application-keyboard-shortcuts=[
    (lib.hm.gvariant.mkDictionaryEntry["firefox.desktop" (lib.hm.gvariant.mkTuple[5 true])])
    (lib.hm.gvariant.mkDictionaryEntry["org.gnome.TextEditor.desktop" (lib.hm.gvariant.mkTuple[5 true])])
    (lib.hm.gvariant.mkDictionaryEntry["org.gnome.Nautilus.desktop" (lib.hm.gvariant.mkTuple[1 true])])
    (lib.hm.gvariant.mkDictionaryEntry["org.gnome.Console.desktop" (lib.hm.gvariant.mkTuple[5 true])])
  ];
};

And sure enough, it worked.

[org/gnome/shell/extensions/gestureImprovements]
forward-back-application-keyboard-shortcuts={'firefox.desktop': (5, true), 'org.gnome.TextEditor.desktop': (5, true), 'org.gnome.Nautilus.desktop': (1, true), 'org.gnome.Console.desktop': (5, true)}

PS: shorter version:

"org/gnome/shell/extensions/gestureImprovements" = {
  forward-back-application-keyboard-shortcuts = with lib.hm.gvariant; [ 
    (mkDictionaryEntry["firefox.desktop" (mkTuple[5 true])])
    (mkDictionaryEntry["org.gnome.TextEditor.desktop" (mkTuple[5 true])])
    (mkDictionaryEntry["org.gnome.Nautilus.desktop" (mkTuple[1 true])])
    (mkDictionaryEntry["org.gnome.Console.desktop" (mkTuple[5 true])])
  ];
};

PS2: Another example of multiple dictionaries in an array.

actual dconf:

[org/gnome/epiphany]
search-engine-providers=[{'url': <'https://www.bing.com/search?q=%s'>, 'bang': <'!b'>, 'name': <'Bing'>}, {'url': <'https://duckduckgo.com/?q=%s&t=epiphany'>, 'bang': <'!ddg'>, 'name': <'DuckDuckGo'>}, {'url': <'https://www.google.com/search?q=%s'>, 'bang': <'!g'>, 'name': <'Google'>}, {'url': <'https://www.startpage.com/search?q=%s'>, 'bang': <'!s'>, 'name': <'Startpage'>}]

Nix equivalent:

"org/gnome/epiphany" = {
  search-engine-providers = with lib.hm.gvariant; [
    [ 
      (mkDictionaryEntry["url" (mkVariant "https://www.bing.com/search?q=%s")])
      (mkDictionaryEntry["bang" (mkVariant "!b")])
      (mkDictionaryEntry["name" (mkVariant "Bing")])
    ]
    [ 
      (mkDictionaryEntry["url" (mkVariant "https://duckduckgo.com/?q=%s&t=epiphany")])
      (mkDictionaryEntry["bang" (mkVariant "!ddg")])
      (mkDictionaryEntry["name" (mkVariant "DuckDuckGo")])
    ]
    [ 
      (mkDictionaryEntry["url" (mkVariant "https://www.google.com/search?q=%s")])
      (mkDictionaryEntry["bang" (mkVariant "!g")])
      (mkDictionaryEntry["name" (mkVariant "Google")])
    ]
    [ 
      (mkDictionaryEntry["url" (mkVariant "https://www.startpage.com/search?q=%s")])
      (mkDictionaryEntry["bang" (mkVariant "!s")])
      (mkDictionaryEntry["name" (mkVariant "StartPage")])
    ]
  ];
};