From 250de35e057b8242497ae547f6bde7a259cdf536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Tue, 4 Apr 2023 23:37:15 +0200 Subject: [PATCH] contributing: remove information related to mkCompositeOption (#316) --- CONTRIBUTING.md | 46 +++++----------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 83b89a2f..8979e714 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,50 +78,14 @@ Because the options may not have the same case (and may require some pre-process ```nix { some_opt = cfg.someOpt; - some_raw_opt = helpers.ifNonNull' cfg.some_raw_opt (mkRaw cfg.some_raw_opt); - some_submodule_opt = with cfg.submoduleOpt; - helpers.ifNonNull' cfg.someSubmoduleOpt { - inherit some_opt; - some_other_opt = someOtherOpt; - }; -} -``` - -#### A note on composite/nested options - -Here is how to handle options that have several suboptions: -```nix -{ - options.my-plugin = { - ... - option1 = ... - - myCompositeOption = helpers.mkCompositeOption "Description of my composite option" { - - subOption1 = helpers.defaultNullOpts.mkStr "foo" "This is subOption1 which does X"; - subOption2 = helpers.defaultNullOpts.mkStr "baz" "This is subOption2 which does Y"; + some_raw_opt = helpers.ifNonNull' cfg.someRawOpt (mkRaw cfg.someRawOpt); + some_meta_opt = with cfg.metaOpt; # metaOpt = { foo = ...; someOtherOpt = ...; }; + { + inherit foo; + some_other_opt = someOtherOpt; }; - ... - }; - - config = mkIf cfg.enabled { - option_1 = cfg.option1; - my_composite_option = with cfg.myCompositeOption; - helpers.ifNonNull' cfg.myCompositeOption { - sub_option_1 = subOption1; - sub_option_2 = subOption2; - }; - }; } ``` -`mkCompositeOption` creates an option which default is `null` and which type is a `types.submodule` -with the provided options. -Because the default value for `myCompositeOption` is `null`, we have to handle this case in the -implementation part using `helpers.ifNonNull'` which is defined as: -```nix -ifNonNull' = x: y: if x == null then null else y; -``` - ### Tests