diff options
author | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2008-08-05 17:16:35 +0000 |
---|---|---|
committer | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2008-08-05 17:16:35 +0000 |
commit | 0e25bb67cf0e264034616b7173f9a12af9536a5c (patch) | |
tree | 9d9d72b00e3f432eeb70f145f64a50c9821ed31b /pkgs/test | |
parent | 7abbe5889f86ed720cf45a8a311339027986b7fb (diff) |
Add a new way to handle option sets.
svn path=/nixpkgs/trunk/; revision=12505
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/mkOption/declare.nix | 53 | ||||
-rw-r--r-- | pkgs/test/mkOption/keep.nix | 11 | ||||
-rw-r--r-- | pkgs/test/mkOption/keep.ref | 57 | ||||
-rw-r--r-- | pkgs/test/mkOption/merge.nix | 15 | ||||
-rw-r--r-- | pkgs/test/mkOption/merge.ref | 20 | ||||
-rwxr-xr-x | pkgs/test/mkOption/test.sh | 9 |
6 files changed, 165 insertions, 0 deletions
diff --git a/pkgs/test/mkOption/declare.nix b/pkgs/test/mkOption/declare.nix new file mode 100644 index 000000000000..9e89a1c096da --- /dev/null +++ b/pkgs/test/mkOption/declare.nix @@ -0,0 +1,53 @@ +# sets of small configurations: +# Each configuration +rec { + # has 2 arguments pkgs and this. + configA = pkgs: this: { + # Can depends on other configuration + require = configB; + + # Defines new options + optionA = pkgs.lib.mkOption { + # With default values + default = false; + # And merging functions. + merge = pkgs.lib.mergeEnableOption; + }; + + # Add a new definition to other options. + optionB = this.optionA; + }; + + # Can be used for option header. + configB = pkgs: this: { + # Can depends on more than one configuration. + require = [ configC configD ]; + + optionB = pkgs.lib.mkOption { + default = false; + }; + + # Is not obliged to define other options. + }; + + configC = pkgs: this: { + require = [ configA ]; + + optionC = pkgs.lib.mkOption { + default = false; + }; + + # Use the default value if it is not overwritten. + optionA = this.optionC; + }; + + # Can also be used as option configuration only. + # without any arguments (backward compatibility) + configD = { + # Is not forced to specify the require attribute. + + # Is not force to make new options. + optionA = true; + optionD = false; + }; +} diff --git a/pkgs/test/mkOption/keep.nix b/pkgs/test/mkOption/keep.nix new file mode 100644 index 000000000000..c26064d89f7e --- /dev/null +++ b/pkgs/test/mkOption/keep.nix @@ -0,0 +1,11 @@ +let + pkgs = import ../../top-level/all-packages.nix {}; + config = import ./declare.nix; +in + with (pkgs.lib); + + finalReferenceOptionSets + filterOptionSets + pkgs + # List of main configurations. + [ config.configB config.configC ] diff --git a/pkgs/test/mkOption/keep.ref b/pkgs/test/mkOption/keep.ref new file mode 100644 index 000000000000..a3a051eb48c4 --- /dev/null +++ b/pkgs/test/mkOption/keep.ref @@ -0,0 +1,57 @@ +<?xml version='1.0' encoding='utf-8'?> +<expr> + <attrs> + <attr name="optionA"> + <list> + <attrs> + <attr name="_type"> + <string value="option" /> + </attr> + <attr name="default"> + <bool value="false" /> + </attr> + <attr name="merge"> + <unevaluated /> + </attr> + <attr name="name"> + <string value="optionA" /> + </attr> + </attrs> + </list> + </attr> + <attr name="optionB"> + <list> + <attrs> + <attr name="_type"> + <string value="option" /> + </attr> + <attr name="default"> + <bool value="false" /> + </attr> + <attr name="name"> + <string value="optionB" /> + </attr> + </attrs> + </list> + </attr> + <attr name="optionC"> + <list> + <attrs> + <attr name="_type"> + <string value="option" /> + </attr> + <attr name="default"> + <bool value="false" /> + </attr> + <attr name="name"> + <string value="optionC" /> + </attr> + </attrs> + </list> + </attr> + <attr name="optionD"> + <attrs> + </attrs> + </attr> + </attrs> +</expr> diff --git a/pkgs/test/mkOption/merge.nix b/pkgs/test/mkOption/merge.nix new file mode 100644 index 000000000000..0d4b3c1acd18 --- /dev/null +++ b/pkgs/test/mkOption/merge.nix @@ -0,0 +1,15 @@ +let + pkgs = import ../../top-level/all-packages.nix {}; + config = import ./declare.nix; + + # Define the handler of unbound options. + noOption = name: values: + builtins.trace "Attribute named '${name}' does not match any option declaration." values; +in + with (pkgs.lib); + + finalReferenceOptionSets + (mergeOptionSets noOption) + pkgs + # List of main configurations. + [ config.configB config.configC ] diff --git a/pkgs/test/mkOption/merge.ref b/pkgs/test/mkOption/merge.ref new file mode 100644 index 000000000000..6956f65dbbcc --- /dev/null +++ b/pkgs/test/mkOption/merge.ref @@ -0,0 +1,20 @@ +trace: Str("Attribute named 'optionD' does not match any option declaration.",[]) +<?xml version='1.0' encoding='utf-8'?> +<expr> + <attrs> + <attr name="optionA"> + <bool value="true" /> + </attr> + <attr name="optionB"> + <bool value="true" /> + </attr> + <attr name="optionC"> + <bool value="false" /> + </attr> + <attr name="optionD"> + <list> + <bool value="false" /> + </list> + </attr> + </attrs> +</expr> diff --git a/pkgs/test/mkOption/test.sh b/pkgs/test/mkOption/test.sh new file mode 100755 index 000000000000..5478846d563f --- /dev/null +++ b/pkgs/test/mkOption/test.sh @@ -0,0 +1,9 @@ +#! /bin/sh -e + +echo 1>&2 "Test: Merge of option bindings." +nix-instantiate merge.nix --eval-only --strict --xml >& merge.out +diff merge.ref merge.out + +echo 1>&2 "Test: Filter of option declarations." +nix-instantiate keep.nix --eval-only --strict --xml >& keep.out +diff keep.ref keep.out |