3 releases
Uses new Rust 2024
| 0.1.2 | Jun 6, 2025 |
|---|---|
| 0.1.1 | May 2, 2025 |
| 0.1.0 | May 1, 2025 |
#922 in Encoding
Used in mkdev
26KB
737 lines
ser_nix
Nix is a declarative, atomic, and reproducible package manager that is configured with the nix programming language
{
a = 1;
b = "Hello World";
submap.foo = "bar";
}
ser_nix can be used to serialise arbitrary rust types into corresponding nix data types. As the name implies, ser_nix does not provide deserialisation capabilities, as the process for doing so is non-trivial, and requires evaluating nix code.
ser_nix tries to follow the idioms of other serde libraries, like serde_json.
use serde::Serialize;
use ser_nix::to_string;
#[derive(Serialize)]
struct Person {
name: String,
age: u8,
}
let cm = Person {
name: "John Doe".into(),
age: 65,
};
let serialized = to_string(&cm).unwrap();
let expected = "{\n name = \"John Doe\";\n age = 65;\n}".to_string();
assert_eq!(serialized, expected);
Disclaimer
This library was created mostly to be used as a subcomponent of my main project, mkdev. Because of that it is not as a full featured as other serde implemenatations, but I intend to change that over time
An opinionated Nix serialiser, using the serde frame-work.
[!WARNING] This is alpha software
[!NOTE] This is not a deserialiser, for that look into tvix_serde (which only implements the deserialiser half). I make no guarantees of compatibility between the two.
Currently ser_nix only exposes a to_string function, and an error type. Ser_nix is new software, and currently only exists to fulfill a need I had for my main project. The decision to release it publicly was in hope that others might wish to contribute and improve, as the ecosystem seemed bare in this regard.
Please open an issue or contact me via email for any concerns related to this crate.
Dependencies
~0.3–1MB
~22K SLoC