about summary refs log tree commit diff
path: root/tvix/eval
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2022-10-08T18·22-0400
committerclbot <clbot@tvl.fyi>2022-10-08T19·16+0000
commit1e852098091dcaaaf3b9750c6dff5e465403f8c3 (patch)
treed0c713351b4110d097e9c7bf3128e016ecc0f818 /tvix/eval
parent207f3dd47e90c1ccc80b4775c1b2d13e5bfc6a72 (diff)
feat(tvix/eval): Handle invoking binary with a directory r/5070
Similar to what we do for import, push on a `default.nix` to the path
that the top-level is invoked with (if any) if it's a directory.

Change-Id: I281bd44e3c8803b6765c886ae5fd08f549e2e563
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6895
Autosubmit: grfn <grfn@gws.fyi>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval')
-rw-r--r--tvix/eval/src/main.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/tvix/eval/src/main.rs b/tvix/eval/src/main.rs
index efd4d14c3b1a..0fbc7ad9a620 100644
--- a/tvix/eval/src/main.rs
+++ b/tvix/eval/src/main.rs
@@ -1,7 +1,4 @@
-use std::{
-    fs,
-    path::{Path, PathBuf},
-};
+use std::{fs, path::PathBuf};
 
 use clap::Parser;
 use rustyline::{error::ReadlineError, Editor};
@@ -18,17 +15,18 @@ struct Args {
 fn main() {
     let args = Args::parse();
 
-    if let Some(file) = &args.script {
+    if let Some(file) = args.script {
         run_file(file, args.eval_options)
     } else {
         run_prompt(args.eval_options)
     }
 }
 
-fn run_file(file: &Path, eval_options: tvix_eval::Options) {
-    let contents = fs::read_to_string(file).expect("failed to read the input file");
-    let path = Path::new(file).to_owned();
-
+fn run_file(mut path: PathBuf, eval_options: tvix_eval::Options) {
+    if path.is_dir() {
+        path.push("default.nix");
+    }
+    let contents = fs::read_to_string(&path).expect("failed to read the input file");
     match tvix_eval::interpret(&contents, Some(path), eval_options) {
         Ok(result) => println!("=> {} :: {}", result, result.type_of()),
         Err(err) => eprintln!("{}", err),