1use snix_eval::{EvalIO, FileType};
10use std::io::{self, Cursor};
11use std::path::{Path, PathBuf};
12
13pub struct SnixIO<T> {
15 actual: T,
17}
18
19impl<T> SnixIO<T> {
20 pub fn new(actual: T) -> Self {
21 Self { actual }
22 }
23}
24
25impl<T> EvalIO for SnixIO<T>
26where
27 T: AsRef<dyn EvalIO>,
28{
29 fn store_dir(&self) -> Option<String> {
30 self.actual.as_ref().store_dir()
31 }
32
33 fn import_path(&self, path: &Path) -> io::Result<PathBuf> {
34 self.actual.as_ref().import_path(path)
35 }
36
37 fn path_exists(&self, path: &Path) -> io::Result<bool> {
38 if path.starts_with("/__corepkgs__") {
39 return Ok(true);
40 }
41
42 self.actual.as_ref().path_exists(path)
43 }
44
45 fn open(&self, path: &Path) -> io::Result<Box<dyn io::Read>> {
46 if path.starts_with("/__corepkgs__/fetchurl.nix") {
55 return Ok(Box::new(Cursor::new(include_bytes!("fetchurl.nix"))));
56 }
57
58 self.actual.as_ref().open(path)
59 }
60
61 fn file_type(&self, path: &Path) -> io::Result<FileType> {
62 self.actual.as_ref().file_type(path)
63 }
64
65 fn read_dir(&self, path: &Path) -> io::Result<Vec<(bytes::Bytes, FileType)>> {
66 self.actual.as_ref().read_dir(path)
67 }
68}