Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 formats, 4 stdenvNoCC, 5 writeText, 6 ... 7}: 8let 9 libconfig = formats.libconfig { }; 10 11 include_expr = { 12 val = 1; 13 }; 14 15 include_file = writeText "libconfig-test-include" '' 16 val=1; 17 ''; 18 19 expression = { 20 simple_top_level_attr = "1.0"; 21 nested.attrset.has.a.integer.value = 100; 22 some_floaty = 29.95; 23 ## dashes in key names 24 top-level-dash = "pass"; 25 nested.level-dash = "pass"; 26 ## Same syntax here on these two, but they should get serialized differently: 27 # > A list may have zero or more elements, each of which can be a scalar value, an array, a group, or another list. 28 list1d = libconfig.lib.mkList [ 29 1 30 "mixed!" 31 5 32 2 33 ]; 34 # You might also omit the mkList, as a list will be a list (in contrast to an array) by default. 35 list2d = [ 36 1 37 [ 38 1 39 1.2 40 "foo" 41 ] 42 [ 43 "bar" 44 1.2 45 1 46 ] 47 ]; 48 # > An array may have zero or more elements, but the elements must all be scalar values of the same type. 49 array1d = libconfig.lib.mkArray [ 50 1 51 5 52 2 53 ]; 54 array2d = [ 55 (libconfig.lib.mkArray [ 56 1 57 2 58 ]) 59 (libconfig.lib.mkArray [ 60 2 61 1 62 ]) 63 ]; 64 nasty_string = "\"@\n\\\t^*bf\n0\";'''$"; 65 66 weirderTypes = { 67 _includes = [ include_file ]; 68 pi = 3.141592654; 69 bigint = 9223372036854775807; 70 hex = libconfig.lib.mkHex "0x1FC3"; 71 octal = libconfig.lib.mkOctal "0027"; 72 float = libconfig.lib.mkFloat "1.2E-3"; 73 array_of_ints = libconfig.lib.mkArray [ 74 (libconfig.lib.mkOctal "0732") 75 (libconfig.lib.mkHex "0xA3") 76 1234 77 ]; 78 list_of_weird_types = [ 79 3.141592654 80 9223372036854775807 81 (libconfig.lib.mkHex "0x1FC3") 82 (libconfig.lib.mkOctal "0027") 83 (libconfig.lib.mkFloat "1.2E-32") 84 (libconfig.lib.mkFloat "1") 85 ]; 86 }; 87 }; 88 89 libconfig-test-cfg = libconfig.generate "libconfig-test.cfg" expression; 90in 91stdenvNoCC.mkDerivation { 92 name = "pkgs.formats.libconfig-test-comprehensive"; 93 94 dontUnpack = true; 95 dontBuild = true; 96 97 doCheck = true; 98 checkPhase = '' 99 cp ${./expected.txt} expected.txt 100 substituteInPlace expected.txt \ 101 --subst-var-by include_file "${include_file}" 102 diff -U3 ./expected.txt ${libconfig-test-cfg} 103 ''; 104 105 installPhase = '' 106 mkdir $out 107 cp expected.txt $out 108 cp ${libconfig-test-cfg} $out/libconfig-test.cfg 109 cp ${libconfig-test-cfg.passthru.json} $out/libconfig-test.json 110 ''; 111}