Dotfiles

· by Gürkan · Read in about 4 min · (708 Words)





If you're working on multiple computers/servers, managing your personal config files is a hard task. And as a sysadmin, I need my settings to be as global as possible.

Many people are uploading their dotfiles under GitHub or some other public place. This has downsides, at least for me, since one can easily have private information embedded inside these files. Some people synchronizes these files to cloud services like Dropbox. But again, this is a trust thing:

I herd my cats with these 3 tools: Syncthing, stow and systemd. But be warned, all of these is just to make it hurt less, it's still a dirty task overall.

Syncthing

https://syncthing.net/

It's just a tool which runs as a daemon and syncs the folders you give it to, to the nodes you select. Some points to consider while running it:

  • Selecting which files to ignore and how to do it a big topic and still discussed. Current best way to have a .stglobalignore or similar file, which is synced between nodes. You can include this file under node-specific and non-synced .stignore file via adding a line like #include .stglobalignore. More info

  • Check out mobile client, it's working nice, at least on Android.

Stow

https://www.gnu.org/software/stow/

It's a GNU project for managing symlinks. It has lots of features so you can fine-tune and go crazy with symlinks, but the main functionality is generally enough for what we want to do with it.

Here is a small example: Consider you have a folder named test and you have few files/folders in it like test/myfile). If you run stow -t /tmp/ test, stow will create symlinks for each object you have in test, under /tmp (so you'll have /tmp/myfile as a symlink). It is a clever tool also, because if you have a folder under test which is also present under /tmp, (as long as there is no real file conflict) it will not cry and just place symlinks for missing files/folders accordingly under that folder.

Systemd

Well, it is systemd. Like systemd itself, this part is completely optional if you want to use it or not. I use the --user functionality with my setup. You can have user services defined under a directory like ~/.config/systemd and they are manageable by systemctl --user ... command.

Since you can sync your keys, small scripts/binaries etc. You might want to have the helpers to be ready with your dotfiles. For example the service files for shadowsocks and/or dnscrypt, or even syncthing daemon itself. As long as you sync your ~/.config/systemd folder, you'll keep your daemons/timers wherever you want.

Let's do it

Here is my suggestion and what I do, since it is working pretty good for a long time:

  • Create a folder named dotfiles
  • Create folders in it, for each app you'd like to sync configs: zsh, pass, neovim, systemd, tmux ...)
  • Move your configs under it, like how it should be under the target folder. E.g. if you have .zsh folder, put it as a folder under dotfiles/zsh so you'd have dotfiles/zsh/.zsh.
  • For configuration files living in deep (like your Firefox profiles) duplicate the folder structure as a stub. You wouldn't want to synchronize your whole Firefox cache. So if you only want to sync a single file like ~/.mozilla/firefox/profiles.ini, put it under empty directories you've created under dotfiles: dotfiles/firefox/.mozilla/firefox/profiles.ini
  • Tell stow to do its magic for each folder like stow -t ~ firefox. This will create symlinks under target folder (which is ~ in this example)
  • Sync your dotfiles folder via Syncthing. Don't forget to check and add some files/folders you don't want to sync (like cache, *.swp etc.) to the synced ignore file we mentioned above.

And the best (+ hardest) part: Learn to make your configs a bit flexible. Give some love to them so you can use them everywhere you've synced. Use plugin managers (and configure them to keep everything which you don't touch outside of your synced folders), handle the cases like if you can't find a specific plugin etc. on a new node.

Ping me if you have an idea and/or suggestion regarding this setup, since so far I didn't see a big problem/shortage related with this. And a sysadmin working with own configs, is a happy sysadmin.