refactor(tvix): introduce nix-compat crate

Move nixbase32 and store_path into this.

This allows //tvix/cli to not pull in //tvix/store for now.

Change-Id: Id3a32867205d95794bc0d33b21d4cb3d9bafd02a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7964
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
Florian Klink 2023-01-31 12:18:03 +01:00 committed by flokli
parent 8ea93bb646
commit c27bacd905
20 changed files with 109 additions and 27 deletions

16
tvix/Cargo.lock generated
View file

@ -1301,6 +1301,18 @@ dependencies = [
"tempfile",
]
[[package]]
name = "nix-compat"
version = "0.1.0"
dependencies = [
"anyhow",
"data-encoding",
"glob",
"sha2 0.10.6",
"test-case",
"thiserror",
]
[[package]]
name = "nom8"
version = "0.2.0"
@ -2617,7 +2629,6 @@ dependencies = [
"thiserror",
"tvix-derivation",
"tvix-eval",
"tvix-store-bin",
]
[[package]]
@ -2627,13 +2638,13 @@ dependencies = [
"anyhow",
"data-encoding",
"glob",
"nix-compat",
"serde",
"serde_json",
"sha2 0.10.6",
"test-case",
"test-generator",
"thiserror",
"tvix-store-bin",
]
[[package]]
@ -2699,6 +2710,7 @@ dependencies = [
"data-encoding",
"fastcdc",
"lazy_static",
"nix-compat",
"prost",
"prost-build",
"sled",

View file

@ -43,6 +43,16 @@ rec {
# File a bug if you depend on any for non-debug work!
debug = internal.debugCrate { inherit packageId; };
};
"nix-compat" = rec {
packageId = "nix-compat";
build = internal.buildRustCrateWithFeatures {
packageId = "nix-compat";
};
# Debug support which might change between releases.
# File a bug if you depend on any for non-debug work!
debug = internal.debugCrate { inherit packageId; };
};
"tvix-cli" = rec {
packageId = "tvix-cli";
build = internal.buildRustCrateWithFeatures {
@ -3725,6 +3735,46 @@ rec {
features = { };
resolvedDefaultFeatures = [ "integration_tests" ];
};
"nix-compat" = rec {
crateName = "nix-compat";
version = "0.1.0";
edition = "2021";
# We can't filter paths with references in Nix 2.4
# See https://github.com/NixOS/nix/issues/5410
src =
if (lib.versionOlder builtins.nixVersion "2.4pre20211007")
then lib.cleanSourceWith { filter = sourceFilter; src = ./nix-compat; }
else ./nix-compat;
dependencies = [
{
name = "anyhow";
packageId = "anyhow";
}
{
name = "data-encoding";
packageId = "data-encoding";
}
{
name = "glob";
packageId = "glob";
}
{
name = "sha2";
packageId = "sha2 0.10.6";
}
{
name = "thiserror";
packageId = "thiserror";
}
];
devDependencies = [
{
name = "test-case";
packageId = "test-case";
}
];
};
"nom8" = rec {
crateName = "nom8";
version = "0.2.0";
@ -7745,10 +7795,6 @@ rec {
name = "tvix-eval";
packageId = "tvix-eval";
}
{
name = "tvix-store-bin";
packageId = "tvix-store-bin";
}
];
};
@ -7775,6 +7821,10 @@ rec {
name = "glob";
packageId = "glob";
}
{
name = "nix-compat";
packageId = "nix-compat";
}
{
name = "serde";
packageId = "serde";
@ -7788,10 +7838,6 @@ rec {
name = "thiserror";
packageId = "thiserror";
}
{
name = "tvix-store-bin";
packageId = "tvix-store-bin";
}
];
devDependencies = [
{
@ -8060,6 +8106,10 @@ rec {
name = "lazy_static";
packageId = "lazy_static";
}
{
name = "nix-compat";
packageId = "nix-compat";
}
{
name = "prost";
packageId = "prost";

View file

@ -24,6 +24,7 @@ members = [
"eval/builtin-macros",
"nar",
"nix_cli",
"nix-compat",
"serde",
"store",
]

View file

@ -12,7 +12,6 @@ tvix-eval = { path = "../eval" }
tvix-derivation = { path = "../derivation" }
rustyline = "10.0.0"
clap = { version = "4.0", features = ["derive", "env"] }
tvix-store-bin = { path = "../store" }
dirs = "4.0.0"
smol_str = "0.1"
aho-corasick = "0.7"

View file

@ -9,10 +9,10 @@ edition = "2021"
anyhow = "1.0.68"
data-encoding = "2.3.3"
glob = "0.3.0"
nix-compat = { path = "../nix-compat" }
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10.6"
thiserror = "1.0.38"
tvix-store-bin = { path = "../store" }
[dev-dependencies.test-generator]
# This fork of test-generator adds support for cargo workspaces, see

View file

@ -1,12 +1,12 @@
use crate::output::{Hash, Output};
use crate::write;
use crate::DerivationError;
use nix_compat::nixbase32;
use nix_compat::store_path::{StorePath, STORE_DIR};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::collections::BTreeSet;
use std::{collections::BTreeMap, fmt, fmt::Write};
use tvix_store::nixbase32;
use tvix_store::store_path::{StorePath, STORE_DIR};
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct Derivation {

View file

@ -1,5 +1,5 @@
use nix_compat::{nixbase32::Nixbase32DecodeError, store_path::ParseStorePathError};
use thiserror::Error;
use tvix_store::{nixbase32::Nixbase32DecodeError, store_path::ParseStorePathError};
/// Errors that can occur during the validation of Derivation structs.
#[derive(Debug, Error, PartialEq)]

View file

@ -1,5 +1,5 @@
use nix_compat::{nixbase32, store_path::StorePath};
use serde::{Deserialize, Serialize};
use tvix_store::{nixbase32, store_path::StorePath};
use crate::OutputError;

View file

@ -1,12 +1,12 @@
use crate::derivation::Derivation;
use crate::output::{Hash, Output};
use nix_compat::store_path::StorePath;
use std::collections::BTreeSet;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use test_case::test_case;
use test_generator::test_resources;
use tvix_store::store_path::StorePath;
const RESOURCES_PATHS: &str = "src/tests/derivation_tests";

View file

@ -1,5 +1,5 @@
use crate::{derivation::Derivation, DerivationError};
use tvix_store::store_path::StorePath;
use nix_compat::store_path::StorePath;
impl Derivation {
/// validate ensures a Derivation struct is properly populated,

View file

@ -0,0 +1,16 @@
[package]
name = "nix-compat"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.68"
data-encoding = "2.3.3"
glob = "0.3.0"
sha2 = "0.10.6"
thiserror = "1.0.38"
[dev-dependencies]
test-case = "2.2.2"

View file

@ -0,0 +1,5 @@
{ depot, ... }:
depot.tvix.crates.workspaceMembers.nix-compat.build.override {
runTests = true;
}

View file

@ -0,0 +1,2 @@
pub mod nixbase32;
pub mod store_path;

View file

@ -14,9 +14,10 @@ lazy_static = "1.4.0"
clap = { version = "4.0", features = ["derive", "env"] }
prost = "0.11.2"
sled = { version = "0.34.7", features = ["compression"] }
nix-compat = { path = "../nix-compat" }
thiserror = "1.0.38"
tokio = { version = "1.23.0", features = ["rt-multi-thread"] }
tokio-stream = "0.1.11"
tokio = { version = "1.23.0", features = ["rt-multi-thread"] }
tonic = "0.8.2"
tracing-subscriber = "0.3.16"
tracing = "0.1.37"

View file

@ -1,6 +1,4 @@
pub mod nixbase32;
pub mod proto;
pub mod store_path;
pub mod dummy_blob_service;
pub mod sled_directory_service;

View file

@ -5,7 +5,7 @@ use thiserror::Error;
use prost::Message;
use crate::store_path::{ParseStorePathError, StorePath};
use nix_compat::store_path::{ParseStorePathError, StorePath};
tonic::include_proto!("tvix.store.v1");

View file

@ -7,7 +7,7 @@ use crate::proto::CalculateNarResponse;
use crate::proto::GetPathInfoRequest;
use crate::proto::Node;
use crate::proto::PathInfo;
use crate::store_path::DIGEST_SIZE;
use nix_compat::store_path::DIGEST_SIZE;
use tonic::{Request, Response, Result, Status};
use tracing::{instrument, warn};

View file

@ -1,8 +1,6 @@
use crate::{
proto::{self, Node, PathInfo, ValidatePathInfoError},
store_path::{ParseStorePathError, StorePath},
};
use crate::proto::{self, Node, PathInfo, ValidatePathInfoError};
use lazy_static::lazy_static;
use nix_compat::store_path::{ParseStorePathError, StorePath};
use test_case::test_case;
lazy_static! {