keepassxc-cli) to expose data as template functions.
Setup
Install KeePassXC CLI
Configuration
Provide the path to your KeePassXC database:~/.config/chezmoi/chezmoi.toml
Template Functions
keepassxc
Get structured data from an entry:
keepassxc-cli show $database example.com and returns parsed data.
keepassxcAttribute
Get additional attributes from an entry:
Usage Examples
Basic Credentials
Database Credentials
~/.config/db/config.yml.tmpl
SSH Private Keys
Store SSH keys as additional attributes:~/.ssh/id_rsa.tmpl
AWS Credentials
~/.aws/credentials.tmpl
API Tokens
~/.config/tokens.env.tmpl
Multiple Service Credentials
~/.netrc.tmpl
Configuration Options
Non-Password-Protected Databases
If your database is not password protected:~/.config/chezmoi/chezmoi.toml
YubiKey Support
chezmoi includes experimental YubiKey support. Setkeepassxc.mode to open:
~/.config/chezmoi/chezmoi.toml
slot:serial, where:
slot: YubiKey configuration slot (usually 1 or 2)serial: YubiKey serial number
Custom Command
Ifkeepassxc-cli is not in your PATH:
~/.config/chezmoi/chezmoi.toml
Additional Arguments
Pass additional arguments tokeepassxc-cli:
~/.config/chezmoi/chezmoi.toml
Advanced Usage
Using Key Files
If your database uses a key file:~/.config/chezmoi/chezmoi.toml
Accessing Standard Fields
KeePassXC entries have standard fields:Organizing Entries in Groups
Reference entries by their full path:Conditional Template Logic
~/.gitconfig.tmpl
Complete Examples
Multi-Environment Setup
~/.config/app/config.yml.tmpl
SSH Configuration
~/.ssh/config.tmpl
Troubleshooting
Database Locked
You’ll be prompted for the password when chezmoi accesses the database. Enter your master password.Entry Not Found
List all entries to find the correct path:Command Not Found
Ensure KeePassXC CLI is installed:Testing Templates
Test template functions:Verify Entry Structure
Show entry details:Permission Denied
Ensure your database file has proper permissions:Best Practices
- Use groups: Organize entries in folders (Work, Personal, Servers)
- Use attributes: Store additional data as custom attributes
- Secure your database: Use a strong master password
- Backup regularly: Keep encrypted backups of your database
- Test access: Verify entries are accessible before using in templates
- Use key files: Add a key file for additional security
- YubiKey: Consider using a YubiKey for hardware-based security