On Fri, Jan 22, 2016 at 01:31:37PM +0900, Eric Sagnes wrote:
> I would like to force an option of type `types.listOf packages` to
> allow only a certain list of packages. Something like `types.someOf
> packages [ pkgs.pluginA pkgs.pluginB pkgs.pluginC ]`.
>
> So that if a user set `myModule.plugins = [ pkgs.pluginA pkgs.firefox
> ]`, it gives an error like "Invalid value `pkgs.firefox` for
> `myModule.plugins. Values should be some of [ pkgs.pluginA
> pkgs.pluginB pkgs.pluginC ]";
>
> Is there a way to achieve this?

You can use something like:

  listOf (enum [ pkgs.pluginA pkgs.firefox ])

However, I'd advise against that because on comparison the list elements
are unboxed and thus can lead to an infinite recursion.

I'd suggest the following in this case:

  listOf (addCheck package (p: p.meta.isFooPlugin or false))

That way only packages with a meta.isFooPlugin attribute can be added to
that list and nothing else. And it also avoids unboxing the full
attribute set, because it checks only the meta attribute and whether it
is a derivation/store path.

a!
-- 
aszlig
Universal dilettante

Attachment: signature.asc
Description: Digital signature

_______________________________________________
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev

Reply via email to