aboutsummaryrefslogtreecommitdiffstats
path: root/zone_nspawn/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'zone_nspawn/src/config.rs')
-rw-r--r--zone_nspawn/src/config.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/zone_nspawn/src/config.rs b/zone_nspawn/src/config.rs
new file mode 100644
index 0000000..3c13ff5
--- /dev/null
+++ b/zone_nspawn/src/config.rs
@@ -0,0 +1,40 @@
+use figment::{
+ error::Result,
+ providers::{Format, Serialized, Toml},
+ value::{Dict, Map},
+ Figment, Metadata, Profile, Provider,
+};
+use serde::{Deserialize, Serialize};
+use std::path::PathBuf;
+#[derive(Debug, Clone, Deserialize, Serialize)]
+pub struct Config {
+ pub network_configs_path: Option<PathBuf>,
+}
+
+impl Default for Config {
+ fn default() -> Self {
+ Config {
+ network_configs_path: None,
+ }
+ }
+}
+
+impl Config {
+ pub fn from<T: Provider>(provider: T) -> Result<Config> {
+ Figment::from(provider).extract()
+ }
+
+ pub fn figment() -> Figment {
+ Figment::from(Config::default()).merge(Toml::file("NSpawn.toml").nested())
+ }
+}
+
+impl Provider for Config {
+ fn metadata(&self) -> Metadata {
+ Metadata::named("ZFS Config")
+ }
+
+ fn data(&self) -> Result<Map<Profile, Dict>> {
+ Serialized::defaults(Config::default()).data()
+ }
+}