nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 formats,
4 stdenvNoCC,
5 writeText,
6 ...
7}:
8let
9 hocon = formats.hocon { };
10
11 include_file =
12 (writeText "hocon-test-include.conf" ''
13 "val" = 1
14 '').overrideAttrs
15 (
16 _: _: {
17 outputHashAlgo = "sha256";
18 outputHashMode = "flat";
19 outputHash = "sha256-UhkJLhT3bD6znq+IdDjs/ahP19mLzrLCy/R14pVrfew=";
20 }
21 );
22
23 expression = {
24 simple_top_level_attr = "1.0";
25 nested.attrset.has.a.integer.value = 100;
26 some_floaty = 29.95;
27
28 array2d = [
29 [
30 1
31 2
32 "a"
33 ]
34 [
35 2
36 1
37 "b"
38 ]
39 ];
40 nasty_string = "\"@\n\\\t^*bf\n0\";'''$";
41
42 "misc attrs" = {
43 x = 1;
44 y = hocon.lib.mkAppend { a = 1; };
45 };
46
47 "cursed \" .attrs \" " = {
48 "a" = 1;
49 "a b" = hocon.lib.mkSubstitution "a";
50 "a b c" = hocon.lib.mkSubstitution {
51 value = "a b";
52 required = false;
53 };
54 };
55
56 to_include = {
57 _includes = [
58 (hocon.lib.mkInclude include_file)
59 (hocon.lib.mkInclude "https://example.com")
60 (hocon.lib.mkInclude {
61 required = true;
62 type = "file";
63 value = include_file;
64 })
65 (hocon.lib.mkInclude { value = include_file; })
66 (hocon.lib.mkInclude {
67 value = "https://example.com";
68 type = "url";
69 })
70 ];
71 };
72 };
73
74 hocon-test-conf = hocon.generate "hocon-test.conf" expression;
75in
76stdenvNoCC.mkDerivation {
77 name = "pkgs.formats.hocon-test-comprehensive";
78
79 dontUnpack = true;
80 dontBuild = true;
81
82 doCheck = true;
83 checkPhase = ''
84 runHook preCheck
85
86 diff -U3 ${./expected.txt} ${hocon-test-conf}
87
88 runHook postCheck
89 '';
90
91 installPhase = ''
92 runHook preInstall
93
94 mkdir $out
95 cp ${./expected.txt} $out/expected.txt
96 cp ${hocon-test-conf} $out/hocon-test.conf
97 cp ${hocon-test-conf.passthru.json} $out/hocon-test.json
98
99 runHook postInstall
100 '';
101}