Config management from scratch
There is a GNU utility called stow that lets a user manage symlinks. This lets you for example store all of your config files in a folder in your home directory then link them across your system in all the proper places. That in turn will allow you to easily track these files in git for example.
I didn't know this tool existed and I decided that I should make my own and it turned out a bit different.
My solution to deploying configurable config
Revolves around two shell scripts:
link-setconfig
And a very simple config file format for modularity
script: link-set
Program to perform two set operations on the filesystem using symlinks:
union- Takes a source directory/file and unions (using symlinks) it over the destination directory/file.
- Now the destination contains all of the files/directories from the source (as symlinks)
- If conflicting files exist in the destination it will not touch them (because it is a union)
- Idempotent (only changes if you add more files to the source or use
minus)
minus- Removes all symlinks that would be created by the union
- If a file exists that would be symlinked but it is not a symlink it is excluded
- Only removes the file/dir link if its source is actually symlinked to it
- Idempotent
config file: a 'linkage'
- A simple ad hoc file format for linking all the config files for a given program/purpose
- The purpose of separating the linkages is so that they can be linked/unlinked independently instead of always linking/unlinking the entire system config
- Linkages can include other linkages (don't make an infinite loop...)
A typical linkage looks like the following: editors.conf
config/.vimrc=~
config/vscode/settings.json=~/.config/Code/User/
config/vscode/customstyle.css=~/.config/Code/User/
On the LHS of the equals sign we specify the source directory and on the RHS we specify the system path (~ is substituted for the users's home directory).
A more complex linkage may link many things together: basic.conf
# Include all of the basic system setup
.include shells.conf
.include editors.conf
.include git.conf
...
Linkage files consist of comments, includes and links:
#is a comment.includeincludes another linkage with your linkageconfig/dir=/sys/dirlinks config dir assys/dirconfig/file=/sys/dir/links file intosys/dirconfig/file=/sys/filelinks file assys/file
script: config
The higher-level tool for managing configurations.
- Either links or unlinks a given linkage
- All these operations are safe and won't destroy your files
interesting properties of linkages
- Linking a superset of something you have already linked works fine
- Unlinking a subset of your linkages works file
- Linking more than once does nothing unless new config files are added
- Does not destroy conflicting files the system may have during linking/unlinking
- this property can be though of as 'overlaying' your config on the system
- if the system already has its own config it doesn't destroy it
- Unlinking is painless
- Can easily swap between multiple different config installs
- When you link a directory new files placed in it are now in your config folder
How I setup my system now
Basic setup
This is how you get a config repo and install the scripts in your path:
The rest of the description assumes you have refreshed your path
Full config install
Note: This can be done over any linux system and will not mess up any of its file setup and can be easily installed with
Modular config
Uninstall
To uninstall an individual component just do it by name:
To uninstall everything just do uninstall all. It will not fail even if you only have a partially installed config