twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.36k stars 493 forks source link

include, includeTemplate with git submodules #3186

Closed vaygr closed 1 year ago

vaygr commented 1 year ago

What exactly are you trying to do?

I'm using chezmoi with 2 git repositories, where one is a git submodule of the other. The main benefit is that I can have a small subset of dotfiles synced and available on a specific subset of nodes (e.g. servers) while parent repository that's used primarily on workstations can have symlinks to the files/templates in that "server" sub-repository. That works perfectly.

However when using a more lightweight approach for handling machine-to-machine differences (as described in Without using symlinks), I found out that both include and includeTemplate don't take sub-repo relativity into account.

For example, if I have:

$ cat dot_test.tmpl
{{ includeTemplate "test_template" }}

in ~/.local/share/chezmoi/dot_sdots and this is executed on a node that uses parent git repository, it would look for a template in ~/.local/share/chezmoi/.chezmoitemplates first, then fallback to ~/.local/share/chezmoi/. Same for include.

Shouldn't chezmoi look for include files/templates relative to the original repository path (which in the example above would be ~/.local/share/chezmoi/dot_sdots)?

What have you tried so far?

N/A

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

$ chezmoi --verbose $COMMAND

Output of chezmoi doctor

```console $ chezmoi doctor ```

Additional context

Add any other context about the problem here.

twpayne commented 1 year ago

chezmoi doesn't know about git submodules when reading the source state. To chezmoi, the source state is just a normal directory.

Extending chezmoi to understand git submodule structures is something that I don't want to do for multiple reasons:

  1. I want to keep the structure of chezmoi's source directory as simple as possible and keep the structure independent of the underlying VCS used.
  2. git is complex, and I don't want to try to emulate git's functionality in chezmoi if I can avoid it.
  3. In my experience, git submodules are a fractal nightmare of broken abstractions. I would recommend using absolutely anything else except git submodules if you can.

The whole point of chezmoi is that you can keep all your dotfiles for multiple machines in a single repo. chezmoi provides a huge range of features for controlling exactly which dotfiles are present on each machine, how their contents adapt to the local machine, and ensuring that secrets don't leak. Fundamentally, if you're using chezmoi with multiple dotfile repos, then you're not holding chezmoi correctly.

So, I would instead recommend using something like this instead.