Skip to content
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

lib.optionals in place of lib.optional ? #140

Open
drupol opened this issue Aug 16, 2023 · 0 comments
Open

lib.optionals in place of lib.optional ? #140

drupol opened this issue Aug 16, 2023 · 0 comments

Comments

@drupol
Copy link

drupol commented Aug 16, 2023

Hello,

How about having a rule explaining why lib.optionals is a better idea than lib.optional ?

Here are some rough ideas:

  1. Since lib.optional does more than expected. It wraps its contents into a list. This adds an extra cognitive load for newcomers.
  2. Some people consider it harmful: https://discourse.nixos.org/t/lib-optional-considered-harmful/7081
  3. Since we are dealing with buildInputs which is a list containing potential more than 1 element, using the plural form lib.optionals seems more natural.
  4. Using lib.optionals allows you to add more than one element after the condition. If you try to do the same with lib.optional, you might end up with lists within lists.
  5. I've been submitting a couple of PRs against nixpkgs before and some maintainers asked me to use lib.optionals instead of lib.optional.
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

No branches or pull requests

1 participant