treewide: improve usage of lib.optional
and lib.optionals
#304726
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR updates
nixpkgs
by replacing instances oflib.optional
withlib.optionals
where appropriate. This change aims to standardize our usage of these functions and make the codebase more intuitive, especially for new contributors.The
lib.optional
function generates a list containing the value if the condition is true, and an empty list if false. Thelib.optionals
function, on the other hand, doesn't wrap values by default. Here is a quick reminder of how both functions behave:During code reviews, I have frequently noticed incorrect usage of
lib.optional
andlib.optionals
. By consistently adoptinglib.optionals
, we can avoid common errors such as unintentionally nested lists when a flat list is expected. This function's explicit need for bracketed output also improves readability and reduces ambiguity, lowering the barrier for new contributors and ensuring alignment with common Nix naming patterns.Description of changes
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 馃憤 reaction to pull requests you find important.