2022-12-06 14:47:02 +01:00
|
|
|
# Nix helpers for projects under //tvix
|
2023-08-19 16:46:36 +02:00
|
|
|
{ pkgs, lib, depot, ... }:
|
2022-12-06 14:47:02 +01:00
|
|
|
|
2023-01-06 18:20:44 +01:00
|
|
|
let
|
|
|
|
# crate override for crates that need protobuf
|
|
|
|
protobufDep = prev: (prev.nativeBuildInputs or [ ]) ++ [ pkgs.protobuf ];
|
2023-09-10 13:03:32 +02:00
|
|
|
iconvDarwinDep = lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv ];
|
2023-03-14 20:16:45 +01:00
|
|
|
|
2022-12-07 12:05:02 +01:00
|
|
|
# Load the crate2nix crate tree.
|
|
|
|
crates = import ./Cargo.nix {
|
|
|
|
inherit pkgs;
|
|
|
|
nixpkgs = pkgs.path;
|
2023-01-06 18:20:44 +01:00
|
|
|
|
2023-09-10 13:03:32 +02:00
|
|
|
# Hack to fix Darwin build
|
|
|
|
# See https://github.com/NixOS/nixpkgs/issues/218712
|
|
|
|
buildRustCrateForPkgs = pkgs:
|
|
|
|
if pkgs.stdenv.isDarwin then
|
|
|
|
let
|
|
|
|
buildRustCrate = pkgs.buildRustCrate;
|
|
|
|
buildRustCrate_ = args: buildRustCrate args // { dontStrip = true; };
|
|
|
|
override = o: args: buildRustCrate.override o (args // { dontStrip = true; });
|
|
|
|
in
|
|
|
|
pkgs.makeOverridable override { }
|
|
|
|
else pkgs.buildRustCrate;
|
|
|
|
|
2023-01-06 18:20:44 +01:00
|
|
|
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
|
2023-09-10 13:03:32 +02:00
|
|
|
zstd-sys = prev: {
|
|
|
|
nativeBuildInputs = prev.nativeBuildInputs or [ ] ++ iconvDarwinDep;
|
|
|
|
};
|
|
|
|
|
2023-01-06 18:20:44 +01:00
|
|
|
prost-build = prev: {
|
|
|
|
nativeBuildInputs = protobufDep prev;
|
|
|
|
};
|
|
|
|
|
|
|
|
tonic-reflection = prev: {
|
|
|
|
nativeBuildInputs = protobufDep prev;
|
|
|
|
};
|
|
|
|
|
2023-09-21 21:32:44 +02:00
|
|
|
tvix-castore = prev: {
|
|
|
|
PROTO_ROOT = depot.tvix.proto;
|
|
|
|
nativeBuildInputs = protobufDep prev;
|
|
|
|
};
|
|
|
|
|
2023-01-06 18:20:44 +01:00
|
|
|
tvix-store = prev: {
|
2023-09-21 21:32:44 +02:00
|
|
|
PROTO_ROOT = depot.tvix.proto;
|
2023-01-06 18:20:44 +01:00
|
|
|
nativeBuildInputs = protobufDep prev;
|
|
|
|
};
|
|
|
|
};
|
2022-12-07 12:05:02 +01:00
|
|
|
};
|
2022-12-08 14:55:47 +01:00
|
|
|
|
2023-08-19 16:46:36 +02:00
|
|
|
# Cargo dependencies to be used with nixpkgs rustPlatform functions.
|
|
|
|
cargoDeps = pkgs.rustPlatform.importCargoLock {
|
|
|
|
lockFile = ./Cargo.lock;
|
|
|
|
# Extract the hashes from `crates` / Cargo.nix, we already get them from cargo2nix.
|
|
|
|
# This returns an attribute set containing "${crateName}-${version}" as key,
|
|
|
|
# and the outputHash as value.
|
|
|
|
outputHashes = builtins.listToAttrs
|
|
|
|
(map
|
|
|
|
(crateName:
|
|
|
|
(lib.nameValuePair "${crateName}-${crates.internal.crates.${crateName}.version}" crates.internal.crates.${crateName}.src.outputHash)
|
|
|
|
) [
|
2023-09-16 17:20:34 +02:00
|
|
|
"fuse-backend-rs"
|
2023-08-19 16:46:36 +02:00
|
|
|
"test-generator"
|
|
|
|
"tonic-mock"
|
|
|
|
"wu-manber"
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit crates;
|
|
|
|
|
2022-12-22 15:44:32 +01:00
|
|
|
# Run crate2nix generate in the current working directory, then
|
|
|
|
# format the generated file with depotfmt.
|
|
|
|
crate2nixGenerate = pkgs.writeShellScriptBin "crate2nix-generate" ''
|
|
|
|
${pkgs.crate2nix}/bin/crate2nix generate
|
|
|
|
${depot.tools.depotfmt}/bin/depotfmt Cargo.nix
|
|
|
|
'';
|
|
|
|
|
2023-09-07 16:51:34 +02:00
|
|
|
# Provide the Tvix logo in both .webp and .png format.
|
|
|
|
logo = pkgs.runCommand "logo"
|
|
|
|
{
|
|
|
|
nativeBuildInputs = [ pkgs.imagemagick ];
|
|
|
|
} ''
|
|
|
|
mkdir -p $out
|
|
|
|
cp ${./logo.webp} $out/logo.webp
|
|
|
|
convert $out/logo.webp $out/logo.png
|
|
|
|
'';
|
|
|
|
|
2022-12-08 14:55:47 +01:00
|
|
|
# Provide a shell for the combined dependencies of all Tvix Rust
|
|
|
|
# projects. Note that as this is manually maintained it may be
|
|
|
|
# lacking something, but it is required for some people's workflows.
|
|
|
|
#
|
|
|
|
# This shell can be entered with e.g. `mg shell //tvix:shell`.
|
|
|
|
shell = pkgs.mkShell {
|
|
|
|
name = "tvix-rust-dev-env";
|
|
|
|
packages = [
|
|
|
|
pkgs.buf-language-server
|
|
|
|
pkgs.cargo
|
2023-09-22 11:23:51 +02:00
|
|
|
pkgs.cargo-machete
|
2022-12-08 14:55:47 +01:00
|
|
|
pkgs.clippy
|
2022-11-26 17:35:15 +01:00
|
|
|
pkgs.evans
|
2023-05-28 09:22:08 +02:00
|
|
|
pkgs.fuse
|
|
|
|
pkgs.pkg-config
|
2022-12-08 14:55:47 +01:00
|
|
|
pkgs.rust-analyzer
|
|
|
|
pkgs.rustc
|
|
|
|
pkgs.rustfmt
|
|
|
|
pkgs.protobuf
|
2023-09-10 13:03:32 +02:00
|
|
|
] ++ iconvDarwinDep;
|
2022-12-08 14:55:47 +01:00
|
|
|
};
|
|
|
|
|
2023-09-21 21:32:44 +02:00
|
|
|
# Builds and tests the code in castore/protos.
|
2023-09-22 15:22:52 +02:00
|
|
|
castore-protos-go = pkgs.buildGoModule {
|
|
|
|
name = "castore-golang";
|
|
|
|
src = depot.third_party.gitignoreSource ./store/protos;
|
|
|
|
vendorHash = "sha256-zRbMwhZvcDop8qDd0OrHeDJ+lVPKxwjKmlFbj8Ypy9g=";
|
|
|
|
};
|
2023-09-09 14:11:16 +02:00
|
|
|
|
2023-09-21 21:32:44 +02:00
|
|
|
# Builds and tests the code in store/protos.
|
2023-09-22 15:22:52 +02:00
|
|
|
store-protos-go = pkgs.buildGoModule {
|
|
|
|
name = "store-golang";
|
|
|
|
src = depot.third_party.gitignoreSource ./store/protos;
|
|
|
|
vendorHash = "sha256-zRbMwhZvcDop8qDd0OrHeDJ+lVPKxwjKmlFbj8Ypy9g=";
|
|
|
|
};
|
2023-09-09 14:11:16 +02:00
|
|
|
|
2023-08-19 16:57:14 +02:00
|
|
|
# Build the Rust documentation for publishing on docs.tvix.dev.
|
2023-03-14 20:16:45 +01:00
|
|
|
rust-docs = pkgs.stdenv.mkDerivation {
|
|
|
|
inherit cargoDeps;
|
|
|
|
name = "tvix-rust-docs";
|
|
|
|
src = depot.third_party.gitignoreSource ./.;
|
2023-09-21 21:32:44 +02:00
|
|
|
PROTO_ROOT = depot.tvix.proto;
|
2023-03-14 20:16:45 +01:00
|
|
|
|
2023-05-28 09:22:08 +02:00
|
|
|
buildInputs = [
|
|
|
|
pkgs.fuse
|
|
|
|
];
|
2023-03-14 20:16:45 +01:00
|
|
|
nativeBuildInputs = with pkgs; [
|
|
|
|
cargo
|
2023-05-28 09:22:08 +02:00
|
|
|
pkg-config
|
|
|
|
protobuf
|
2023-03-14 20:16:45 +01:00
|
|
|
rustc
|
2023-05-28 09:22:08 +02:00
|
|
|
rustPlatform.cargoSetupHook
|
2023-09-10 13:03:32 +02:00
|
|
|
] ++ iconvDarwinDep;
|
2023-03-14 20:16:45 +01:00
|
|
|
|
|
|
|
buildPhase = ''
|
2023-03-14 22:20:27 +01:00
|
|
|
cargo doc --document-private-items
|
2023-03-14 20:16:45 +01:00
|
|
|
mv target/doc $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-09-21 21:32:44 +02:00
|
|
|
meta.ci.targets = [
|
2023-09-22 15:22:52 +02:00
|
|
|
"castore-protos-go"
|
|
|
|
"store-protos-go"
|
2023-09-21 21:32:44 +02:00
|
|
|
"shell"
|
|
|
|
"rust-docs"
|
|
|
|
];
|
2022-12-06 14:47:02 +01:00
|
|
|
}
|