grapevine/nix/pkgs/default/default.nix
K900 7ee117d36a fix: update nix inputs, fix build with latest crane
Fixes references to rustc leaking into the binary.

Flake lock file updates:

• Updated input 'attic':
    'github:zhaofengli/attic/47752427561f1c34debb16728a210d378f0ece36' (2024-11-10)
  → 'github:zhaofengli/attic/ff8a897d1f4408ebbf4d45fa9049c06b3e1e3f4e' (2025-02-02)
• Updated input 'crane':
    'github:ipetkov/crane/ef80ead953c1b28316cc3f8613904edc2eb90c28' (2024-11-08)
  → 'github:ipetkov/crane/70947c1908108c0c551ddfd73d4f750ff2ea67cd' (2025-03-19)
• Updated input 'fenix':
    'github:nix-community/fenix/e10ba121773f754a30d31b6163919a3e404a434f' (2024-11-16)
  → 'github:nix-community/fenix/7d9ba794daf5e8cc7ee728859bc688d8e26d5f06' (2025-03-20)
• Updated input 'fenix/rust-analyzer-src':
    'github:rust-lang/rust-analyzer/1b90e979aeee8d1db7fe14603a00834052505497' (2024-11-15)
  → 'github:rust-lang/rust-analyzer/15d87419f1a123d8f888d608129c3ce3ff8f13d4' (2025-03-18)
• Updated input 'flake-compat':
    'github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33' (2023-10-04)
  → 'github:edolstra/flake-compat/ff81ac966bb2cae68946d5ed5fc4994f96d0ffec' (2024-12-04)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/5e4fbfb6b3de1aa2872b76d49fafc942626e2add' (2024-11-15)
  → 'github:NixOS/nixpkgs/698214a32beb4f4c8e3942372c694f40848b360d' (2025-03-25)
2025-03-27 22:37:39 +03:00

128 lines
3.2 KiB
Nix

# Dependencies (keep sorted)
{ craneLib
, inputs
, jq
, lib
, pkgsBuildHost
, rocksdb
, rust
, rust-jemalloc-sys
, snappy
, stdenv
# Options (keep sorted)
, default-features ? true
, all-features ? false
, features ? []
, profile ? "release"
, version-extra ? inputs.self.shortRev
or inputs.self.dirtyShortRev
or null,
}:
let
# We perform default-feature unification in nix, because some of the dependencies
# on the nix side depend on feature values.
cargoManifest = lib.importTOML "${inputs.self}/Cargo.toml";
allDefaultFeatures = cargoManifest.features.default;
allFeatures = lib.unique (
lib.remove "default" (lib.attrNames cargoManifest.features) ++
lib.attrNames
(lib.filterAttrs (_: dependency: dependency.optional or false)
cargoManifest.dependencies));
features' = lib.unique
(features ++
lib.optionals default-features allDefaultFeatures ++
lib.optionals all-features allFeatures);
featureEnabled = feature : builtins.elem feature features';
buildDepsOnlyEnv =
let
rocksdb' = rocksdb.override {
enableJemalloc = featureEnabled "jemalloc";
};
in
{
NIX_OUTPATH_USED_AS_RANDOM_SEED = "randomseed";
CARGO_PROFILE = profile;
ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include";
ROCKSDB_LIB_DIR = "${rocksdb'}/lib";
}
//
(import ./cross-compilation-env.nix {
# Keep sorted
inherit
lib
pkgsBuildHost
rust
snappy
stdenv;
});
buildPackageEnv =
(lib.optionalAttrs (version-extra != null) {
GRAPEVINE_VERSION_EXTRA = version-extra;
})
// buildDepsOnlyEnv;
commonAttrs = {
# Reading from cargoManifest directly instead of using
# createNameFromCargoToml to avoid IFD
pname = cargoManifest.package.name;
version = cargoManifest.package.version;
src = let filter = inputs.nix-filter.lib; in filter {
root = inputs.self;
# Keep sorted
include = [
"Cargo.lock"
"Cargo.toml"
"src"
];
};
dontStrip = profile != "release";
buildInputs = lib.optional (featureEnabled "jemalloc") rust-jemalloc-sys;
nativeBuildInputs = [
# bindgen needs the build platform's libclang. Apparently due to "splicing
# weirdness", pkgs.rustPlatform.bindgenHook on its own doesn't quite do the
# right thing here.
pkgsBuildHost.rustPlatform.bindgenHook
# We don't actually depend on `jq`, but crane's `buildPackage` does, but
# its `buildDepsOnly` doesn't. This causes those two derivations to have
# differing values for `NIX_CFLAGS_COMPILE`, which contributes to spurious
# rebuilds of bindgen and its depedents.
jq
];
# Opt out of crane's automagic cross support
doIncludeCrossToolchainEnv = false;
};
in
craneLib.buildPackage (commonAttrs // {
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // {
env = buildDepsOnlyEnv;
});
cargoExtraArgs = "--locked --no-default-features "
+ lib.optionalString
(features' != [])
"--features " + (builtins.concatStringsSep "," features');
# This is redundant with CI
doCheck = false;
env = buildPackageEnv;
passthru = {
env = buildPackageEnv;
};
meta.mainProgram = commonAttrs.pname;
})