Library for reading and writing from NAR (Nix Archive) files written in Rust.
The NAR format, developed exclusively for the Nix package manager, is a fully
deterministic and reproducible alternative to the tar archive format. It is
used to serialize and deserialize filesystem objects, such as files and
directories and symlinks, in and out of the Nix store. Unlike tar, .nar
archives have the following properties:
setuid
and sticky bits along with all filesystem-specific
extended attributes before packinglibnar
is a fast and lightweight implementation of the Nix Archive format in
Rust and provides a convenient interface for opening, creating, packing, and
unpacking .nar
files. It is intentionally kept as minimal as possible with few
dependencies to keep the codebase portable.
use std::fs::File;
use libnar::Archive;
fn main() {
let file = File::open("/path/to/archive.nar").unwrap();
let mut nar = Archive::new(file).unwrap();
let entries = nar.entries().unwrap();
for entry in entries {
let entry = entry.unwrap();
println!("{:?}", entry);
}
}
use std::fs::File;
use libnar::Archive;
fn main() {
let file = File::open("/path/to/archive.nar").unwrap();
let mut nar = Archive::new(file).unwrap();
nar.unpack("./archive").unwrap();
}
use std::fs::File;
fn main() {
let mut file = File::create("/path/to/archive.nar").unwrap();
libnar::to_writer(&mut file, "/path/to/archive").unwrap();
}
libnar
is free and open source software distributed under the terms of both
the MIT and the Apache 2.0 licenses.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.