libpostal: Use real 1.1 release, add data files and enable tests (#362841)
[NixPkgs.git] / pkgs / pkgs-lib / formats / libconfig / default.nix
blobab0cb6afd12d405c672f57745820f5790f001caf
2   lib,
3   pkgs,
4 }:
5 let
6   inherit (pkgs) buildPackages callPackage;
8   libconfig-generator = buildPackages.rustPlatform.buildRustPackage {
9     name = "libconfig-generator";
10     version = "0.1.0";
11     src = ./src;
13     passthru.updateScript = ./update.sh;
15     cargoLock.lockFile = ./src/Cargo.lock;
16   };
18   libconfig-validator =
19     buildPackages.runCommandCC "libconfig-validator"
20       {
21         buildInputs = with buildPackages; [ libconfig ];
22       }
23       ''
24         mkdir -p "$out/bin"
25         $CC -lconfig -x c - -o "$out/bin/libconfig-validator" ${./validator.c}
26       '';
29   format =
30     {
31       generator ? libconfig-generator,
32       validator ? libconfig-validator,
33     }:
34     {
35       inherit generator;
37       type =
38         with lib.types;
39         let
40           valueType =
41             (oneOf [
42               bool
43               int
44               float
45               str
46               path
47               (attrsOf valueType)
48               (listOf valueType)
49             ])
50             // {
51               description = "libconfig value";
52             };
53         in
54         attrsOf valueType;
56       lib = {
57         mkHex = value: {
58           _type = "hex";
59           inherit value;
60         };
61         mkOctal = value: {
62           _type = "octal";
63           inherit value;
64         };
65         mkFloat = value: {
66           _type = "float";
67           inherit value;
68         };
69         mkArray = value: {
70           _type = "array";
71           inherit value;
72         };
73         mkList = value: {
74           _type = "list";
75           inherit value;
76         };
77       };
79       generate =
80         name: value:
81         callPackage
82           (
83             {
84               stdenvNoCC,
85               libconfig-generator,
86               libconfig-validator,
87               writeText,
88             }:
89             stdenvNoCC.mkDerivation rec {
90               inherit name;
92               dontUnpack = true;
93               preferLocalBuild = true;
95               json = builtins.toJSON value;
96               passAsFile = [ "json" ];
98               strictDeps = true;
99               nativeBuildInputs = [ libconfig-generator ];
100               buildPhase = ''
101                 runHook preBuild
102                 libconfig-generator < $jsonPath > output.cfg
103                 runHook postBuild
104               '';
106               doCheck = true;
107               nativeCheckInputs = [ libconfig-validator ];
108               checkPhase = ''
109                 runHook preCheck
110                 libconfig-validator output.cfg
111                 runHook postCheck
112               '';
114               installPhase = ''
115                 runHook preInstall
116                 mv output.cfg $out
117                 runHook postInstall
118               '';
120               passthru.json = writeText "${name}.json" json;
121             }
122           )
123           {
124             libconfig-generator = generator;
125             libconfig-validator = validator;
126           };
127     };