refactor(tvix/nix-compat): absorb //tvix/derivation
Put this in its src/derivation. Change-Id: Ic047ab1c2da555a833ee454e10ef60c77537b617 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7967 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
parent
9e809e21cc
commit
2d24c5f260
34 changed files with 60 additions and 148 deletions
21
tvix/Cargo.lock
generated
21
tvix/Cargo.lock
generated
|
@ -1308,8 +1308,11 @@ dependencies = [
|
|||
"anyhow",
|
||||
"data-encoding",
|
||||
"glob",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2 0.10.6",
|
||||
"test-case",
|
||||
"test-generator",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
|
@ -2623,30 +2626,14 @@ dependencies = [
|
|||
"clap 4.0.32",
|
||||
"data-encoding",
|
||||
"dirs",
|
||||
"nix-compat",
|
||||
"rustyline",
|
||||
"smol_str",
|
||||
"ssri",
|
||||
"thiserror",
|
||||
"tvix-derivation",
|
||||
"tvix-eval",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tvix-derivation"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"data-encoding",
|
||||
"glob",
|
||||
"nix-compat",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2 0.10.6",
|
||||
"test-case",
|
||||
"test-generator",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tvix-eval"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -63,16 +63,6 @@ rec {
|
|||
# File a bug if you depend on any for non-debug work!
|
||||
debug = internal.debugCrate { inherit packageId; };
|
||||
};
|
||||
"tvix-derivation" = rec {
|
||||
packageId = "tvix-derivation";
|
||||
build = internal.buildRustCrateWithFeatures {
|
||||
packageId = "tvix-derivation";
|
||||
};
|
||||
|
||||
# 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-eval" = rec {
|
||||
packageId = "tvix-eval";
|
||||
build = internal.buildRustCrateWithFeatures {
|
||||
|
@ -3758,6 +3748,11 @@ rec {
|
|||
name = "glob";
|
||||
packageId = "glob";
|
||||
}
|
||||
{
|
||||
name = "serde";
|
||||
packageId = "serde";
|
||||
features = [ "derive" ];
|
||||
}
|
||||
{
|
||||
name = "sha2";
|
||||
packageId = "sha2 0.10.6";
|
||||
|
@ -3768,10 +3763,18 @@ rec {
|
|||
}
|
||||
];
|
||||
devDependencies = [
|
||||
{
|
||||
name = "serde_json";
|
||||
packageId = "serde_json";
|
||||
}
|
||||
{
|
||||
name = "test-case";
|
||||
packageId = "test-case";
|
||||
}
|
||||
{
|
||||
name = "test-generator";
|
||||
packageId = "test-generator";
|
||||
}
|
||||
];
|
||||
|
||||
};
|
||||
|
@ -7771,6 +7774,10 @@ rec {
|
|||
name = "dirs";
|
||||
packageId = "dirs";
|
||||
}
|
||||
{
|
||||
name = "nix-compat";
|
||||
packageId = "nix-compat";
|
||||
}
|
||||
{
|
||||
name = "rustyline";
|
||||
packageId = "rustyline";
|
||||
|
@ -7787,73 +7794,12 @@ rec {
|
|||
name = "thiserror";
|
||||
packageId = "thiserror";
|
||||
}
|
||||
{
|
||||
name = "tvix-derivation";
|
||||
packageId = "tvix-derivation";
|
||||
}
|
||||
{
|
||||
name = "tvix-eval";
|
||||
packageId = "tvix-eval";
|
||||
}
|
||||
];
|
||||
|
||||
};
|
||||
"tvix-derivation" = rec {
|
||||
crateName = "tvix-derivation";
|
||||
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 = ./derivation; }
|
||||
else ./derivation;
|
||||
dependencies = [
|
||||
{
|
||||
name = "anyhow";
|
||||
packageId = "anyhow";
|
||||
}
|
||||
{
|
||||
name = "data-encoding";
|
||||
packageId = "data-encoding";
|
||||
}
|
||||
{
|
||||
name = "glob";
|
||||
packageId = "glob";
|
||||
}
|
||||
{
|
||||
name = "nix-compat";
|
||||
packageId = "nix-compat";
|
||||
}
|
||||
{
|
||||
name = "serde";
|
||||
packageId = "serde";
|
||||
features = [ "derive" ];
|
||||
}
|
||||
{
|
||||
name = "sha2";
|
||||
packageId = "sha2 0.10.6";
|
||||
}
|
||||
{
|
||||
name = "thiserror";
|
||||
packageId = "thiserror";
|
||||
}
|
||||
];
|
||||
devDependencies = [
|
||||
{
|
||||
name = "serde_json";
|
||||
packageId = "serde_json";
|
||||
}
|
||||
{
|
||||
name = "test-case";
|
||||
packageId = "test-case";
|
||||
}
|
||||
{
|
||||
name = "test-generator";
|
||||
packageId = "test-generator";
|
||||
}
|
||||
];
|
||||
|
||||
};
|
||||
"tvix-eval" = rec {
|
||||
crateName = "tvix-eval";
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
members = [
|
||||
"cli",
|
||||
"derivation",
|
||||
"eval",
|
||||
"eval/builtin-macros",
|
||||
"nar",
|
||||
|
|
|
@ -8,8 +8,8 @@ name = "tvix"
|
|||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
nix-compat = { path = "../nix-compat" }
|
||||
tvix-eval = { path = "../eval" }
|
||||
tvix-derivation = { path = "../derivation" }
|
||||
rustyline = "10.0.0"
|
||||
clap = { version = "4.0", features = ["derive", "env"] }
|
||||
dirs = "4.0.0"
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! Implements `builtins.derivation`, the core of what makes Nix build packages.
|
||||
|
||||
use data_encoding::BASE64;
|
||||
use nix_compat::derivation::{Derivation, Hash};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{btree_map, BTreeSet};
|
||||
use std::rc::Rc;
|
||||
use tvix_derivation::{Derivation, Hash};
|
||||
use tvix_eval::builtin_macros::builtins;
|
||||
use tvix_eval::{AddContext, CoercionKind, ErrorKind, NixAttrs, NixList, Value, VM};
|
||||
|
||||
|
@ -416,9 +416,10 @@ mod derivation_builtins {
|
|||
|
||||
// TODO: fail on derivation references (only "plain" is allowed here)
|
||||
|
||||
let path = tvix_derivation::path_with_references(name.as_str(), content.as_str(), refs)
|
||||
.map_err(Error::InvalidDerivation)?
|
||||
.to_absolute_path();
|
||||
let path =
|
||||
nix_compat::derivation::path_with_references(name.as_str(), content.as_str(), refs)
|
||||
.map_err(Error::InvalidDerivation)?
|
||||
.to_absolute_path();
|
||||
|
||||
state.borrow_mut().plain(&path);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use nix_compat::derivation::DerivationError;
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use tvix_derivation::DerivationError;
|
||||
|
||||
/// Errors related to derivation construction
|
||||
#[derive(Debug, Error, PartialEq)]
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
[package]
|
||||
name = "tvix-derivation"
|
||||
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"
|
||||
nix-compat = { path = "../nix-compat" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
sha2 = "0.10.6"
|
||||
thiserror = "1.0.38"
|
||||
|
||||
[dev-dependencies.test-generator]
|
||||
# This fork of test-generator adds support for cargo workspaces, see
|
||||
# also https://github.com/frehberg/test-generator/pull/14
|
||||
git = "https://github.com/JamesGuthrie/test-generator.git"
|
||||
rev = "82e799979980962aec1aa324ec6e0e4cad781f41"
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0"
|
||||
test-case = "2.2.2"
|
|
@ -1,5 +0,0 @@
|
|||
{ depot, ... }:
|
||||
|
||||
depot.tvix.crates.workspaceMembers.tvix-derivation.build.override {
|
||||
runTests = true;
|
||||
}
|
|
@ -9,8 +9,16 @@ edition = "2021"
|
|||
anyhow = "1.0.68"
|
||||
data-encoding = "2.3.3"
|
||||
glob = "0.3.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
sha2 = "0.10.6"
|
||||
thiserror = "1.0.38"
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0"
|
||||
test-case = "2.2.2"
|
||||
|
||||
[dev-dependencies.test-generator]
|
||||
# This fork of test-generator adds support for cargo workspaces, see
|
||||
# also https://github.com/frehberg/test-generator/pull/14
|
||||
git = "https://github.com/JamesGuthrie/test-generator.git"
|
||||
rev = "82e799979980962aec1aa324ec6e0e4cad781f41"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::output::{Hash, Output};
|
||||
use crate::write;
|
||||
use crate::DerivationError;
|
||||
use nix_compat::nixbase32;
|
||||
use nix_compat::store_path::{StorePath, STORE_DIR};
|
||||
use crate::derivation::output::{Hash, Output};
|
||||
use crate::derivation::write;
|
||||
use crate::derivation::DerivationError;
|
||||
use crate::nixbase32;
|
||||
use crate::store_path::{StorePath, STORE_DIR};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::collections::BTreeSet;
|
|
@ -1,4 +1,4 @@
|
|||
use nix_compat::{nixbase32::Nixbase32DecodeError, store_path::ParseStorePathError};
|
||||
use crate::{nixbase32::Nixbase32DecodeError, store_path::ParseStorePathError};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Errors that can occur during the validation of Derivation structs.
|
|
@ -1,8 +1,7 @@
|
|||
use nix_compat::{nixbase32, store_path::StorePath};
|
||||
use crate::derivation::OutputError;
|
||||
use crate::{nixbase32, store_path::StorePath};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::OutputError;
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Output {
|
||||
pub path: String,
|
|
@ -1,6 +1,6 @@
|
|||
use crate::derivation::output::{Hash, Output};
|
||||
use crate::derivation::Derivation;
|
||||
use crate::output::{Hash, Output};
|
||||
use nix_compat::store_path::StorePath;
|
||||
use crate::store_path::StorePath;
|
||||
use std::collections::BTreeSet;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
@ -8,7 +8,7 @@ use std::path::Path;
|
|||
use test_case::test_case;
|
||||
use test_generator::test_resources;
|
||||
|
||||
const RESOURCES_PATHS: &str = "src/tests/derivation_tests";
|
||||
const RESOURCES_PATHS: &str = "src/derivation/tests/derivation_tests";
|
||||
|
||||
fn read_file(path: &str) -> String {
|
||||
let path = Path::new(path);
|
||||
|
@ -20,7 +20,7 @@ fn read_file(path: &str) -> String {
|
|||
return data;
|
||||
}
|
||||
|
||||
#[test_resources("src/tests/derivation_tests/*.drv")]
|
||||
#[test_resources("src/derivation/tests/derivation_tests/*.drv")]
|
||||
fn check_serizaliation(path_to_drv_file: &str) {
|
||||
let data = read_file(&format!("{}.json", path_to_drv_file));
|
||||
let derivation: Derivation = serde_json::from_str(&data).expect("JSON was not well-formatted");
|
||||
|
@ -33,7 +33,7 @@ fn check_serizaliation(path_to_drv_file: &str) {
|
|||
assert_eq!(expected, serialized_derivation);
|
||||
}
|
||||
|
||||
#[test_resources("src/tests/derivation_tests/*.drv")]
|
||||
#[test_resources("src/derivation/tests/derivation_tests/*.drv")]
|
||||
fn validate(path_to_drv_file: &str) {
|
||||
let data = read_file(&format!("{}.json", path_to_drv_file));
|
||||
let derivation: Derivation = serde_json::from_str(&data).expect("JSON was not well-formatted");
|
||||
|
@ -43,7 +43,7 @@ fn validate(path_to_drv_file: &str) {
|
|||
.expect("derivation failed to validate")
|
||||
}
|
||||
|
||||
#[test_resources("src/tests/derivation_tests/*.drv")]
|
||||
#[test_resources("src/derivation/tests/derivation_tests/*.drv")]
|
||||
fn check_to_string(path_to_drv_file: &str) {
|
||||
let data = read_file(&format!("{}.json", path_to_drv_file));
|
||||
let derivation: Derivation = serde_json::from_str(&data).expect("JSON was not well-formatted");
|
||||
|
@ -313,7 +313,7 @@ fn path_with_zero_references() {
|
|||
// nix-repl> builtins.toFile "foo" "bar"
|
||||
// "/nix/store/vxjiwkjkn7x4079qvh1jkl5pn05j2aw0-foo"
|
||||
|
||||
let store_path = crate::path_with_references("foo", "bar", Vec::<String>::new())
|
||||
let store_path = crate::derivation::path_with_references("foo", "bar", Vec::<String>::new())
|
||||
.expect("path_with_references() should succeed");
|
||||
|
||||
assert_eq!(
|
||||
|
@ -329,12 +329,13 @@ fn path_with_non_zero_references() {
|
|||
// nix-repl> builtins.toFile "baz" "${builtins.toFile "foo" "bar"}"
|
||||
// "/nix/store/5xd714cbfnkz02h2vbsj4fm03x3f15nf-baz"
|
||||
|
||||
let inner = crate::path_with_references("foo", "bar", Vec::<String>::new())
|
||||
let inner = crate::derivation::path_with_references("foo", "bar", Vec::<String>::new())
|
||||
.expect("path_with_references() should succeed");
|
||||
let inner_path = inner.to_absolute_path();
|
||||
|
||||
let outer = crate::path_with_references("baz", &inner_path, vec![inner_path.as_str()])
|
||||
.expect("path_with_references() should succeed");
|
||||
let outer =
|
||||
crate::derivation::path_with_references("baz", &inner_path, vec![inner_path.as_str()])
|
||||
.expect("path_with_references() should succeed");
|
||||
|
||||
assert_eq!(
|
||||
outer.to_absolute_path().as_str(),
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{derivation::Derivation, DerivationError};
|
||||
use nix_compat::store_path::StorePath;
|
||||
use crate::derivation::{Derivation, DerivationError};
|
||||
use crate::store_path::StorePath;
|
||||
|
||||
impl Derivation {
|
||||
/// validate ensures a Derivation struct is properly populated,
|
|
@ -3,8 +3,8 @@
|
|||
//!
|
||||
//! [ATerm]: http://program-transformation.org/Tools/ATermFormat.html
|
||||
|
||||
use crate::output::Output;
|
||||
use crate::string_escape::escape_string;
|
||||
use crate::derivation::output::Output;
|
||||
use crate::derivation::string_escape::escape_string;
|
||||
use std::collections::BTreeSet;
|
||||
use std::{collections::BTreeMap, fmt, fmt::Write};
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
pub mod derivation;
|
||||
pub mod nixbase32;
|
||||
pub mod store_path;
|
||||
|
|
Loading…
Reference in a new issue