pub struct SandboxSpec {
host_workdir: PathBuf,
command: Vec<String>,
sandbox_workdir: PathBuf,
scratches: Vec<PathBuf>,
additional_files: Vec<AdditionalFile>,
env_vars: Vec<EnvVar>,
with_inputs: InputsProvider,
provide_shell: Option<PathBuf>,
allow_network: bool,
}Expand description
A sandbox builder.
Its API is tailored to the needs of Snix builds, namely running sandboxed commands with optional build input paths, files, network access. And allow for such commands to produce outputs that stay available after the sandbox has stopped.
Fields§
§host_workdir: PathBufWorking directory on the host, where the sandbox is assembled.
command: Vec<String>Command to execute inside the sandbox
sandbox_workdir: PathBufWorkdir inside the sandbox, in which the Self::command will be executed.
scratches: Vec<PathBuf>A list of scratch paths to make available inside the sandbox.
These directories are read+writable inside the sandbox and their contents is preserved after the sandbox has stopped.
additional_files: Vec<AdditionalFile>Any additional files to rw-mount inside the sandbox.
env_vars: Vec<EnvVar>Env vars to set before running Self::command.
with_inputs: InputsProviderOptionally read-only mount build inputs.
§Example
Mount some host path at “/nix/store” inside the sandbox.
use snix_build::sandbox::SandboxSpec;
let _ = SandboxSpec::builder()
.host_workdir("/tmp/sandbox1")
.command(["echo", "Hello"])
.sandbox_workdir("build")
.scratches(["foo"])
.with_inputs("nix/store", |path| {
// mount dir at `path`
// return an RAII guard that will unmount the dir
Ok(())
})
.build();provide_shell: Option<PathBuf>Absolute path to the shell that will be mounted at /bin/sh inside the sandbox.
It must static binary, otherwise it will likely fail to start.
allow_network: boolWhether to allow network access inside the sandbox.
Implementations§
Source§impl SandboxSpec
impl SandboxSpec
Sourcepub fn builder() -> SandboxSpecBuilder<((), (), (), (), (), (), (), (), ())>
pub fn builder() -> SandboxSpecBuilder<((), (), (), (), (), (), (), (), ())>
Create a builder for building SandboxSpec.
On the builder, call .host_workdir(...), .command(...), .sandbox_workdir(...), .scratches(...), .additional_files(...)(optional), .env_vars(...)(optional), .with_inputs(...)(optional), .provide_shell(...)(optional), .allow_network(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of SandboxSpec.
Source§impl SandboxSpec
impl SandboxSpec
pub fn host_workdir(&self) -> &Path
pub fn command(&self) -> impl IntoIterator<Item = &String>
pub fn sandbox_workdir(&self) -> &Path
pub fn scratches(&self) -> impl IntoIterator<Item = &PathBuf>
pub fn additional_files(&self) -> impl IntoIterator<Item = &AdditionalFile>
pub fn env_vars(&self) -> impl IntoIterator<Item = &EnvVar>
pub fn provide_shell(&self) -> Option<&Path>
pub fn allow_network(&self) -> bool
pub fn inputs_provider(&self) -> &InputsProvider
Trait Implementations§
Source§impl From<SandboxSpec> for InputsProvider
impl From<SandboxSpec> for InputsProvider
Source§fn from(value: SandboxSpec) -> Self
fn from(value: SandboxSpec) -> Self
Auto Trait Implementations§
impl Freeze for SandboxSpec
impl !RefUnwindSafe for SandboxSpec
impl Send for SandboxSpec
impl !Sync for SandboxSpec
impl Unpin for SandboxSpec
impl !UnwindSafe for SandboxSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request