Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 gnat,
6 gprbuild,
7 which,
8 gnatcoll-core,
9 component,
10 # components built by this derivation other components depend on
11 gnatcoll-sql,
12 gnatcoll-sqlite,
13 gnatcoll-xref,
14 # component specific extra dependencies
15 gnatcoll-iconv,
16 gnatcoll-readline,
17 sqlite,
18 libpq,
19}:
20
21let
22 libsFor = {
23 gnatcoll_db2ada = [
24 gnatcoll-sql
25 ];
26 gnatinspect = [
27 gnatcoll-sqlite
28 gnatcoll-readline
29 gnatcoll-xref
30 ];
31 postgres = [
32 gnatcoll-sql
33 libpq
34 ];
35 sqlite = [
36 gnatcoll-sql
37 sqlite
38 ];
39 xref = [
40 gnatcoll-iconv
41 gnatcoll-sqlite
42 ];
43 };
44
45 # These components are just tools and don't install a library
46 onlyExecutable = builtins.elem component [
47 "gnatcoll_db2ada"
48 "gnatinspect"
49 ];
50in
51
52stdenv.mkDerivation rec {
53 # executables don't adhere to the string gnatcoll-* scheme
54 pname =
55 if onlyExecutable then
56 builtins.replaceStrings [ "_" ] [ "-" ] component
57 else
58 "gnatcoll-${component}";
59 version = "25.0.0";
60
61 src = fetchFromGitHub {
62 owner = "AdaCore";
63 repo = "gnatcoll-db";
64 rev = "v${version}";
65 sha256 = "0q35ii0aa4hh59v768l5cilg1b30a4ckcvlbfy0lkcbp3rcfnbz3";
66 };
67
68 # Link executables dynamically unless specified by the platform,
69 # as we usually do in nixpkgs where possible
70 postPatch = lib.optionalString (!stdenv.hostPlatform.isStatic) ''
71 for f in gnatcoll_db2ada/Makefile gnatinspect/Makefile; do
72 substituteInPlace "$f" --replace "=static" "=relocatable"
73 done
74 '';
75
76 nativeBuildInputs = [
77 gnat
78 gprbuild
79 which
80 ];
81
82 # Propagate since GPRbuild needs to find referenced .gpr files
83 # and other libraries to link against when static linking is used.
84 # For executables this is of course not relevant and we can reduce
85 # the closure size dramatically
86 ${if onlyExecutable then "buildInputs" else "propagatedBuildInputs"} = [
87 gnatcoll-core
88 ]
89 ++ libsFor."${component}" or [ ];
90
91 makeFlags = [
92 "-C"
93 component
94 "PROCESSORS=$(NIX_BUILD_CORES)"
95 # confusingly, for gprbuild --target is autoconf --host
96 "TARGET=${stdenv.hostPlatform.config}"
97 "prefix=${placeholder "out"}"
98 ]
99 ++ lib.optionals (component == "sqlite") [
100 # link against packaged, not vendored libsqlite3
101 "GNATCOLL_SQLITE=external"
102 ];
103
104 meta = with lib; {
105 description = "GNAT Components Collection - Database packages";
106 homepage = "https://github.com/AdaCore/gnatcoll-db";
107 license = licenses.gpl3Plus;
108 maintainers = [ maintainers.sternenseemann ];
109 platforms = platforms.all;
110 };
111}