| Crates.io | ser_nix |
| lib.rs | ser_nix |
| version | 0.2.0 |
| created_at | 2025-05-01 12:32:16.250259+00 |
| updated_at | 2026-01-16 03:58:13.436378+00 |
| description | An opinionated nix serialiser for serde.rs |
| homepage | https://github.com/4jamesccraven/ser_nix |
| repository | https://github.com/4jamesccraven/ser_nix |
| max_upload_size | |
| id | 1656189 |
| size | 54,789 |
An opinionated Nix serializer, using the serde framework.
ser_nix exists to allow generation of human readable Nix code from Rust that
can be included in NixOS configurations, devShells, etc.
[!NOTE] This is not a deserializer, for that look into tvix_serde (which only implements the deserializer half). There is no guarantee of compatibility between the two.
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);
see the docs for more.
This crate is intentionally opinionated in the way it produces output. Unlike other crates in the Serde ecosystem, there is no "pretty" serialization and "normal" serialization; output is formatted/pretty by default.
Contributions, issues, etc. are all welcome and encouraged.
Please ensure code is formatted with rustfmt prior to submitting PRs.
ser_nix is licensed under the MIT license.