Struct nix_config_parser::NixConfig
source · pub struct NixConfig { /* private fields */ }
Expand description
A newtype wrapper around a HashMap
, where the key is the name of the Nix
setting, and the value is the value of that setting. If the setting accepts
a list of values, the value will be space delimited.
Implementations§
source§impl NixConfig
impl NixConfig
pub fn new() -> Self
pub fn settings(&self) -> &HashMap<String, String>
pub fn settings_mut(&mut self) -> &mut HashMap<String, String>
pub fn into_settings(self) -> HashMap<String, String>
sourcepub fn parse_file(path: &Path) -> Result<Self, ParseError>
pub fn parse_file(path: &Path) -> Result<Self, ParseError>
Attempt to parse the nix.conf
at the provided path.
std::fs::write(
"nix.conf",
b"experimental-features = flakes nix-command\nwarn-dirty = false\n",
)?;
let nix_conf = nix_config_parser::NixConfig::parse_file(&std::path::Path::new("nix.conf"))?;
assert_eq!(
nix_conf.settings().get("experimental-features").unwrap(),
"flakes nix-command"
);
assert_eq!(nix_conf.settings().get("warn-dirty").unwrap(), "false");
std::fs::remove_file("nix.conf")?;
sourcepub fn parse_string(
contents: String,
origin: Option<&Path>
) -> Result<Self, ParseError>
pub fn parse_string( contents: String, origin: Option<&Path> ) -> Result<Self, ParseError>
Attempt to parse the nix.conf
out of the provided String
. The origin
parameter is Option
al, and only influences potential error messages.
let nix_conf_string = String::from("experimental-features = flakes nix-command");
let nix_conf = nix_config_parser::NixConfig::parse_string(nix_conf_string, None)?;
assert_eq!(
nix_conf.settings().get("experimental-features").unwrap(),
"flakes nix-command"
);