Skip to content

feat(chezmoi): apply private secondary sources with a dotfiles wrapper - #118

Merged
0xA3B merged 3 commits into
mainfrom
feat/multi-source-chezmoi
Nov 11, 2026
Merged

0xA3B merged 3 commits into
mainfrom
feat/multi-source-chezmoi

Conversation

@0xA3B

@0xA3B 0xA3B commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Some machines need dotfiles that must stay out of this public repository, and chezmoi applies only
one source directory per invocation. This change lets a machine apply private secondary sources
alongside this repository.

Solution

A secondary source is a separate Git repository checked out at managed-<name>/ inside this
repository, which Git ignores. The new dotfiles wrapper applies this repository first and then
runs a separate chezmoi invocation for each secondary source, with that source's own persistent
state file and the shared config. Nesting lets a secondary source reuse this repository's tooling
and modify helpers. ADR 0001 records
the layout and the rejected alternatives: a shared state file, chezmoi hooks or a git-repo
external, and a sibling checkout.

  • dotfiles init, update, apply, diff, and status act on every source. These verbs accept
    only -n, --dry-run, -v, --verbose, and --force. The wrapper has no general parser for
    chezmoi's flags.
  • dotfiles <name> <args> runs chezmoi against one secondary source. The wrapper appends
    --persistent-state and --source after the arguments, because chezmoi takes the last value of a
    repeated flag. It refuses init, --init, purge, and --.
  • The wrapper refuses a secondary source that ships a chezmoi config template, at its root or under
    .chezmoiroot, because such a template would replace the shared config.
  • Work machines prompt for the work source URL, and an includeIf gives managed-work/ the work
    Git identity.
  • The shared mise tasks and pre-commit hooks also run from inside a secondary source.

The global Git ignore and this repository's .gitignore now match the macOS Icon\r file with
[[:cntrl:]]. The old two-line bracket pattern lost its carriage return to LF normalization, and
StyLua rejected the result when it ran inside a nested repository.

Review notes

  • [task_config] dir = "{{cwd}}" in mise.toml makes every task run in the invocation directory. A
    task run from a subdirectory of this repository now covers only that subtree. CI and hooks run
    from the root.
  • If the last argument to dotfiles <name> is a flag that takes a value, chezmoi reads the appended
    --persistent-state as that value. The wrapper docstring documents this.
  • A secondary source's checkout lives under this repository's root. The README's work-machine steps
    deny a tool access to managed-work/ before the first clone. No commit hook checks this
    repository for secondary-source content.

Validation

tests/test_dotfiles_chezmoi.py runs the wrapper against a real chezmoi binary. CI installs no
chezmoi, so it skips there. Locally, with chezmoi v2.74.0, it passes and fails when the appended
--source is removed.

…y source

A secondary source checked out at managed-<name>/ has no tooling of its own.
mise tasks now run in the invocation directory and pass this repository's
pre-commit config explicitly, hook file filters also match paths relative to
a secondary source's root, and yamllint skips the nested checkouts.
The ignore rules split Icon[ and ] across two lines so the bracket held a
literal carriage return. LF normalization drops that CR, leaving an invalid
pattern that StyLua rejects. [[:cntrl:]] matches the CR without depending on
it.
A secondary source is a separate Git repository checked out at
managed-<name>/ and applied by its own chezmoi invocation with its own state
file. dotfiles runs init, update, apply, diff, and status against this
repository and then each secondary source, and refuses a secondary source
that ships a config template. Work machines prompt for the work source URL,
and Git uses the work identity inside managed-work/.

ADR 0001 records the layout and the alternatives it rejected.
@0xA3B
0xA3B force-pushed the feat/multi-source-chezmoi branch from 2346ee4 to 865cc52 Compare November 11, 2026 00:39
@0xA3B
0xA3B merged commit 97b14fb into main Nov 11, 2026
2 checks passed
@0xA3B
0xA3B deleted the feat/multi-source-chezmoi branch November 11, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant