Skip to content

Conversation

@TakodaS
Copy link

@TakodaS TakodaS commented Mar 4, 2025

Currently you need to manually add a description for templates as per the documentation

templates = {
    my-template.description = "This is my template created with Snowfall Lib!";
};

However, it seems easier and more sane to automatically extract the description from ./templates/my-template/flake.nix's description field. This is what this PR does, meaning that you no longer need to add the above description manually.

@anntnzrb
Copy link

anntnzrb commented Oct 9, 2025

Implemented with Improvements

I've adopted this feature with enhanced error handling for better robustness.

Implementation

The template description auto-extraction now:

Automatically extracts description from ./templates/<name>/flake.nix
Gracefully handles missing flake.nix files
Gracefully handles missing description fields
Maintains backward compatibility with manual overrides
Preserves all metadata (path, description, etc.)

Key Differences from Original PR

The implementation includes additional safety checks:

create-template-metadata = template: let
  flake-file = template + "/flake.nix";
  has-flake = builtins.pathExists flake-file;
  flake-attrs = if has-flake then import flake-file else {};
  description = flake-attrs.description or null;
in
  { name = ...; path = template; }
  // (if description != null then {inherit description;} else {});

This ensures templates without flake.nix or without a description field won't break.

Usage

Templates can now simply define their description in their own flake.nix:

# templates/my-template/flake.nix
{
  description = "My awesome template!";
  # ... rest of template flake
}

No manual configuration needed in the parent flake!

Commit: anntnzrb/snowfall-lib@f00967f

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.

2 participants