summary refs log tree commit diff
path: root/doc/contributing/coding-conventions.chapter.md
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2021-10-05 23:13:26 +0200
committerGitHub <noreply@github.com>2021-10-05 23:13:26 +0200
commitf289d93a41cf9888f0ade3357b0d8df9104505dd (patch)
tree31ee725c3a0cb16e12d4944af2ffd1d944b8731a /doc/contributing/coding-conventions.chapter.md
parent704b174d77f2a2e2c185739ba728944aedb34ff6 (diff)
downloadnixpkgs-f289d93a41cf9888f0ade3357b0d8df9104505dd.tar
nixpkgs-f289d93a41cf9888f0ade3357b0d8df9104505dd.tar.gz
nixpkgs-f289d93a41cf9888f0ade3357b0d8df9104505dd.tar.bz2
nixpkgs-f289d93a41cf9888f0ade3357b0d8df9104505dd.tar.lz
nixpkgs-f289d93a41cf9888f0ade3357b0d8df9104505dd.tar.xz
nixpkgs-f289d93a41cf9888f0ade3357b0d8df9104505dd.tar.zst
nixpkgs-f289d93a41cf9888f0ade3357b0d8df9104505dd.zip
doc/contributing: add lib.optional (#121251)
Co-authored-by: Cole Helbling <cole.e.helbling@outlook.com>
Diffstat (limited to 'doc/contributing/coding-conventions.chapter.md')
-rw-r--r--doc/contributing/coding-conventions.chapter.md15
1 files changed, 15 insertions, 0 deletions
diff --git a/doc/contributing/coding-conventions.chapter.md b/doc/contributing/coding-conventions.chapter.md
index 85c8626bd99..7a8e7741a33 100644
--- a/doc/contributing/coding-conventions.chapter.md
+++ b/doc/contributing/coding-conventions.chapter.md
@@ -181,6 +181,21 @@
   rev = "${version}";
   ```
 
+- Filling lists condionally _should_ be done with `lib.optional(s)` instead of using `if cond then [ ... ] else null` or `if cond then [ ... ] else [ ]`.
+
+  ```nix
+  buildInputs = lib.optional stdenv.isDarwin iconv;
+  ```
+
+  instead of
+
+  ```nix
+  buildInputs = if stdenv.isDarwin then [ iconv ] else null;
+  ```
+
+  As an exception, an explicit conditional expression with null can be used when fixing a important bug without triggering a mass rebuild.
+  If this is done a follow up pull request _should_ be created to change the code to `lib.optional(s)`.
+
 - Arguments should be listed in the order they are used, with the exception of `lib`, which always goes first.
 
 ## Package naming {#sec-package-naming}