Skip to content

cli: init with template #1721

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

LorenzBischof
Copy link
Contributor

Closes #1718

@liammcdermott
Copy link

Thanks for this! I tested this PR using:

devenv init --template github:LorenzBischof/devenv-issue-1718

And it worked as expected.

@LorenzBischof
Copy link
Contributor Author

If this feature is being considered, we should probably also merge the .gitignore file.

I also thought about maybe forcing a template prefix? We could default to devenv-default and if that does not exist list all the templates that start with devenv-? This would ensure that there can be both flake and devenv templates at the same time.

We could also think about adding a templates option to the devenv.nix file, but that would require committing the generated flake.nix or reimplementing the whole template downloading logic ourselves.

@sandydoo
Copy link
Member

@LorenzBischof, this is fine as it is. I don't particularly like coupling ourselves to the flake API, but this feels like a useful feature for some and we can re-implement the behaviuor separately if needed down the line.

Could you please rebase this on main for the builds to pass and I'll merge it.

@domenkozar
Copy link
Member

I don't think we should be using flakes for templates, we should add templates top-level attribute to devenv if we want to support it

@LorenzBischof
Copy link
Contributor Author

LorenzBischof commented Mar 16, 2025

@domenkozar Could you give me a quick heads up if the following approach sounds reasonable?

  1. Split template reference at #
  2. nix flake prefetch with the first part.
  3. Generate a Flake from the devenv.nix
  4. Use nix flake init --template with the store path and second part after #

This would reuse all the code from Flake templates, but would allow a future refactor if required. It also allows us to validate templates and fail if something is wrong or there are no devenv templates available.

@domenkozar
Copy link
Member

domenkozar commented Mar 17, 2025

We're currently hacking on #1548 at https://oceansprint.org, I think we need that in order to be able to parse flakeref uris and then we can support templates directly from devenv.

It's going to take a while to get this in, but I really don't want to encourage to write flake files for templates and then using devenv.

@LorenzBischof LorenzBischof force-pushed the templates branch 9 times, most recently from d2da73a to 45a9059 Compare March 18, 2025 20:05
@LorenzBischof
Copy link
Contributor Author

The templates can now be specified in the devenv.nix file under the top-level templates option. The basic functionality is implemented, but still needs some cleanup.

Since I have no idea how far along the Snix implementation is, I do not know if it makes sense to continue. Would you consider merging this before the rewrite?

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.

Devenv init template support
4 participants