[EN] Dotfiles Revolution: How I Manage My Entire dev Environment with Chezmoi
If you’re a developer, you’ve probably experienced it: setting up a new machine is painful. Your aliases, configurations, keybindings, favorite tools â everything you spent years perfecting lives scattered across .bashrc, .zshrc, .vimrc, and dozens of other config files. And when you get a new work laptop or reinstall your OS? Start from scratch.
I’ve been there. After years of manually copying configs between machines, I decided to finally solve this properly. This is the story of how I built a fully automated, cross-platform dotfiles system using chezmoi that handles everything from my shell aliases to my Neovim config to my terminal emulators â across macOS, Fedora (both regular and Atomic), Raspberry Pi, and Windows.
Why Chezmoi?
Before diving into the solution, let’s talk about why I chose chezmoi over other options:
| Tool | Pros | Cons |
|---|---|---|
| GNU Stow | Simple, lightweight | No templating, no scripts |
| Yadm | Good encryption support | Less active development |
| Dotfiles symlinks | Simple | Manual, error-prone |
| Ansible | Powerful, declarative | Overkill for dotfiles |
| Chezmoi | Templates, scripts, encryption, active dev | Learning curve |
Chezmoi hit the sweet spot: it treats your dotfiles as code, supports Go templates for conditional configuration, runs scripts during apply, encrypts secrets, and integrates seamlessly with Git. Plus, it’s actively developed and has a great community.
The Architecture
My dotfiles setup consists of several key components:
~/.local/share/chezmoi/
âââ .chezmoiscripts/ # Automation scripts
â âââ 01-setup/ # System prerequisites
â âââ 02-install/ # Package installation
â âââ 03-configure/ # Post-install config
â âââ 04-update/ # Update scripts
âââ dot_config/ # XDG config files
âââ dot_zsh/ # Zsh configuration (modular)
âââ dot_bash/ # Bash configuration
âââ scripts/ # Bootstrap scripts
âââ .chezmoi.toml.tmpl # Configuration template
1. Profile-Based Configuration
One of chezmoi’s most powerful features is templating. I use this to apply different configurations based on machine type:
[data]
profile = "mac" # or "linux", "windows", "rpi"
This allows me to have:
- macOS: Homebrew packages, specific aliases, Apple-friendly prompts
- Fedora: DNF packages, Flatpak for GUI apps, different prompt
- Fedora Atomic: Immutable OS considerations, rpm-ostree base layer
- Raspberry Pi: APT packages, lighter configuration
- Windows: Scoop packages, minimal bash config
2. Modular Shell Configuration
Instead of one giant .zshrc, I split my shell config into numbered files:
dot_zsh/
âââ 00-env.zsh # Environment variables
âââ 01-path.zsh # PATH management
âââ 02-completions.zsh
âââ 10-aliases.zsh # Command aliases
âââ 20-functions.zsh # Custom functions
âââ 30-keybindings.zsh
âââ 99-integrations.zsh # FZF, Atuin, etc.
This makes finding and editing specific parts trivial. Need to add an alias? It’s in 10-aliases.zsh.
3. The Bootstrap Script: One-Command Setup
The centerpiece of my setup is a bootstrap script that:
- Detects the platform (macOS, Fedora, Fedora Atomic, RPi, Debian, Windows)
- Installs prerequisites (git, package manager)
- Installs chezmoi
- Applies all dotfiles
- Runs platform-specific setup scripts
# One command to rule them all
curl -sL https://raw.githubusercontent.com/jsoyer/dotfiles/main/scripts/bootstrap.sh | bash
The script handles:
- Fedora Atomic: Special handling for rpm-ostree, base layer packages
- SSH server: Installation and enablement
- Modern CLI tools: eza, bat, ripgrep, etc.
- chezmoi initialization: Handles both fresh installs and updates
4. Automation Scripts
Chezmoi scripts are a game-changer. I have scripts that run:
- Before apply (
01-setup/): Install system prerequisites - During apply (
02-install/): Install packages - After apply (
03-configure/): Configure things that need dotfiles first - On change (
04-update/): Update packages when dotfiles change
Example: On Fedora, the setup script detects whether it’s regular Fedora, Fedora Atomic, or running in a Toolbox container, and adjusts package installation accordingly.
5. Auto-Sync: No More Manual Git Commands
The killer feature: I enabled auto-commit and auto-push in chezmoi:
[git]
autoAdd = true
autoCommit = true
autoPush = true
Now when I change a config:
# Edit directly in my home directory
nvim ~/.config/alacritty/alacritty.toml
# Re-add to chezmoi
chezmoi re-add ~/.config/alacritty/alacritty.toml
# Done! Auto-committed and pushed to GitHub
No manual git add ., git commit, git push. It’s magical.
6. Secrets Management
For sensitive data (GPG keys, API tokens), I use chezmoi’s encryption:
chezmoi add --encrypt ~/.zsh/secrets.zsh
Encrypted with a passphrase, decrypted automatically on new machines.
The Daily Workflow
On my main machine (MacBook Pro):
- Edit config files directly
- Test changes
- Run
chezmoi re-add <file>â auto-commits and pushes
On secondary machines:
- Run
chezmoi updateorchezmoi apply - Everything syncs automatically
Updating packages:
I have a cup alias (chezmoi update + package updates) that handles everything:
- chezmoi update
- Homebrew/DNF/Scoop upgrades
- Docker container updates
Lessons Learned
Start simple: Don’t try to migrate everything at once. Add files incrementally.
Use templates wisely: Conditional logic is powerful but can get complex. Document your templates.
Test on VMs: Before applying changes to your main machine, test on a VM or container.
Bootstrap is key: A good bootstrap script makes onboarding new machines trivial.
Git is your friend: The git working tree inside chezmoi gives you rollback capability.
The Result
Now when I get a new machine:
# 5 minutes later, I'm productive
curl -sL https://raw.githubusercontent.com/jsoyer/dotfiles/main/scripts/bootstrap.sh | bash
My entire development environment â shell, editor, terminal, tools, aliases, functions â is exactly the same across:
- đ» macOS (MacBook Pro, Mac Mini)
- đ§ Fedora (desktop, laptop, Fedora Atomic on Framework)
- đ Raspberry Pi
- đȘ Windows (WSL)
That’s the power of treating your dotfiles as code.
[FR] Dotfiles Revolution : Comment je gĂšre tout mon environnement de dev avec Chezmoi
Le ProblĂšme : Chaque Machine est Unique
Si vous ĂȘtes dĂ©veloppeur, vous l’avez probablement vĂ©cu : configurer une nouvelle machine est douloureux. Vos alias, configurations, raccourcis clavier, outils prĂ©fĂ©rĂ©s â tout ce sur quoi vous avez passĂ© des annĂ©es Ă peaufiner â est dispersĂ© Ă travers .bashrc, .zshrc, .vimrc, et des dizaines d’autres fichiers de config. Et quand vous avez un nouvel ordinateur ou rĂ©installez votre OS ? Tout recommencer Ă zĂ©ro.
J’ai Ă©tĂ© lĂ . AprĂšs des annĂ©es Ă copier manuellement des configs entre machines, j’ai dĂ©cidĂ© de rĂ©soudre ce problĂšme dĂ©finitivement. Voici l’histoire de comment j’ai construit un systĂšme de dotfiles entiĂšrement automatisĂ© et multi-plateforme utilisant chezmoi qui gĂšre tout : de mes alias shell Ă ma config Neovim en passant par mes Ă©mulateurs de terminal â sur macOS, Fedora (classique et Atomic), Raspberry Pi, et Windows.
Pourquoi Chezmoi ?
Avant de parler de la solution, parlons de pourquoi j’ai choisi chezmoi plutĂŽt que d’autres options :
| Outil | Avantages | Inconvénients |
|---|---|---|
| GNU Stow | Simple, léger | Pas de templating, pas de scripts |
| Yadm | Bon support du chiffrement | Développement moins actif |
| Dotfiles symlinks | Simple | Manuel, sujet aux erreurs |
| Ansible | Puissant, déclaratif | Trop lourd pour des dotfiles |
| Chezmoi | Templates, scripts, chiffrement, dĂ©veloppement actif | Courbe d’apprentissage |
Chezmoi a trouvĂ© le juste milieu : il traite vos dotfiles comme du code, supporte les templates Go pour la configuration conditionnelle, exĂ©cute des scripts pendant l’application, chiffre les secrets et s’intĂšgre parfaitement avec Git. De plus, il est activement dĂ©veloppĂ© et a une communautĂ© formidable.
L’Architecture
Mon systÚme de dotfiles se compose de plusieurs composants clés :
~/.local/share/chezmoi/
âââ .chezmoiscripts/ # Scripts d'automatisation
â âââ 01-setup/ # PrĂ©requis systĂšme
â âââ 02-install/ # Installation de paquets
â âââ 03-configure/ # Configuration post-install
â âââ 04-update/ # Scripts de mise Ă jour
âââ dot_config/ # Fichiers de config XDG
âââ dot_zsh/ # Configuration Zsh (modulaire)
âââ dot_bash/ # Configuration Bash
âââ scripts/ # Scripts de bootstrap
âââ .chezmoi.toml.tmpl # ModĂšle de configuration
1. Configuration Basée sur le Profil
Une des fonctionnalitĂ©s les plus puissantes de chezmoi est le templating. Je l’utilise pour appliquer diffĂ©rentes configurations selon le type de machine :
[data]
profile = "mac" # ou "linux", "windows", "rpi"
Cela me permet d’avoir :
- macOS : Paquets Homebrew, alias spécifiques, prompts adaptés à Apple
- Fedora : Paquets DNF, Flatpak pour les apps GUI, prompt différent
- Fedora Atomic : Considérations pour OS immuable, couche de base rpm-ostree
- Raspberry Pi : Paquets APT, configuration légÚre
- Windows : Paquets Scoop, config bash minimale
2. Configuration Shell Modulaire
Au lieu d’un .zshrc gĂ©ant, je divise ma config shell en fichiers numĂ©rotĂ©s :
dot_zsh/
âââ 00-env.zsh # Variables d'environnement
âââ 01-path.zsh # Gestion du PATH
âââ 02-completions.zsh
âââ 10-aliases.zsh # Alias de commandes
âââ 20-functions.zsh # Fonctions personnalisĂ©es
âââ 30-keybindings.zsh
âââ 99-integrations.zsh # FZF, Atuin, etc.
Trouver et Ă©diter des parties spĂ©cifiques devient trivial. Besoin d’ajouter un alias ? C’est dans 10-aliases.zsh.
3. Le Script de Bootstrap : Configuration en Une Commande
Le cĆur de ma configuration est un script de bootstrap qui :
- Détecte la plateforme (macOS, Fedora, Fedora Atomic, RPi, Debian, Windows)
- Installe les prérequis (git, gestionnaire de paquets)
- Installe chezmoi
- Applique tous les dotfiles
- Exécute les scripts de configuration spécifiques à la plateforme
# Une commande pour tout configurer
curl -sL https://raw.githubusercontent.com/jsoyer/dotfiles/main/scripts/bootstrap.sh | bash
Le script gĂšre :
- Fedora Atomic : Traitement spécial pour rpm-ostree, couche de base
- Serveur SSH : Installation et activation
- Outils CLI modernes : eza, bat, ripgrep, etc.
- Initialisation chezmoi : GĂšre les nouvelles installs et les mises Ă jour
4. Scripts d’Automatisation
Les scripts chezmoi sont rĂ©volutionnaires. J’ai des scripts qui s’exĂ©cutent :
- Avant l’application (
01-setup/) : Installer les prĂ©requis systĂšme - Pendant l’application (
02-install/) : Installer les paquets - AprĂšs l’application (
03-configure/) : Configurer les choses qui ont besoin des dotfiles - Au changement (
04-update/) : Mettre Ă jour les paquets quand les dotfiles changent
Exemple : Sur Fedora, le script de setup dĂ©tecte si c’est Fedora classique, Fedora Atomic, ou si ça tourne dans un Toolbox, et ajuste l’installation des paquets en consĂ©quence.
5. Auto-Sync : Plus de Commandes Git Manuelles
La fonctionnalitĂ© dĂ©cisive : j’ai activĂ© auto-commit et auto-push dans chezmoi :
[git]
autoAdd = true
autoCommit = true
autoPush = true
Maintenant quand je change une config :
# Ăditer directement dans mon rĂ©pertoire personnel
nvim ~/.config/alacritty/alacritty.toml
# Re-ajouter Ă chezmoi
chezmoi re-add ~/.config/alacritty/alacritty.toml
# C'est fait ! Auto-commit et push vers GitHub
Plus de git add ., git commit, git push manuels. C’est magique.
6. Gestion des Secrets
Pour les donnĂ©es sensibles (clĂ©s GPG, tokens API), j’utilise le chiffrement de chezmoi :
chezmoi add --encrypt ~/.zsh/secrets.zsh
Chiffré avec une phrase de passe, déchiffré automatiquement sur les nouvelles machines.
Le Quotidien
Sur ma machine principale (MacBook Pro) :
- Ăditer les fichiers de config directement
- Tester les changements
- Lancer
chezmoi re-add <fichier>â auto-commit et push
Sur les machines secondaires :
- Lancer
chezmoi updateouchezmoi apply - Tout se synchronise automatiquement
Mettre Ă jour les paquets :
J’ai un alias cup (chezmoi update + mise Ă jour des paquets) qui gĂšre tout :
- chezmoi update
- Mises Ă jour Homebrew/DNF/Scoop
- Mises Ă jour des containers Docker
Leçons Apprises
Commencer simple : N’essayez pas de tout migrer d’un coup. Ajoutez les fichiers progressivement.
Utiliser le templating intelligemment : La logique conditionnelle est puissante mais peut devenir complexe. Documentez vos templates.
Tester sur VMs : Avant d’appliquer des changements sur votre machine principale, testez sur une VM ou un container.
Le bootstrap est clĂ© : Un bon script de bootstrap rend l’onboarding de nouvelles machines trivial.
Git est votre ami : L’arbre de travail git Ă l’intĂ©rieur de chezmoi vous donne la capacitĂ© de revenir en arriĂšre.
Le Résultat
Maintenant quand j’ai une nouvelle machine :
# 5 minutes plus tard, je suis productif
curl -sL https://raw.githubusercontent.com/jsoyer/dotfiles/main/scripts/bootstrap.sh | bash
Mon environnement de dĂ©veloppement complet â shell, Ă©diteur, terminal, outils, alias, fonctions â est exactement le mĂȘme sur :
- đ» macOS (MacBook Pro, Mac Mini)
- đ§ Fedora (bureau, laptop, Fedora Atomic sur Framework)
- đ Raspberry Pi
- đȘ Windows (WSL)
C’est le pouvoir de traiter ses dotfiles comme du code.
Written with â€ïž using chezmoi-managed Neovim configuration
Ăcrit avec â€ïž en utilisant une configuration Neovim gĂ©rĂ©e par chezmoi