#5077·chezmoi

Support for dynamic contents of exact_ directories

Author: 103sbavertCreated May 25, 2026Updated Jun 10, 2026
Labelssupport

Is your feature request related to a problem? Please describe.

Originally discussed in #5074, the problem is as follows:

Chezmoi currently does not have chezmoi-native (read declarative) way to define the contents of an exact_ directory such that different files are copied under different conditions or different managed machines. The contents of the exact_ directory are always the exact same on all managed machines under all conditions.

Putting the files I intend to omit (and enforce the omission thereof) in templated .chezmoiignore and .chezmoiremove will not work because, as intended, ignore files simply ignore the files whether they are present or not, and remove files cannot define files already present in source (as that is contradictory)

Describe the solution you'd like

I cannot think of anything perfect but a good solution would be to define the contents of an exact_ (or another, new attribute) directory in a file inside the directory which can be templated, maybe .chezmoicontentd or .chezmoimanifest which, when resolved into a new line or space separated list of file paths relative to the containing directory, would enforce the omission of said files in the target directory.

The behavior would be the exact ;) same as a directory with the exact_ attribute, only that the resolved state of the target directory is dynamically determined.

Describe alternatives you've considered

Creating a run_onchange_after script which uses the resolved .chezmoiignore.tmpl file (using includeTemplate) to delete those files explictily. I don't like this because it's fragile (.chezmoiignore does not enforce paths to be relative or absolute - simply the file name is perfectly acceptable) and because it's not declarative like the rest of chezmoi.

Additional context

https://github.com/twpayne/chezmoi/discussions/5074