Skip to content

Instantly share code, notes, and snippets.

@jbeda
Created September 1, 2015 23:04
Show Gist options
  • Save jbeda/5c79d2b1434f0018d693 to your computer and use it in GitHub Desktop.
Save jbeda/5c79d2b1434f0018d693 to your computer and use it in GitHub Desktop.
Nix Archive (NAR) file specification

This is taken directly from Figure 5.2 in http://nixos.org/~eelco/pubs/phd-thesis.pdf. It is presented here to be more directly linkable.

serialise(fso) = str("nix-archive-1") + serialise1(fso)

serialise1(fso) = str("(") + seralise2(fso) + str(")")

serialise2(type=Regular, exec, contents) =
  str("type") + str("regular")
  + (
    str("executable") + str(""), if exec = Executable
    "", if exec = NonExecutable
  ) + str("contents") + str(contents)
  
serialise2(type=SymLink, target) =
  str("type") + str("symlink")
  + str("target") + str(target)

serialise2(type=Directory, entries) =
  str("type") + str("directory")
  + concatMap(serialiseEntry, sortEntries(entries))

serialiseEntry((name, fso)) =
  str("entry") + str("(")
  + str("name") + str(name)
  + str("node") + serialise1(fso)
  + str(")")
  
str(s) = int(|s|) + pad(s)

int(n) = the 64-bit little endian representation of the number n

pad(s) = the byte sequence s, padded with 0s to a multiple of 8 bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment