deadc0de6 / dotdrop

Save your dotfiles once, deploy them everywhere
https://dotdrop.readthedocs.io
GNU General Public License v3.0
1.79k stars 106 forks source link

[help] dump/load Gnome's dconf settings #442

Closed gmvelencoso closed 1 month ago

gmvelencoso commented 1 month ago

What I am trying to achieve

(disclaimer: I achieved my goal, just wondering if it's the correct/best way)

Hey! I've just starting setting up dotdrop. Works great for dotfiles, but I had trouble managing Gnome's dconf.

I want to include dumps from Tilix terminal in my dotfiles repository. I struggled a bit TBH, but it seems to work now.

Now I plan to add other keys (or event the whole dconf DB), but I'd like to ask for advice on if this is the correct way.

What I have tried so far

I've defined an action and a trans_update.

actions:
  dconf_load: dconf load "{0}" < "{{@@ _dotfile_abs_src @@}}"
trans_update:
  dconf_dump: dconf dump "{2}" > "{1}"
dconf_tilix:
    src: config/tilix/tilix.dconf
    dst: /tmp/tilix.dconf # a fake dst so dotdrop considers this to install.
    actions:
      - dconf_load /com/gexperts/Tilix/
    trans_update: dconf_dump /com/gexperts/Tilix/
    link: nolink

On dotdrop install it detects changes in the repository and executes the action, applying to dconf my new config.

On dotdrop update, it dumps whatever is in the dconf registry and if there's a diff with my tmp/tilix.dconf file, it will ask for confirmation:

Overwrite "/home/gerard/.dotfiles/dotfiles/config/tilix/tilix.dconf" with "/tmp/dotdrop-6n7sm47d/7043ac2a-d441-44dc-8a0b-b4965716d3c3"? [y/N] ? y
    -> "/home/gerard/.dotfiles/dotfiles/config/tilix/tilix.dconf" updated

I can always delete the /tmp files to avoid the confirmation.

So, as said, I made it work, but I have the feeling this is not the right way.

Thanks in advance!

deadc0de6 commented 1 month ago

Hello, happy it works ;-) Well I'm not sure I can do better since I think it's a very good way to achieve what you want to do. I'm a bit puzzled by the fake dst and I'm thinking that maybe I should implement something so that it's a bit cleaner (maybe using a placeholder like - or /dev/null).

It's a very interesting way to interact with a config manager and if you're ok, I'd like to add your example to the documentation?

Dotdrop was meant initially to interact with files only and I guess that's the reasons your solution might look a bit weird but since you have on both ways to interact with dconf, it's a good way to solve it.

gmvelencoso commented 1 month ago

I'm thinking that maybe I should implement something so that it's a bit cleaner (maybe using a placeholder like - or /dev/null)

Totally. A placeholder would make this logic much more clear. BTW, I first tried the /dev/null approach, and I finally went with the fake dst, because when you install, the program asks you to overwrite the installation:

Overwrite "/dev/null" [y/N] ?

Since I have 2 dconf configs and I plan to add more, I preferred to know which config I was overwriting at each step. But I guess you can easily detect that and output the config name.

It's a very interesting way to interact with a config manager and if you're ok, I'd like to add your example to the documentation?

I would be honoured 😊 Feel free to make any modification to it, and let me know if I can help you somehow.

Thanks for the feedback and for the tool!

deadc0de6 commented 1 month ago

@gmvelencoso I've added your example here: https://dotdrop.readthedocs.io/en/latest/howto/manage-dconf-settings/