feat(tvix/utils): Add defaultCrateOverridesForPkgs function

This function can be reused across the rest of the repo to make use of
our overriden defaultCrateOverrides with support for tvix crates.

Change-Id: I8c554dece052bd9dd32acac13dab8114933272a7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11951
Autosubmit: Ilan Joselevich <personal@ilanjoselevich.com>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Ilan Joselevich 2024-07-04 22:02:35 +03:00
parent 63654fbeb1
commit 6a7069904e
2 changed files with 78 additions and 78 deletions

View file

@ -2,86 +2,9 @@
{ pkgs, lib, depot, ... }: { pkgs, lib, depot, ... }:
let let
# crate override for crates that need protobuf
protobufDep = prev: (prev.nativeBuildInputs or [ ]) ++ [ pkgs.buildPackages.protobuf ];
# On Darwin, some crates producing binaries need to be able to link against security.
darwinDeps = lib.optionals pkgs.stdenv.isDarwin (with pkgs.buildPackages.darwin.apple_sdk.frameworks; [
Security
SystemConfiguration
]);
# Load the crate2nix crate tree. # Load the crate2nix crate tree.
crates = pkgs.callPackage ./Cargo.nix { crates = pkgs.callPackage ./Cargo.nix {
defaultCrateOverrides = pkgs.defaultCrateOverrides // { defaultCrateOverrides = depot.tvix.utils.defaultCrateOverridesForPkgs pkgs;
nix-compat = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = (root + "/testdata");
};
};
tvix-build = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = (lib.fileset.fileFilter (f: f.hasExt "proto") root);
};
PROTO_ROOT = depot.tvix.build.protos.protos;
nativeBuildInputs = protobufDep prev;
buildInputs = darwinDeps;
};
tvix-castore = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = (lib.fileset.fileFilter (f: f.hasExt "proto") root);
};
PROTO_ROOT = depot.tvix.castore.protos.protos;
nativeBuildInputs = protobufDep prev;
};
tvix-cli = prev: {
src = depot.tvix.utils.filterRustCrateSrc { root = prev.src.origSrc; };
buildInputs = prev.buildInputs or [ ] ++ darwinDeps;
};
tvix-store = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = (lib.fileset.fileFilter (f: f.hasExt "proto") root);
};
PROTO_ROOT = depot.tvix.store.protos.protos;
nativeBuildInputs = protobufDep prev;
# fuse-backend-rs uses DiskArbitration framework to handle mount/unmount on Darwin
buildInputs = prev.buildInputs or [ ]
++ darwinDeps
++ lib.optional pkgs.stdenv.isDarwin pkgs.buildPackages.darwin.apple_sdk.frameworks.DiskArbitration;
};
tvix-eval-builtin-macros = prev: {
src = depot.tvix.utils.filterRustCrateSrc { root = prev.src.origSrc; };
};
tvix-eval = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = (root + "/proptest-regressions");
};
};
tvix-glue = prev: {
src = depot.tvix.utils.filterRustCrateSrc {
root = prev.src.origSrc;
};
};
tvix-serde = prev: {
src = depot.tvix.utils.filterRustCrateSrc { root = prev.src.origSrc; };
};
tvix-tracing = prev: {
src = depot.tvix.utils.filterRustCrateSrc { root = prev.src.origSrc; };
};
};
}; };
# Cargo dependencies to be used with nixpkgs rustPlatform functions. # Cargo dependencies to be used with nixpkgs rustPlatform functions.

View file

@ -41,4 +41,81 @@
(lib.fileset.maybeMissing (root + "/Cargo.lock")) (lib.fileset.maybeMissing (root + "/Cargo.lock"))
] ++ lib.optional (extraFileset != null) extraFileset)); ] ++ lib.optional (extraFileset != null) extraFileset));
}; };
# A function which takes a pkgs instance and returns an overriden defaultCrateOverrides with support for tvix crates.
# This can be used throughout the rest of the repo.
defaultCrateOverridesForPkgs = pkgs:
let
commonDarwinDeps = with pkgs.darwin.apple_sdk.frameworks; [
Security
SystemConfiguration
];
in
pkgs.defaultCrateOverrides // {
nix-compat = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = root + "/testdata";
};
};
tvix-build = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = lib.fileset.fileFilter (f: f.hasExt "proto") root;
};
PROTO_ROOT = depot.tvix.build.protos.protos;
nativeBuildInputs = [ pkgs.protobuf ];
buildInputs = lib.optional pkgs.stdenv.isDarwin commonDarwinDeps;
};
tvix-castore = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = lib.fileset.fileFilter (f: f.hasExt "proto") root;
};
PROTO_ROOT = depot.tvix.castore.protos.protos;
nativeBuildInputs = [ pkgs.protobuf ];
};
tvix-cli = prev: {
src = depot.tvix.utils.filterRustCrateSrc { root = prev.src.origSrc; };
buildInputs = lib.optional pkgs.stdenv.isDarwin commonDarwinDeps;
};
tvix-store = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = lib.fileset.fileFilter (f: f.hasExt "proto") root;
};
PROTO_ROOT = depot.tvix.store.protos.protos;
nativeBuildInputs = [ pkgs.protobuf ];
# fuse-backend-rs uses DiskArbitration framework to handle mount/unmount on Darwin
buildInputs = lib.optional pkgs.stdenv.isDarwin (commonDarwinDeps ++ pkgs.darwin.apple_sdk.frameworks.DiskArbitration);
};
tvix-eval-builtin-macros = prev: {
src = depot.tvix.utils.filterRustCrateSrc { root = prev.src.origSrc; };
};
tvix-eval = prev: {
src = depot.tvix.utils.filterRustCrateSrc rec {
root = prev.src.origSrc;
extraFileset = root + "/proptest-regressions";
};
};
tvix-glue = prev: {
src = depot.tvix.utils.filterRustCrateSrc {
root = prev.src.origSrc;
};
};
tvix-serde = prev: {
src = depot.tvix.utils.filterRustCrateSrc { root = prev.src.origSrc; };
};
tvix-tracing = prev: {
src = depot.tvix.utils.filterRustCrateSrc { root = prev.src.origSrc; };
};
};
} }