maybe add multiple outputs support to nix flake for jemalloc and hardened_malloc

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-10 20:31:00 -04:00 committed by June
parent 10219a531b
commit a94387dcdc
3 changed files with 124 additions and 4 deletions

1
Cargo.lock generated
View file

@ -2482,6 +2482,7 @@ dependencies = [
"libz-sys", "libz-sys",
"lz4-sys", "lz4-sys",
"pkg-config", "pkg-config",
"tikv-jemalloc-sys",
"zstd-sys", "zstd-sys",
] ]

View file

@ -326,12 +326,11 @@ default = [
"gzip_compression", "gzip_compression",
"brotli_compression", "brotli_compression",
"zstd_compression", "zstd_compression",
"hardened_malloc",
] ]
backend_sqlite = ["sqlite"] backend_sqlite = ["sqlite"]
backend_rocksdb = ["rocksdb"] backend_rocksdb = ["rocksdb"]
rocksdb = ["rust-rocksdb", "num_cpus"] rocksdb = ["rust-rocksdb", "num_cpus"]
jemalloc = ["tikv-jemalloc-ctl", "tikv-jemallocator"] jemalloc = ["tikv-jemalloc-ctl", "tikv-jemallocator", "rust-rocksdb/jemalloc"]
sqlite = ["rusqlite", "parking_lot", "thread_local", "num_cpus"] sqlite = ["rusqlite", "parking_lot", "thread_local", "num_cpus"]
systemd = ["sd-notify"] systemd = ["sd-notify"]
sentry_telemetry = ["sentry", "sentry-tracing", "sentry-tower"] sentry_telemetry = ["sentry", "sentry-tracing", "sentry-tower"]

124
flake.nix
View file

@ -41,7 +41,7 @@
let let
version = "9.0.0"; version = "9.0.0";
in in
pkgs.rocksdb.overrideAttrs (old: { (pkgs.rocksdb.overrideAttrs (old: {
inherit version; inherit version;
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "girlbossceo"; owner = "girlbossceo";
@ -49,7 +49,7 @@
rev = "449768a833b79c267c584b5ab1d50e73db6faf9d"; rev = "449768a833b79c267c584b5ab1d50e73db6faf9d";
hash = "sha256-MjmGfAlZ5WC2+hFH6nEUprqBjO8xiTQh2HJIqQ5mIg8="; hash = "sha256-MjmGfAlZ5WC2+hFH6nEUprqBjO8xiTQh2HJIqQ5mIg8=";
}; };
}); }));
# Nix-accessible `Cargo.toml` # Nix-accessible `Cargo.toml`
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
@ -185,6 +185,50 @@
meta.mainProgram = cargoToml.package.name; meta.mainProgram = cargoToml.package.name;
}; };
packageJemalloc = pkgs: builder pkgs {
src = nix-filter {
root = ./.;
include = [
"src"
"Cargo.toml"
"Cargo.lock"
];
};
rocksdb' = pkgs.rocksdb.override { enableJemalloc = true; };
# This is redundant with CI
doCheck = false;
env = env pkgs;
nativeBuildInputs = nativeBuildInputs pkgs;
meta.mainProgram = cargoToml.package.name;
buildFeatures = [ "jemalloc" ];
};
packageHMalloc = pkgs: builder pkgs {
src = nix-filter {
root = ./.;
include = [
"src"
"Cargo.toml"
"Cargo.lock"
];
};
# This is redundant with CI
doCheck = false;
env = env pkgs;
nativeBuildInputs = nativeBuildInputs pkgs;
meta.mainProgram = cargoToml.package.name;
buildFeatures = [ "hardened_malloc" ];
};
mkOciImage = pkgs: package: mkOciImage = pkgs: package:
pkgs.dockerTools.buildImage { pkgs.dockerTools.buildImage {
name = package.pname; name = package.pname;
@ -204,11 +248,55 @@
]; ];
}; };
}; };
mkOciImageJemalloc = pkgs: packageJemalloc:
pkgs.dockerTools.buildImage {
name = "${package.pname}-jemalloc";
tag = "main";
copyToRoot = [
pkgs.dockerTools.caCertificates
];
config = {
# Use the `tini` init system so that signals (e.g. ctrl+c/SIGINT)
# are handled as expected
Entrypoint = [
"${pkgs.lib.getExe' pkgs.tini "tini"}"
"--"
];
Cmd = [
"${pkgs.lib.getExe package}"
];
};
};
mkOciImageHMalloc = pkgs: packageHMalloc:
pkgs.dockerTools.buildImage {
name = "${package.pname}-hmalloc";
tag = "main";
copyToRoot = [
pkgs.dockerTools.caCertificates
];
config = {
# Use the `tini` init system so that signals (e.g. ctrl+c/SIGINT)
# are handled as expected
Entrypoint = [
"${pkgs.lib.getExe' pkgs.tini "tini"}"
"--"
];
Cmd = [
"${pkgs.lib.getExe package}"
];
};
};
in in
{ {
packages = { packages = {
default = package pkgsHost; default = package pkgsHost;
jemalloc = packageJemalloc pkgsHost;
hmalloc = packageHMalloc pkgsHost;
oci-image = mkOciImage pkgsHost self.packages.${system}.default; oci-image = mkOciImage pkgsHost self.packages.${system}.default;
oci-image-jemalloc = mkOciImageJemalloc pkgsHost self.packages.${system}.default;
oci-image-hmalloc = mkOciImageHMalloc pkgsHost self.packages.${system}.default;
book = book =
let let
@ -261,6 +349,18 @@
value = package pkgsCrossStatic; value = package pkgsCrossStatic;
} }
# An output for a statically-linked binary with jemalloc
{
name = "${binaryName}-jemalloc";
value = packageJemalloc pkgsCrossStatic;
}
# An output for a statically-linked binary with hardened_malloc
{
name = "${binaryName}-hmalloc";
value = packageHMalloc pkgsCrossStatic;
}
# An output for an OCI image based on that binary # An output for an OCI image based on that binary
{ {
name = "oci-image-${crossSystem}"; name = "oci-image-${crossSystem}";
@ -268,11 +368,31 @@
pkgsCrossStatic pkgsCrossStatic
self.packages.${system}.${binaryName}; self.packages.${system}.${binaryName};
} }
# An output for an OCI image based on that binary with jemalloc
{
name = "oci-image-${crossSystem}-jemalloc";
value = mkOciImageJemalloc
pkgsCrossStatic
self.packages.${system}.${binaryName};
}
# An output for an OCI image based on that binary with hardened_malloc
{
name = "oci-image-${crossSystem}-hmalloc";
value = mkOciImageHMalloc
pkgsCrossStatic
self.packages.${system}.${binaryName};
}
] ]
) )
[ [
"x86_64-unknown-linux-musl" "x86_64-unknown-linux-musl"
"x86_64-unknown-linux-musl-jemalloc"
"x86_64-unknown-linux-musl-hmalloc"
"aarch64-unknown-linux-musl" "aarch64-unknown-linux-musl"
"aarch64-unknown-linux-musl-jemalloc"
"aarch64-unknown-linux-musl-hmalloc"
] ]
) )
); );