juspay / omnix

🚧 A Nix wrapper to improve developer experience
https://omnix.page
GNU Affero General Public License v3.0
67 stars 5 forks source link

`om init` - for smart template generation #152

Closed srid closed 1 month ago

srid commented 1 month ago

Add

om init

This should support a registry of flake templates (use our various flake-parts modules), initialize them using nix flake init as well as fill in any user-specific content using the templateGenerators idea in flake-parts/templates#7 (comment)

The goal is to have om init create flakes for any kind of stack, eventually.

Implementation

To extend flake.templates, we can add:

{
  flake.templateGenerators.default = {
    # The generator to use (string or package)
    generator = "om init";
    # Arbitrary metaata (of the template) to pass to the generator.
    templates.default.params = {
    };
  };
}

Here, generator can be an arbitrary derivation (a function that takes pkgs and returns a types.package?) or it can be a string that represents the command line to use to invoke the generator? om init can fetch templates, and look for the special "om init" generator, in which case it can short-circuit by calling the necessary internal initializer function, passing the templates.?.params property as necessary.

Tasks

srid commented 1 month ago

cc @roberth (have I correctly understood your templateGenerators idea?)

srid commented 1 month ago

Alternatively, if we don't care about being general enough, we could just pass om configuration for templates as:

{
  templates.default = { ... };
  om.templates.default = {
    params = {
      # ...
    };
  };
}

This way, we don't have to fully spec out the general case first.

(Later, if a general spec does emerge, it should be straightforward to port the om.templates configuration to it).

See #153 for configuration seen from larger context.

srid commented 1 month ago
image

Regarding this, for MVP - let's keep the additional config in this repo, so it gives us some leeway to change things in future. Otherwise, we can consider this feature basically done.