microsandbox_utils/
defaults.rs

1//! Default values and constants used throughout the microsandbox project.
2//!
3//! This module provides default configuration values, paths, and other constants
4//! that are used by various components of the microsandbox system.
5//!
6//! # Examples
7//!
8//! ```
9//! use microsandbox_utils::defaults::{DEFAULT_NUM_VCPUS, DEFAULT_MEMORY_MIB};
10//!
11//! // Use default values for VM configuration
12//! let vcpus = DEFAULT_NUM_VCPUS;
13//! let memory = DEFAULT_MEMORY_MIB;
14//! ```
15
16use std::{fs, path::PathBuf, sync::LazyLock};
17
18use crate::MICROSANDBOX_HOME_DIR;
19
20//--------------------------------------------------------------------------------------------------
21// Constants
22//--------------------------------------------------------------------------------------------------
23
24/// The default maximum log file size (10MB)
25pub const DEFAULT_LOG_MAX_SIZE: u64 = 10 * 1024 * 1024;
26
27/// The default number of vCPUs to use for the MicroVm.
28pub const DEFAULT_NUM_VCPUS: u8 = 1;
29
30/// The default amount of memory in MiB to use for the MicroVm.
31pub const DEFAULT_MEMORY_MIB: u32 = 1024;
32
33/// The path where all microsandbox global data is stored.
34pub static DEFAULT_MICROSANDBOX_HOME: LazyLock<PathBuf> =
35    LazyLock::new(|| dirs::home_dir().unwrap().join(MICROSANDBOX_HOME_DIR));
36
37/// The default OCI registry domain.
38pub const DEFAULT_OCI_REGISTRY: &str = "docker.io";
39
40/// The default OCI reference tag.
41pub const DEFAULT_OCI_REFERENCE_TAG: &str = "latest";
42
43/// The default OCI reference repository namespace.
44pub const DEFAULT_OCI_REFERENCE_REPO_NAMESPACE: &str = "library";
45
46/// The default configuration file content
47pub const DEFAULT_CONFIG: &str = "# Sandbox configurations\nsandboxes:\n";
48
49/// The default shell to use for the sandbox.
50pub const DEFAULT_SHELL: &str = "/bin/sh";
51
52/// The default path to the msbrun binary.
53pub static DEFAULT_MSBRUN_EXE_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
54    let current_exe = std::env::current_exe().unwrap();
55    let actual_exe = fs::canonicalize(current_exe).unwrap();
56    actual_exe.parent().unwrap().join("msbrun")
57});
58
59/// The default path to the msbserver binary.
60pub static DEFAULT_MSBSERVER_EXE_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
61    let current_exe = std::env::current_exe().unwrap();
62    let actual_exe = fs::canonicalize(current_exe).unwrap();
63    actual_exe.parent().unwrap().join("msbserver")
64});
65
66/// The default working directory for the sandbox.
67pub const DEFAULT_WORKDIR: &str = "/";
68
69/// The default namespace for the sandbox server.
70pub const DEFAULT_SERVER_NAMESPACE: &str = "default";
71
72/// The default localhost address.
73pub const DEFAULT_SERVER_HOST: &str = "127.0.0.1";
74
75/// The default microsandbox-server port.
76pub const DEFAULT_SERVER_PORT: u16 = 5555;
77
78/// The default microsandbox-portal port.
79pub const DEFAULT_PORTAL_GUEST_PORT: u16 = 4444;