-
Notifications
You must be signed in to change notification settings - Fork 3
/
default.nix
119 lines (115 loc) · 4.15 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{ sources ? import ./nix/sources.nix # managed by https://github.com/nmattia/niv
, nixpkgs ? sources.nixpkgs
, pkgs ? import nixpkgs {}
, cargo ? import ./Cargo.nix {
inherit nixpkgs pkgs; release = false;
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
prost-build = attrs: {
buildInputs = [ pkgs.protobuf ];
};
tonic-reflection = attrs: {
buildInputs = [ pkgs.rustfmt ];
};
csi-grpc = attrs: {
nativeBuildInputs = [ pkgs.protobuf ];
};
stackable-secret-operator = attrs: {
buildInputs = [ pkgs.protobuf pkgs.rustfmt ];
};
stackable-opa-user-info-fetcher = attrs: {
# TODO: why is this not pulled in via libgssapi-sys?
buildInputs = [ pkgs.krb5 ];
};
krb5-sys = attrs: {
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.krb5 ];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
# Clang's resource directory is located at ${pkgs.clang.cc.lib}/lib/clang/<version>.
# Starting with Clang 16, only the major version is used for the resource directory,
# whereas the full version was used in prior Clang versions (see
# https://github.com/llvm/llvm-project/commit/e1b88c8a09be25b86b13f98755a9bd744b4dbf14).
# The clang wrapper ${pkgs.clang} provides a symlink to the resource directory, which
# we use instead.
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang}/resource-root/include";
};
libgssapi-sys = attrs: {
buildInputs = [ pkgs.krb5 ];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang}/resource-root/include";
};
};
}
, meta ? pkgs.lib.importJSON ./nix/meta.json
, dockerName ? "docker.stackable.tech/sandbox/${meta.operator.name}"
, dockerTag ? null
}:
rec {
inherit cargo sources pkgs meta;
build = cargo.allWorkspaceMembers;
entrypoint = build+"/bin/stackable-${meta.operator.name}";
crds = pkgs.runCommand "${meta.operator.name}-crds.yaml" {}
''
${entrypoint} crd > $out
'';
dockerImage = pkgs.dockerTools.streamLayeredImage {
name = dockerName;
tag = dockerTag;
contents = [
# Common debugging tools
pkgs.bashInteractive pkgs.coreutils pkgs.util-linuxMinimal
# Kerberos 5 must be installed globally to load plugins correctly
pkgs.krb5
# Make the whole cargo workspace available on $PATH
build
];
config = {
Env =
let
fileRefVars = {
PRODUCT_CONFIG = deploy/config-spec/properties.yaml;
};
in pkgs.lib.concatLists (pkgs.lib.mapAttrsToList (env: path: pkgs.lib.optional (pkgs.lib.pathExists path) "${env}=${path}") fileRefVars);
Entrypoint = [ entrypoint ];
Cmd = [ "run" ];
};
};
docker = pkgs.linkFarm "listener-operator-docker" [
{
name = "load-image";
path = dockerImage;
}
{
name = "ref";
path = pkgs.writeText "${dockerImage.name}-image-tag" "${dockerImage.imageName}:${dockerImage.imageTag}";
}
{
name = "image-repo";
path = pkgs.writeText "${dockerImage.name}-repo" dockerImage.imageName;
}
{
name = "image-tag";
path = pkgs.writeText "${dockerImage.name}-tag" dockerImage.imageTag;
}
{
name = "crds.yaml";
path = crds;
}
];
# need to use vendored crate2nix because of https://github.com/kolloch/crate2nix/issues/264
crate2nix = import sources.crate2nix {};
tilt = pkgs.tilt;
regenerateNixLockfiles = pkgs.writeScriptBin "regenerate-nix-lockfiles"
''
#!/usr/bin/env bash
set -euo pipefail
echo Running crate2nix
${crate2nix}/bin/crate2nix generate
# crate2nix adds a trailing newline (see
# https://github.com/nix-community/crate2nix/commit/5dd04e6de2fbdbeb067ab701de8ec29bc228c389).
# The pre-commit hook trailing-whitespace wants to remove it again
# (see https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file#trailing-whitespace).
# So, remove the trailing newline already here to avoid that an
# unnecessary change is shown in Git.
sed -i '$d' Cargo.nix
'';
}