diff options
author | sterni <sternenseemann@systemli.org> | 2022-10-15T14·42+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-10-16T19·11+0000 |
commit | 4dcb8f38c2e442b6433b21b8a7de303736a04568 (patch) | |
tree | b47d780f78d6522926e7842013e436aee0b44222 /tvix/eval/src/vm.rs | |
parent | 0624d78af0839cd8b290eb9cb6e5737f01162b96 (diff) |
fix(tvix/eval): resolve home relative paths at runtime r/5147
Home relative paths depend on the environment to be resolved. We have elected to do everything that depends on the environment, e.g. resolving SPATH expressions using NIX_PATH, at runtime, so tvix evaluation would continue to behave correctly even if we separated the compilation and execution phases more, e.g. via serializing bytecode. Then the value of HOME, NIX_PATH etc. could reasonably change in the time until execution, yielding wrong results if the resolution results were cached in the bytecode. We also take the opportunity to fix the broken path concatenation previously found in the compiler, fixing b/205. Another thing we could consider is emitting a warning for home relative path literals, as they are by nature relatively fragile. One sideeffect of this change is that home path resolution errors become catchable which is not the case in C++ Nix. This will need to be fixed up in a subsequent change. Change-Id: I30bd69b575667c49170a9fdea23a020565d0f9ec Reviewed-on: https://cl.tvl.fyi/c/depot/+/7024 Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: Adam Joseph <adam@westernsemico.com> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r-- | tvix/eval/src/vm.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 05adec5f6ea6..7fcdb9ea739b 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -536,6 +536,26 @@ impl<'o> VM<'o> { _ => panic!("tvix compiler bug: OpFindFile called on non-UnresolvedPath"), }, + OpCode::OpResolveHomePath => match self.pop() { + Value::UnresolvedPath(path) => { + match dirs::home_dir() { + None => { + return Err(self.error(ErrorKind::PathResolution( + "failed to determine home directory".into(), + ))); + } + Some(mut buf) => { + buf.push(path); + self.push(buf.into()); + } + }; + } + + _ => { + panic!("tvix compiler bug: OpResolveHomePath called on non-UnresolvedPath") + } + }, + OpCode::OpJump(JumpOffset(offset)) => { debug_assert!(offset != 0); self.frame_mut().ip += offset; |