diff options
author | Florian Klink <flokli@flokli.de> | 2023-09-23T09·38+0300 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-09-23T12·54+0000 |
commit | e5f22818566b4cc49ce9b089c59921f5a054c48c (patch) | |
tree | 1d88d762cb693a8251596a242557c1f8cf020c25 /tvix/cli/src/derivation.rs | |
parent | dfb3d30d4545015e0cb2c4e7e1e7d43050945262 (diff) |
feat(tvix/cli/derivation): reject derivations with empty names r/6641
As shown in the previous CLs, we can very well have store paths starting with periods, but we can't have derivations with an empty name: ``` nix-build -E 'derivation { name = ""; builder = "/bin/sh"; system = "x86_64-linux"; }' error: store path 'nr7i5pf18hw2zg487vkdyrbasdqylfcj-' has an empty name ``` I'm currently using ErrorKind::Abort here, because we don't have a Derivation- related error in tvix-eval (and probably don't want to). Change-Id: I0e9743cee98dbfa69e9caa2a58352176270f15bd Reviewed-on: https://cl.tvl.fyi/c/depot/+/9448 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/cli/src/derivation.rs')
-rw-r--r-- | tvix/cli/src/derivation.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tvix/cli/src/derivation.rs b/tvix/cli/src/derivation.rs index e2184c4a676a..de6d58a13db2 100644 --- a/tvix/cli/src/derivation.rs +++ b/tvix/cli/src/derivation.rs @@ -229,6 +229,10 @@ mod derivation_builtins { .to_str() .context("determining derivation name")?; + if name.is_empty() { + return Err(ErrorKind::Abort("derivation has empty name".to_string())); + } + // Check whether attributes should be passed as a JSON file. // TODO: the JSON serialisation has to happen here. if let Some(sa) = input.select(STRUCTURED_ATTRS) { @@ -461,6 +465,29 @@ mod tests { ); } + #[test] + fn derivation_empty_name() { + let mut eval = tvix_eval::Evaluation::new_impure( + r#"(derivation { name = ""; builder = "/bin/sh"; system = "x86_64-linux";}).outPath"#, + None, + ); + + let known_paths: Rc<RefCell<KnownPaths>> = Default::default(); + + eval.builtins + .extend(crate::derivation::derivation_builtins(known_paths)); + + // Add the actual `builtins.derivation` from compiled Nix code + // TODO: properly compose this + eval.src_builtins + .push(("derivation", include_str!("derivation.nix"))); + + assert!( + !eval.evaluate().errors.is_empty(), + "expect evaluation to fail" + ); + } + // TODO: These tests are commented out because we do not have // scaffolding to drive generators during testing at the moment. |