https://github.com/determinatesystems/nix-config-parser
https://github.com/determinatesystems/nix-config-parser
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/determinatesystems/nix-config-parser
- Owner: DeterminateSystems
- License: lgpl-2.1
- Created: 2023-01-31T20:54:42.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-04T00:12:51.000Z (about 1 year ago)
- Last Synced: 2025-05-04T01:19:15.660Z (about 1 year ago)
- Language: Rust
- Size: 59.6 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# nix-config-parser
A simple parser for the Nix configuration file format.
Based off of https://github.com/NixOS/nix/blob/0079d2943702a7a7fbdd88c0f9a5ad677c334aa8/src/libutil/config.cc#L80-L138.
## Usage
### Read from a file
```rust
use std::error::Error;
fn main() -> Result<(), Box> {
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")?;
Ok(())
}
```
### Read from a string
```rust
use std::error::Error;
fn main() -> Result<(), Box> {
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"
);
Ok(())
}
```