Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add customizable init command #664

Closed
twpayne opened this issue Apr 11, 2020 · 2 comments
Closed

Add customizable init command #664

twpayne opened this issue Apr 11, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@twpayne
Copy link
Owner

twpayne commented Apr 11, 2020

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

Before I can use chezmoi to create my dotfiles I need to install my password manager so chezmoi can retrieve secrets from it. Right now, I have to do this manually, but I should be able to automate this and have it integrated into chezmoi init.

Describe the solution you'd like

I'd like to be able to have a file like .chezmoiinit or run_init_foo in my source directory that gets run when I run chezmoi init on a new machine. It should be a template so I can handle machine-specific differences.

Describe alternatives you've considered

Adding a run_once_ script that runs early and installs the password manager before chezmoi needs it. This feels a bit clumsy and fragile though. It would be better to have a known script run on chezmoi init.

Additional context

None.

@twpayne twpayne added the enhancement New feature or request label Apr 11, 2020
@samtgarson
Copy link

Adding my 2c that this is a great idea, this could be a really powerful feature, another use case is setting up SSH keys to pull from private repos on Github.

FWIW I've worked around this by prefixing a "bootstrap" directory with an _ so the scripts inside run first, you can see here: https://github.com/samtgarson/dotfiles/tree/master/exact_dot_dotfiles (even though the order in which scripts are run being aphabetical isn't documented so I guess could be dangerous to rely on?)

Worth noting that this would be a pretty significant breaking change as currently I feel safe knowing that init is a command that does not mutate the home directory state at all. Maybe a chezmoi bootstrap command would be more explicit? And could run when doing the first apply on a new machine.

@twpayne
Copy link
Owner Author

twpayne commented Dec 30, 2020

For info, this is now done in the v2 branch (#654). The solution is slightly different though.

In v2, scripts can have an extra pre_ or post_ attribute which controls whether they run before or after the dotfiles are updated. The .chezmoiinit script proposed in this issue is by creating a script called pre_run_once_init (for example). This will be run once, before the dotfiles are updated, is a great time to install your password manager, and preserves the safety of chezmoi init not mutating your home directory (beyond cloning your dotfiles repo and creating chezmoi's config file).

For pulling SSH keys, v2 also gets a new template function gitHubKeys "username" which retrieves username's public keys from GitHub.

@twpayne twpayne closed this as completed Jan 17, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants