Git Product home page Git Product logo

libnar's Introduction

libnar

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:

  1. Deterministic ordering when unpacking files
  2. Fully specified, no undefined or implementation-specific behavior
  3. Strips out non-reproducible file metadata (creation time, last access time, owner and group IDs, all file mode permissions except for executable) before packing and normalizes them at unpacking time
  4. Strips out the setuid and sticky bits along with all filesystem-specific extended attributes before packing

libnar 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.

Examples

Opening an archive

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);
    }
}

Extracting an archive

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();
}

Creating an archive

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();
}

License

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.

libnar's People

Contributors

ebkalderon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

libnar's Issues

Liveliness as of Oct 2021?

Hi Eyal, thank you for sharing this. I'd like to use this library in a project I'm working on, but I'd like to hear from you on how live you think this repo is at this point. The last commit was in January 2020, and there's pull request that's been unaddressed for months ( #2 ). None of this is a problem of course, you don't owe anyone your hobby time. I'd just appreciate hearing where you're at right now. If you've moved on to other things, I'll not list this as a external dependency but vendor the source. If, on the other hand, you've been itching to get back to this but are looking for help, this is me volunteering to lend a hand.

Support WASM

I followed https://rustwasm.github.io/docs/book/reference/add-wasm-support-to-crate.html to try to support webassembly in libnar, and it gets quite far but fails like so:

error[E0433]: failed to resolve: could not find `unix` in `os`
 --> src/de.rs:7:14
  |
7 | use std::os::unix::fs::OpenOptionsExt;
  |              ^^^^ could not find `unix` in `os`

error[E0433]: failed to resolve: could not find `unix` in `os`
 --> src/ser.rs:3:14
  |
3 | use std::os::unix::fs::MetadataExt;
  |              ^^^^ could not find `unix` in `os`

error[E0433]: failed to resolve: could not find `unix` in `os`
   --> src/de.rs:434:18
    |
434 |         std::os::unix::fs::symlink(target, dst)
    |                  ^^^^ could not find `unix` in `os`

error[E0599]: no method named `mode` found for struct `OpenOptions` in the current scope
   --> src/de.rs:419:17
    |
419 |             opt.mode(0o555);
    |                 ^^^^ method not found in `OpenOptions`

error[E0599]: no method named `mode` found for struct `OpenOptions` in the current scope
   --> src/de.rs:421:17
    |
421 |             opt.mode(0o444);
    |                 ^^^^ method not found in `OpenOptions`

error[E0599]: no method named `mode` found for struct `Metadata` in the current scope
  --> src/ser.rs:52:21
   |
52 |         if metadata.mode() & 0o111 != 0 {
   |                     ^^^^ help: there is a method with a similar name: `modified`

Some errors have detailed explanations: E0433, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `libnar` (lib) due to 6 previous errors

Supporting WASM would mean we could compute the NAR Hash of files/folders on a webpage, which would be fantastic for web services built with Nix backends, as I am trying to make.

Where is the specification?

The README says:

Fully specified, no undefined or implementation-specific behavior

But I can't a specification in this repository, nor a link to one?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.