1{
2 lib,
3 buildGoModule,
4 fetchFromGitHub,
5 stdenv,
6 pkg-config,
7 rustPlatform,
8 libiconv,
9 nixosTests,
10}:
11
12let
13 libflux_version = "0.196.1";
14
15 # This is copied from influxdb2 with the required flux version
16 flux = rustPlatform.buildRustPackage rec {
17 pname = "libflux";
18 version = libflux_version;
19 src = fetchFromGitHub {
20 owner = "influxdata";
21 repo = "flux";
22 tag = "v${libflux_version}";
23 hash = "sha256-935aN2SxfNZvpG90rXuqZ2OTpSGLgiBDbZsBoG0WUvU=";
24 };
25 patches = [
26 # https://github.com/influxdata/flux/pull/5542
27 ../influxdb2/fix-unsigned-char.patch
28 ];
29 # Don't fail on missing code documentation
30 postPatch = ''
31 substituteInPlace flux-core/src/lib.rs \
32 --replace-fail "deny(warnings, missing_docs))]" "deny(warnings))]"
33 '';
34 sourceRoot = "${src.name}/libflux";
35
36 cargoHash = "sha256-A6j/lb47Ob+Po8r1yvqBXDVP0Hf7cNz8WFZqiVUJj+Y=";
37 nativeBuildInputs = [ rustPlatform.bindgenHook ];
38 buildInputs = lib.optional stdenv.hostPlatform.isDarwin libiconv;
39 pkgcfg = ''
40 Name: flux
41 Version: ${libflux_version}
42 Description: Library for the InfluxData Flux engine
43 Cflags: -I/out/include
44 Libs: -L/out/lib -lflux -lpthread
45 '';
46 passAsFile = [ "pkgcfg" ];
47 postInstall = ''
48 mkdir -p $out/include $out/pkgconfig
49 cp -r $NIX_BUILD_TOP/source/libflux/include/influxdata $out/include
50 substitute $pkgcfgPath $out/pkgconfig/flux.pc \
51 --replace-fail /out $out
52 ''
53 + lib.optionalString stdenv.hostPlatform.isDarwin ''
54 install_name_tool -id $out/lib/libflux.dylib $out/lib/libflux.dylib
55 '';
56 };
57in
58buildGoModule rec {
59 pname = "influxdb";
60 version = "1.12.0";
61
62 src = fetchFromGitHub {
63 owner = "influxdata";
64 repo = "influxdb";
65 rev = "v${version}";
66 hash = "sha256-jSv3zzU/jIqALF9mb4gV7zyQvm8pIwJU6Y4ADBlpVOE=";
67 };
68
69 vendorHash = "sha256-tPw/1vkUTwmRHrnENDG3NJTV6RplI4pCP6GueRT8dbc=";
70
71 nativeBuildInputs = [ pkg-config ];
72
73 PKG_CONFIG_PATH = "${flux}/pkgconfig";
74
75 # Check that libflux is at the right version
76 preBuild = ''
77 flux_ver=$(grep github.com/influxdata/flux go.mod | awk '{print $2}')
78 if [ "$flux_ver" != "v${libflux_version}" ]; then
79 echo "go.mod wants libflux $flux_ver, but nix derivation provides ${libflux_version}"
80 exit 1
81 fi
82 '';
83
84 doCheck = false;
85
86 ldflags = [
87 "-s"
88 "-w"
89 "-X main.version=${version}"
90 ];
91
92 excludedPackages = "test";
93
94 passthru.tests = {
95 inherit (nixosTests) influxdb;
96 };
97
98 meta = with lib; {
99 description = "Open-source distributed time series database";
100 license = licenses.mit;
101 homepage = "https://influxdata.com/";
102 maintainers = with maintainers; [
103 offline
104 zimbatm
105 ];
106 };
107}