1 { lib, writeTextFile, buildPackages }:
3 # See https://people.freedesktop.org/~dbn/pkg-config-guide.html#concepts
4 { name # The name of the pc file
6 # provide a default description for convenience. it's not important but still required by pkg-config.
7 , description ? "Pkg-config file for ${name}"
11 , requiresPrivate ? [ ]
20 # only 'out' has to be changed, otherwise it would be replaced by the out of the writeTextFile
21 placeholderToSubstVar = builtins.replaceStrings [ "${placeholder "out"}" ] [ "@out@" ];
23 replacePlaceholderAndListToString = x:
25 then placeholderToSubstVar (builtins.concatStringsSep " " x)
26 else placeholderToSubstVar x;
30 mustBeAList = attr: attrName: lib.throwIfNot (lib.isList attr) "'${attrName}' must be a list" attr;
34 "Description" = description;
37 "Requires" = mustBeAList requires "requires";
38 "Requires.private" = mustBeAList requiresPrivate "requiresPrivate";
39 "Conflicts" = mustBeAList conflicts "conflicts";
40 "Cflags" = mustBeAList cflags "cflags";
41 "Libs" = mustBeAList libs "libs";
42 "Libs.private" = mustBeAList libsPrivate "libsPrivate";
45 renderVariable = name: value:
46 lib.optionalString (value != "" && value != [ ]) "${name}=${replacePlaceholderAndListToString value}";
47 renderKeyword = name: value:
48 lib.optionalString (value != "" && value != [ ]) "${name}: ${replacePlaceholderAndListToString value}";
50 renderSomething = renderFunc: attrs:
52 (lib.mapAttrsToList renderFunc)
53 (builtins.filter (v: v != ""))
57 variablesSectionRendered = renderSomething renderVariable variables;
58 keywordsSectionRendered = renderSomething renderKeyword keywordsSection;
60 content = [ variablesSectionRendered keywordsSectionRendered ];
64 destination = "/lib/pkgconfig/${name}.pc";
65 text = builtins.concatStringsSep "\n" content;
66 checkPhase = ''${buildPackages.pkg-config}/bin/${buildPackages.pkg-config.targetPrefix}pkg-config --validate "$target"'';