4 ms·
I'm still looking for a good way to I'm using this approach, but looking for a way manage dotfiles for multiple machines. Having separate branches feels clunky,
by lwhsiao 8y ago
I'm still looking for a good way to I'm using this approach, but looking for a way manage dotfiles for multiple machines. Having separate branches feels clunky, since there is a lot of overlap and tweak may involve making the same tweak on several branches. Any recommendations for managing this situation?
- yjftsjthsd-h 8y agoWhy do you want different configs on different machines? I think the "easy" solution is "don't do that";) But of course that's useless advice if you actually have some usecase, so a suggestion: Have case/if blocks on $(hostname), or even do something like `test -f ~/dotfiles/bashrc.$(hostname).local && source ~/dotfiles/bashrc.$(hostname).local`
- katet 8y agoI have a low-key solution. I check in files named by the hostname. For example `.bashrc.[hostname]`. Then I have a quick conditional in all my .bashrc files that checks for a hostname-specific file. This way, I commit them all, but only the relevant ones get loaded.
- frutiger 8y agoThis is overkill, but I have a DAG of profiles. Each profile can refer to one or more parent profiles. When I produce a config for a particular profile, a small Python script applies the profiles starting from the root node(s). To avoid trashing my home directory, this actually is done to the side and committed into a bare git repository (this part is similar to the article). Afterwards, I use `git --git-dir=... --work-tree=~ checkout -p` to apply any changes one-by-one, allowing me to preserve any local edits I may have made. All this is available as a sparsely documented Python package: https://github.com/frutiger/stratum https://github.com/frutiger/stratum
- __blockcipher__ 8y agoCheck $uname and other variables with if statements to activate aliases depending on OS, username etc. I also keep a barebones “core” of aliases/functions that i use everywhere (e.g. on linux servers as well as my current macos laptop). And then a file that contains the non-core stuff that only get used on my dev environment (MacBook) but not on servers. — It’d help if you provided examples of what differences you have between machines though. Most should be pretty simple e.g. slightly different dir structure, different package managers etc.
- djblue 8y agoThe reason I want to be able to have different files for different machines was to make slight variations to some of my dotfiles. I used to use branches but it was too much error prone work keeping all my branches up-to-date. I switched to a system where I template my dotfiles, but now I have to expand those templates for them to actually work. I do have leverage when to expand the templates and how to install them. There are a bunch of different ways to do this depending on what you want but what I ended up doing was: 1. Template files using a syntax that was easy find / replace using a regex. You could use an existing one if you like. 2. Generate a bash install script with all the file variants embedded as base64 strings. I can build this script locally, but I also have a travis ci build that pushes up the install.sh script as a gh-pages like branch. 3. I can now curl the install.sh script from any machine I want and bootstrap my dotfiles. The only install time dependencies are bash, curl, git, base64, mkdir, and echo so it's a very portable self-contained script. 4. During install time, I use a case on hostname to determine which files to use and I use git to put them into my $HOME directory using a similar strategy described by the article. github: https://github.com/djblue/dotfiles https://github.com/djblue/dotfiles install.sh: https://git.io/vxQ4g https://git.io/vxQ4g
- Barrin92 8y agoI use https://github.com/thoughtbot/rcm https://github.com/thoughtbot/rcm it's great. It has tags to only pull up specific dotfiles (say for emacs, .config etc), and supports configurations for multiple hosts and multiple source folders.
- gkmcd 8y agoSurprised nobody has mentioned YADM - it can do per-device files and/or per-device templating too (jinja2 syntax). It's just a thin wrapper around git so you can use any git commands too. http://yadm.io http://yadm.io
- thingfox 8y agoThere's nothing really to gain from using git directly. Yadm is awesome. I put up my dotfiles here https://github.com/thingfox/dotfiles https://github.com/thingfox/dotfiles (sample documentation repository with examples), in it I show how I did the templating for ssh hosts amongst other configs. This allows me to remove the most sensitive data and use the https://yadm.io/docs/encryption https://yadm.io/docs/encryption option for that. The https://yadm.io/docs/bootstrap https://yadm.io/docs/bootstrap feature is also awesome as is https://yadm.io/docs/alternates https://yadm.io/docs/alternates
- nine_k 8y agoI ended up putting everything common into the master branch, and keep only the varying parts (not the common parts) in machine-specific branches. These are normally "include files" that end up in ~/.profile.d/, ~/.emacd.d/, etc. I have to check out both the main branch and the machine-specific branch in separate directories, and use symlinks. OK by me, though; I don't set up a new workstation often.
- mindslight 8y agoI template trees using a python script, for both ~ and /. The template language isn't even currently that complex - basic per-host conditionals suffice. The host pushing the config does the templating, serializes it, and shoves it over ssh to the receiver. This way I can do things like leave passwords in config files (eg mpd.conf) and not have them end up on eg a VPS. Another example is having helpful comments in authorized_hosts to say where a key is from without that information ending up on the hosts themselves. The receiving host runs python, so it can do things like refuse to overwrite files that have been changed locally. I still need to add a notion of hooks to run on the receiver when a given file is changed. If the remote dependency on python/ssh becomes a problem, I will simply add an option to dump a tarball locally. I really tried to use ansible et al, but those tools seem to be geared towards managing large groups of essentially identical hosts, rather than generally differing hosts with some commonality.
- mikewhy 8y agoAs others have mentioned, sourcing files based on hostname / uname might help: try-source () { if [ -f "$1" ]; then source "$1" fi } try-source "$HOME/.localrc.$(uname -s)" try-source "$HOME/.localrc.$HOSTNAME" try-source "$HOME/.localrc.$(uname -s).$HOSTNAME"