Managing languages and libraries with Chezmoi #2150
marcus-crane
started this conversation in
Show and tell
Replies: 1 comment
-
Thank you @marcus-crane, this is really cool, and the combination of chezmoi and asdf is particularly neat :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there,
There aren't many show and tells so I thought I'd finally get around to posting something.
I thought it might be interesting to share my use case with Chezmoi which is that I manage my dotfiles but it's also expanded into managing both my work and home language versions via
.chezmoidata.yaml
and some customrun_once
scripts 🙂I define all of my languages here where the names are 1:1 with asdf plugins. The actual script, which we'll get to in a second, handles the mess of making sure a plugin is installed and using the version declared.
The structure is custom but basically a language version can be provided as a single value, in which case it's installed regardless of machine, or as a map in which case it'll use the work version if "work mode" is enabled.
As a quick sidebar, "work mode" is just a made up check that checks if I'm running on a particular Macbook Pro. It's on my to do list to tidy up since that check isn't cross-platform but these days, I only use my dotfiles on macOS machines.
It also has libraries too so once a language is installed, various handy global packages are installed, with a concept of
global
,home
andwork
packages.Some packages can be quite slow, such as
ansible
which I only use at work, and even then I rarely use it day to day.The actual installer script is pretty naive in that it just loops through the language blocks and tried to install them, ignoring any failures but it works surprisingly well.
Annoyingly,
asdf
throws an error if you runplugin-add
on a language already installed which is why I just use/bin/true
to return a successful exit code if it errors (indicating we're already in a good state). Dumb but it works.Another nice thing is that we use 1Password at work, which I also use at home. I used to do a hack where I'd stick my master password in a plain text file at
$HOME/.op
but now with 1Password CLI v2, any secrets seen by chezmoi automatically cause a prompt to appear which is niceOne thing I'm quite proud of is that with 1Password integration, I can basically open source my work configuration without having to worry about secrets being leaked since I can reference them at build time 🙂 There needs to be some consideration around viable naming of course but I don't have to fiddle with multiple configurations in most cases such as ssh
I haven't had any cause to do it yet but in an emergency, I could theoretically flip
workMode
to true on my personal machine and suddenly have most of my work aliases and tokens appear in my environment which could be handy in a bind. I'm sure it's not quite that easy though 😉Anyway, it took a bit to get up to speed with at first but Chezmoi has been a really nice middle ground. I used to use GNU Stow in the past which didn't allow as much flexibility or secret injection. I've also considered nix with home-manager but it's quite a beast. I found the above to be a nice compromise where I can get "good enough" reproducability of my environment without all the mental overhead of something like nix or guix
Ah, something further I want to do is turn some of this into literate config as well. I have my own basic home grown tool that I wouldn't recommend but it makes it easy to "tangle" my shell config before chezmoi does its thing and then I can just use a basic Github actions pipeline to render my dotfiles as a readable website using Netlify
Beta Was this translation helpful? Give feedback.
All reactions