Skip to content

Commit

Permalink
lib/modules: Test the ability for config to depend on options for com…
Browse files Browse the repository at this point in the history
…patibility
  • Loading branch information
roberth committed Mar 17, 2020
1 parent b6a5079 commit 31206e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/tests/modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ checkConfigError 'The option .* defined in .* does not exist' config.enable ./di
# Check that imports can depend on derivations
checkConfigOutput "true" config.enable ./import-from-store.nix

# Check that configs can be conditional on option existence
checkConfigOutput true config.enable ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix
checkConfigOutput 360 config.value ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix
checkConfigOutput 7 config.value ./define-option-dependently.nix ./declare-int-positive-value.nix

# Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only
# attrsOf should work with conditional definitions
# In addition, lazyAttrsOf should honor an options emptyValue
Expand Down
16 changes: 16 additions & 0 deletions lib/tests/modules/define-option-dependently.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ lib, options, ... }:

# Some modules may be distributed separately and need to adapt to other modules
# that are distributed and versioned separately.
{

# Always defined, but the value depends on the presence of an option.
config = {
value = if options ? enable then 360 else 7;
}
# Only define if possible.
// lib.optionalAttrs (options ? enable) {
enable = true;
};

}

0 comments on commit 31206e4

Please sign in to comment.