at master 1.3 kB view raw
1# Check that AttrsWith { lazy = true; } is lazy 2{ lib, ... }: 3let 4 inherit (lib) types mkOption; 5 6 lazyAttrsOf = mkOption { 7 # Same as lazyAttrsOf 8 type = types.attrsWith { 9 lazy = true; 10 elemType = types.int; 11 }; 12 }; 13 14 attrsOf = mkOption { 15 # Same as lazyAttrsOf 16 type = types.attrsWith { 17 elemType = types.int; 18 }; 19 }; 20in 21{ 22 imports = [ 23 # Module A 24 ( 25 { ... }: 26 { 27 options.mergedLazyLazy = lazyAttrsOf; 28 options.mergedLazyNonLazy = lazyAttrsOf; 29 options.mergedNonLazyNonLazy = attrsOf; 30 } 31 ) 32 # Module B 33 ( 34 { ... }: 35 { 36 options.mergedLazyLazy = lazyAttrsOf; 37 options.mergedLazyNonLazy = attrsOf; 38 options.mergedNonLazyNonLazy = attrsOf; 39 } 40 ) 41 # Result 42 ( 43 { config, ... }: 44 { 45 # Can only evaluate if lazy 46 config.mergedLazyLazy.bar = config.mergedLazyLazy.baz + 1; 47 config.mergedLazyLazy.baz = 10; 48 options.lazyResult = mkOption { default = config.mergedLazyLazy.bar; }; 49 50 # Can not only evaluate if not lazy 51 config.mergedNonLazyNonLazy.bar = config.mergedNonLazyNonLazy.baz + 1; 52 config.mergedNonLazyNonLazy.baz = 10; 53 options.nonLazyResult = mkOption { default = config.mergedNonLazyNonLazy.bar; }; 54 } 55 ) 56 ]; 57}