hercules-ci / flake-parts

❄️ Simplify Nix Flakes with the module system
https://flake.parts
MIT License
698 stars 38 forks source link

How to define a custom flake attribute for a reusable module #201

Closed loqusion closed 7 months ago

loqusion commented 7 months ago

I'm trying to add a custom option lib to my reusable flake module, and here's what the documentation has to say about it (emphasis added):

If your custom output attribute is a one-off because you need to do something special in a single project, all you have to do is define a value in the flake option.

However, if you want it to be reusable and integrate well, you should declare an option for it, and you could perhaps provide a bit of support logic if that makes sense to do.

However, this piece of documentation does not answer the question "how do I declare an option?", nor does it provide a link doing so. Looking through the rest of the documentation also does not provide any obvious answers.

It would be very helpful if a link that answers this question were present in this text, something like:

If your custom output attribute is a one-off because you need to do something special in a single project, all you have to do is define a value in the flake option.

However, if you want it to be reusable and integrate well, you should declare an option for it, and you could perhaps provide a bit of support logic if that makes sense to do.

Or, alternatively, provide a code snippet that demonstrates how to do so.

bew commented 7 months ago

Why close? Did you find documentation? I'm kinda blocked as well around this topic of "how to actually do a module"

terlar commented 7 months ago

This shows an example on how to define a custom option that will put things under the root flake.

https://github.com/hercules-ci/flake-parts/blob/main/modules/nixosModules.nix#L14

You can use the mkSubmoduleOptions from flake-parts-lib.