Nix Archive (NAR) is the archive format of the Nix package manager. A NAR contains a single file system object: a regular file, a symbolic link, or a directory with everything in it. Besides names, file contents and symlink targets, it only stores which regular files are executable. There are no timestamps and no other permissions.
Unlike TAR or ZIP, the format is canonical: a given file system object always has the same NAR. For example, directory entries are always sorted by name. Nix identifies the contents of each store path by the SHA-256 hash of its NAR, and binary caches serve store paths as NARs, usually compressed. GNU Guix uses the same format.
This Kaitai Struct implementation rejects the same NARs as Nix 2.36.0
with the default settings on Linux, except that it accepts entry names
that contain /.
Older versions of Nix may accept more NARs. For example, Nix checks the order of directory entries only since version 2.25.0, and it limits the length of names and symlink targets and the nesting depth only since 2.35.0. Some of these checks were also backported to patch releases of older versions.
This page hosts a formal specification of Nix Archive (NAR) using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.
// Code generated by kaitai-struct-compiler from a .ksy source file. DO NOT EDIT.
import (
"github.com/kaitai-io/kaitai_struct_go_runtime/kaitai"
"bytes"
)
/**
* Nix Archive (NAR) is the archive format of the [Nix](https://nixos.org/)
* package manager. A NAR contains a single file system object: a regular
* file, a symbolic link, or a directory with everything in it. Besides
* names, file contents and symlink targets, it only stores which regular
* files are executable. There are
* [no timestamps and no other permissions](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/doc/manual/source/command-ref/nix-store/dump.md?plain=1#L15-L19).
*
* Unlike TAR or ZIP, the format is
* [canonical](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/doc/manual/source/command-ref/nix-store/dump.md?plain=1#L21-L27):
* a given file system object always has the same NAR. For example,
* directory entries are always sorted by name. Nix identifies the contents
* of each store path by the SHA-256 hash of its NAR, and
* [binary caches](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/doc/manual/source/protocols/binary-cache/index.md?plain=1#L8-L10)
* serve store paths as NARs, usually compressed.
* [GNU Guix](https://codeberg.org/guix/guix/src/commit/ab6a9f84e783710335a29f6591f570e5e2df143c/guix/serialization.scm#L441-L446)
* uses the same format.
*
* This Kaitai Struct implementation rejects the same NARs as Nix 2.36.0
* with the default settings on Linux, except that it accepts entry names
* that contain `/`.
*
* Older versions of Nix may accept more NARs. For example, Nix checks the
* order of directory entries only since version 2.25.0, and it limits the
* length of names and symlink targets and the nesting depth only since
* 2.35.0. Some of these checks were also backported to patch releases of
* older versions.
* @see <a href="https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/doc/manual/source/protocols/nix-archive/index.md">Git tag "2.36.0"</a>
*/
type NixNar struct {
Magic *NixNar_PaddedStr
RootNode *NixNar_Node
_io *kaitai.Stream
_root *NixNar
_parent kaitai.Struct
}
func NewNixNar() *NixNar {
return &NixNar{
}
}
func (this NixNar) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar) Read(io *kaitai.Stream, parent kaitai.Struct, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
tmp1 := NewNixNar_PaddedStr()
err = tmp1.Read(this._io, this, this._root)
if err != nil {
return err
}
this.Magic = tmp1
{
_it := this.Magic
if !(_it.Body == "nix-archive-1") {
return kaitai.NewValidationExprError(this.Magic, this._io, "/seq/0")
}
}
tmp2 := NewNixNar_Node(0)
err = tmp2.Read(this._io, this, this._root)
if err != nil {
return err
}
this.RootNode = tmp2
return err
}
/**
* Magic string, must be `nix-archive-1`.
*/
/**
* The root of the archive, which is always a single node.
*/
/**
* A single file system node (regular file, directory, or symlink).
*/
type NixNar_Node struct {
_unnamed0 []byte
OpenParen *NixNar_PaddedStr
TypeKey *NixNar_PaddedStr
TypeVal *NixNar_PaddedStr
Body kaitai.Struct
CloseParen *NixNar_PaddedStr
Depth int32
_io *kaitai.Stream
_root *NixNar
_parent kaitai.Struct
}
func NewNixNar_Node(depth int32) *NixNar_Node {
return &NixNar_Node{
Depth: depth,
}
}
func (this NixNar_Node) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar_Node) Read(io *kaitai.Stream, parent kaitai.Struct, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
tmp3, err := this._io.ReadBytes(int(0))
if err != nil {
return err
}
tmp3 = tmp3
this._unnamed0 = tmp3
{
_it := this._unnamed0
if !(this.Depth < 64) {
return kaitai.NewValidationExprError(this._unnamed0, this._io, "/types/node/seq/0")
}
}
tmp4 := NewNixNar_PaddedStr()
err = tmp4.Read(this._io, this, this._root)
if err != nil {
return err
}
this.OpenParen = tmp4
{
_it := this.OpenParen
if !(_it.Body == "(") {
return kaitai.NewValidationExprError(this.OpenParen, this._io, "/types/node/seq/1")
}
}
tmp5 := NewNixNar_PaddedStr()
err = tmp5.Read(this._io, this, this._root)
if err != nil {
return err
}
this.TypeKey = tmp5
{
_it := this.TypeKey
if !(_it.Body == "type") {
return kaitai.NewValidationExprError(this.TypeKey, this._io, "/types/node/seq/2")
}
}
tmp6 := NewNixNar_PaddedStr()
err = tmp6.Read(this._io, this, this._root)
if err != nil {
return err
}
this.TypeVal = tmp6
{
_it := this.TypeVal
if !( ((_it.Body == "regular") || (_it.Body == "directory") || (_it.Body == "symlink")) ) {
return kaitai.NewValidationExprError(this.TypeVal, this._io, "/types/node/seq/3")
}
}
switch (this.TypeVal.Body) {
case "directory":
tmp7 := NewNixNar_TypeDirectory()
err = tmp7.Read(this._io, this, this._root)
if err != nil {
return err
}
this.Body = tmp7
case "regular":
tmp8 := NewNixNar_TypeRegular()
err = tmp8.Read(this._io, this, this._root)
if err != nil {
return err
}
this.Body = tmp8
case "symlink":
tmp9 := NewNixNar_TypeSymlink()
err = tmp9.Read(this._io, this, this._root)
if err != nil {
return err
}
this.Body = tmp9
}
if (this.TypeVal.Body != "directory") {
tmp10 := NewNixNar_PaddedStr()
err = tmp10.Read(this._io, this, this._root)
if err != nil {
return err
}
this.CloseParen = tmp10
{
_it := this.CloseParen
if !(_it.Body == ")") {
return kaitai.NewValidationExprError(this.CloseParen, this._io, "/types/node/seq/5")
}
}
}
return err
}
/**
* Must be `(`, a token starting the node definition.
*/
/**
* Must be `type`.
*/
/**
* Type of the node (`regular`, `directory`, or `symlink`).
*/
/**
* Must be `)`, a token ending the node definition. A directory node
* has no `close_paren`: its `)` is read as the terminator at the end
* of `body.entries`.
*/
/**
* A byte sequence, prefixed with its length (u8le) and
* padded with null bytes to the next 8-byte boundary.
*
* Used for entry names and symlink targets, which Nix handles as raw
* bytes, without decoding them as text.
*/
type NixNar_PaddedBytes struct {
LenBody uint64
Body []byte
Padding []byte
_io *kaitai.Stream
_root *NixNar
_parent kaitai.Struct
}
func NewNixNar_PaddedBytes() *NixNar_PaddedBytes {
return &NixNar_PaddedBytes{
}
}
func (this NixNar_PaddedBytes) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar_PaddedBytes) Read(io *kaitai.Stream, parent kaitai.Struct, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
tmp11, err := this._io.ReadU8le()
if err != nil {
return err
}
this.LenBody = uint64(tmp11)
tmp12, err := this._io.ReadBytes(int(this.LenBody))
if err != nil {
return err
}
tmp12 = tmp12
this.Body = tmp12
tmp14 := this.LenBody % 8
if tmp14 < 0 {
tmp14 += 8
}
tmp13 := (8 - tmp14) % 8
if tmp13 < 0 {
tmp13 += 8
}
tmp15, err := this._io.ReadBytes(int(tmp13))
if err != nil {
return err
}
tmp15 = tmp15
this.Padding = tmp15
{
_it := this.Padding
var tmp16 bool;
if (len(_it) != 0) {
tmp17 := _it[0]
for _, tmp18 := range _it {
if tmp17 < tmp18 {
tmp17 = tmp18
}
}
tmp16 = tmp17 == 0
} else {
tmp16 = true
}
if !(tmp16) {
return kaitai.NewValidationExprError(this.Padding, this._io, "/types/padded_bytes/seq/2")
}
}
return err
}
/**
* A string, prefixed with its length (u8le) and
* padded with null bytes to the next 8-byte boundary.
*
* Used for the tokens of the format, such as `nix-archive-1`, `(` and
* `type`. They are all ASCII.
*/
type NixNar_PaddedStr struct {
LenBody uint64
Body string
Padding []byte
_io *kaitai.Stream
_root *NixNar
_parent kaitai.Struct
}
func NewNixNar_PaddedStr() *NixNar_PaddedStr {
return &NixNar_PaddedStr{
}
}
func (this NixNar_PaddedStr) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar_PaddedStr) Read(io *kaitai.Stream, parent kaitai.Struct, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
tmp19, err := this._io.ReadU8le()
if err != nil {
return err
}
this.LenBody = uint64(tmp19)
tmp20, err := this._io.ReadBytes(int(this.LenBody))
if err != nil {
return err
}
tmp20 = tmp20
this.Body = string(tmp20)
tmp22 := this.LenBody % 8
if tmp22 < 0 {
tmp22 += 8
}
tmp21 := (8 - tmp22) % 8
if tmp21 < 0 {
tmp21 += 8
}
tmp23, err := this._io.ReadBytes(int(tmp21))
if err != nil {
return err
}
tmp23 = tmp23
this.Padding = tmp23
{
_it := this.Padding
var tmp24 bool;
if (len(_it) != 0) {
tmp25 := _it[0]
for _, tmp26 := range _it {
if tmp25 < tmp26 {
tmp25 = tmp26
}
}
tmp24 = tmp25 == 0
} else {
tmp24 = true
}
if !(tmp24) {
return kaitai.NewValidationExprError(this.Padding, this._io, "/types/padded_str/seq/2")
}
}
return err
}
/**
* A directory node, containing a list of entries. Entries must be
* ordered by their names. Each name must be greater than the previous
* one when compared lexicographically as arrays of unsigned bytes.
*/
type NixNar_TypeDirectory struct {
Entries []*NixNar_TypeDirectory_DirEntry
_io *kaitai.Stream
_root *NixNar
_parent *NixNar_Node
}
func NewNixNar_TypeDirectory() *NixNar_TypeDirectory {
return &NixNar_TypeDirectory{
}
}
func (this NixNar_TypeDirectory) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar_TypeDirectory) Read(io *kaitai.Stream, parent *NixNar_Node, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
for i := 1;; i++ {
tmp27 := NewNixNar_TypeDirectory_DirEntry()
err = tmp27.Read(this._io, this, this._root)
if err != nil {
return err
}
_it := tmp27
this.Entries = append(this.Entries, _it)
{
_it := this.Entries[i]
var tmp28 bool;
tmp29, err := _it.IsTerminator()
if err != nil {
return err
}
if ( ((i != 0) && (!(tmp29))) ) {
tmp28 = (bytes.Compare(_it.Body.Name.Body, this.Entries[i - 1].Body.Name.Body) > 0)
} else {
tmp28 = true
}
if !(tmp28) {
return kaitai.NewValidationExprError(this.Entries[i], this._io, "/types/type_directory/seq/0")
}
}
tmp30, err := _it.IsTerminator()
if err != nil {
return err
}
if tmp30 {
break
}
}
return err
}
/**
* A single entry within a directory, or the terminator, i.e. the `)`
* token that ends the directory node.
*/
type NixNar_TypeDirectory_DirEntry struct {
Kind *NixNar_PaddedStr
Body *NixNar_TypeDirectory_DirEntryBody
_io *kaitai.Stream
_root *NixNar
_parent *NixNar_TypeDirectory
_f_isTerminator bool
isTerminator bool
}
func NewNixNar_TypeDirectory_DirEntry() *NixNar_TypeDirectory_DirEntry {
return &NixNar_TypeDirectory_DirEntry{
}
}
func (this NixNar_TypeDirectory_DirEntry) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar_TypeDirectory_DirEntry) Read(io *kaitai.Stream, parent *NixNar_TypeDirectory, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
tmp31 := NewNixNar_PaddedStr()
err = tmp31.Read(this._io, this, this._root)
if err != nil {
return err
}
this.Kind = tmp31
{
_it := this.Kind
if !( ((_it.Body == "entry") || (_it.Body == ")")) ) {
return kaitai.NewValidationExprError(this.Kind, this._io, "/types/type_directory/types/dir_entry/seq/0")
}
}
tmp32, err := this.IsTerminator()
if err != nil {
return err
}
if (!(tmp32)) {
tmp33 := NewNixNar_TypeDirectory_DirEntryBody()
err = tmp33.Read(this._io, this, this._root)
if err != nil {
return err
}
this.Body = tmp33
}
return err
}
func (this *NixNar_TypeDirectory_DirEntry) IsTerminator() (v bool, err error) {
if (this._f_isTerminator) {
return this.isTerminator, nil
}
this._f_isTerminator = true
this.isTerminator = bool(this.Kind.Body == ")")
return this.isTerminator, nil
}
/**
* Must be `entry` (for a child node) or `)` (for the terminator).
*/
/**
* The entry itself. The terminator has no `body`.
*/
type NixNar_TypeDirectory_DirEntryBody struct {
OpenParen *NixNar_PaddedStr
NameKey *NixNar_PaddedStr
Name *NixNar_PaddedBytes
NodeKey *NixNar_PaddedStr
Node *NixNar_Node
CloseParen *NixNar_PaddedStr
_io *kaitai.Stream
_root *NixNar
_parent *NixNar_TypeDirectory_DirEntry
}
func NewNixNar_TypeDirectory_DirEntryBody() *NixNar_TypeDirectory_DirEntryBody {
return &NixNar_TypeDirectory_DirEntryBody{
}
}
func (this NixNar_TypeDirectory_DirEntryBody) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar_TypeDirectory_DirEntryBody) Read(io *kaitai.Stream, parent *NixNar_TypeDirectory_DirEntry, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
tmp34 := NewNixNar_PaddedStr()
err = tmp34.Read(this._io, this, this._root)
if err != nil {
return err
}
this.OpenParen = tmp34
{
_it := this.OpenParen
if !(_it.Body == "(") {
return kaitai.NewValidationExprError(this.OpenParen, this._io, "/types/type_directory/types/dir_entry_body/seq/0")
}
}
tmp35 := NewNixNar_PaddedStr()
err = tmp35.Read(this._io, this, this._root)
if err != nil {
return err
}
this.NameKey = tmp35
{
_it := this.NameKey
if !(_it.Body == "name") {
return kaitai.NewValidationExprError(this.NameKey, this._io, "/types/type_directory/types/dir_entry_body/seq/1")
}
}
tmp36 := NewNixNar_PaddedBytes()
err = tmp36.Read(this._io, this, this._root)
if err != nil {
return err
}
this.Name = tmp36
{
_it := this.Name
tmp37 := _it.Body[0]
for _, tmp38 := range _it.Body {
if tmp37 > tmp38 {
tmp37 = tmp38
}
}
if !( ((len(_it.Body) != 0) && (len(_it.Body) <= 255) && ((bytes.Compare(_it.Body, []uint8{46}) != 0)) && ((bytes.Compare(_it.Body, []uint8{46, 46}) != 0)) && (tmp37 != 0)) ) {
return kaitai.NewValidationExprError(this.Name, this._io, "/types/type_directory/types/dir_entry_body/seq/2")
}
}
tmp39 := NewNixNar_PaddedStr()
err = tmp39.Read(this._io, this, this._root)
if err != nil {
return err
}
this.NodeKey = tmp39
{
_it := this.NodeKey
if !(_it.Body == "node") {
return kaitai.NewValidationExprError(this.NodeKey, this._io, "/types/type_directory/types/dir_entry_body/seq/3")
}
}
tmp40 := NewNixNar_Node(this._parent._parent._parent.Depth + 1)
err = tmp40.Read(this._io, this, this._root)
if err != nil {
return err
}
this.Node = tmp40
tmp41 := NewNixNar_PaddedStr()
err = tmp41.Read(this._io, this, this._root)
if err != nil {
return err
}
this.CloseParen = tmp41
{
_it := this.CloseParen
if !(_it.Body == ")") {
return kaitai.NewValidationExprError(this.CloseParen, this._io, "/types/type_directory/types/dir_entry_body/seq/5")
}
}
return err
}
/**
* Name of the entry, as raw bytes. Nix 2.36.0
* [doesn't decode names as text](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/src/libutil/archive.cc#L245-L248)
* either, and real NARs contain names that aren't valid UTF-8.
*
* The name must be 1 to 255 bytes long, must not be `.` or `..`, and
* must not contain a null byte. Nix also rejects names that contain
* `/`, but this Kaitai Struct implementation doesn't check that: as
* of KS 0.11, expressions can't search a byte array for a given
* byte. A null byte can be detected anyway: 0 is the smallest
* possible byte value, so a name contains a null byte exactly if its
* smallest byte is 0.
*/
/**
* The child node.
*/
/**
* A regular file node.
*/
type NixNar_TypeRegular struct {
FirstKey *NixNar_PaddedStr
ExecutableVal *NixNar_PaddedStr
ContentsKey *NixNar_PaddedStr
FileData *NixNar_TypeRegular_FileContent
_io *kaitai.Stream
_root *NixNar
_parent *NixNar_Node
_f_isExecutable bool
isExecutable bool
}
func NewNixNar_TypeRegular() *NixNar_TypeRegular {
return &NixNar_TypeRegular{
}
}
func (this NixNar_TypeRegular) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar_TypeRegular) Read(io *kaitai.Stream, parent *NixNar_Node, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
tmp42 := NewNixNar_PaddedStr()
err = tmp42.Read(this._io, this, this._root)
if err != nil {
return err
}
this.FirstKey = tmp42
{
_it := this.FirstKey
if !( ((_it.Body == "executable") || (_it.Body == "contents")) ) {
return kaitai.NewValidationExprError(this.FirstKey, this._io, "/types/type_regular/seq/0")
}
}
tmp43, err := this.IsExecutable()
if err != nil {
return err
}
if (tmp43) {
tmp44 := NewNixNar_PaddedStr()
err = tmp44.Read(this._io, this, this._root)
if err != nil {
return err
}
this.ExecutableVal = tmp44
{
_it := this.ExecutableVal
if !(_it.Body == "") {
return kaitai.NewValidationExprError(this.ExecutableVal, this._io, "/types/type_regular/seq/1")
}
}
}
tmp45, err := this.IsExecutable()
if err != nil {
return err
}
if (tmp45) {
tmp46 := NewNixNar_PaddedStr()
err = tmp46.Read(this._io, this, this._root)
if err != nil {
return err
}
this.ContentsKey = tmp46
{
_it := this.ContentsKey
if !(_it.Body == "contents") {
return kaitai.NewValidationExprError(this.ContentsKey, this._io, "/types/type_regular/seq/2")
}
}
}
tmp47 := NewNixNar_TypeRegular_FileContent()
err = tmp47.Read(this._io, this, this._root)
if err != nil {
return err
}
this.FileData = tmp47
return err
}
/**
* True if the file has the `executable` attribute.
*/
func (this *NixNar_TypeRegular) IsExecutable() (v bool, err error) {
if (this._f_isExecutable) {
return this.isExecutable, nil
}
this._f_isExecutable = true
this.isExecutable = bool(this.FirstKey.Body == "executable")
return this.isExecutable, nil
}
/**
* Either `executable` or `contents`.
*/
/**
* Must be empty.
*/
/**
* The contents of the file, prefixed with their length and padded
* with null bytes to the next 8-byte boundary.
*/
type NixNar_TypeRegular_FileContent struct {
LenContents uint64
_unnamed1 []byte
Contents []byte
Padding []byte
_io *kaitai.Stream
_root *NixNar
_parent *NixNar_TypeRegular
_f_narOffset bool
narOffset int
}
func NewNixNar_TypeRegular_FileContent() *NixNar_TypeRegular_FileContent {
return &NixNar_TypeRegular_FileContent{
}
}
func (this NixNar_TypeRegular_FileContent) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar_TypeRegular_FileContent) Read(io *kaitai.Stream, parent *NixNar_TypeRegular, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
tmp48, err := this._io.ReadU8le()
if err != nil {
return err
}
this.LenContents = uint64(tmp48)
tmp49, err := this.NarOffset()
if err != nil {
return err
}
if (tmp49 < 0) {
tmp50, err := this._io.ReadBytes(int(0))
if err != nil {
return err
}
tmp50 = tmp50
this._unnamed1 = tmp50
}
tmp51, err := this._io.ReadBytes(int(this.LenContents))
if err != nil {
return err
}
tmp51 = tmp51
this.Contents = tmp51
tmp53 := this.LenContents % 8
if tmp53 < 0 {
tmp53 += 8
}
tmp52 := (8 - tmp53) % 8
if tmp52 < 0 {
tmp52 += 8
}
tmp54, err := this._io.ReadBytes(int(tmp52))
if err != nil {
return err
}
tmp54 = tmp54
this.Padding = tmp54
{
_it := this.Padding
var tmp55 bool;
if (len(_it) != 0) {
tmp56 := _it[0]
for _, tmp57 := range _it {
if tmp56 < tmp57 {
tmp56 = tmp57
}
}
tmp55 = tmp56 == 0
} else {
tmp55 = true
}
if !(tmp55) {
return kaitai.NewValidationExprError(this.Padding, this._io, "/types/type_regular/types/file_content/seq/3")
}
}
return err
}
/**
* Offset of `contents` in the stream. It corresponds to
* [`narOffset`](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/src/libutil/include/nix/util/source-accessor.hh#L134-L138)
* in Nix.
*/
func (this *NixNar_TypeRegular_FileContent) NarOffset() (v int, err error) {
if (this._f_narOffset) {
return this.narOffset, nil
}
this._f_narOffset = true
tmp58, err := this._io.Pos()
if err != nil {
return 0, err
}
this.narOffset = int(tmp58)
return this.narOffset, nil
}
/**
* This Kaitai Struct implementation keeps the contents of every
* file in memory, so parsing a NAR needs at least as much memory
* as all its files together.
*/
/**
* A symbolic link node.
*/
type NixNar_TypeSymlink struct {
TargetKey *NixNar_PaddedStr
TargetVal *NixNar_PaddedBytes
_io *kaitai.Stream
_root *NixNar
_parent *NixNar_Node
}
func NewNixNar_TypeSymlink() *NixNar_TypeSymlink {
return &NixNar_TypeSymlink{
}
}
func (this NixNar_TypeSymlink) IO_() *kaitai.Stream {
return this._io
}
func (this *NixNar_TypeSymlink) Read(io *kaitai.Stream, parent *NixNar_Node, root *NixNar) (err error) {
this._io = io
this._parent = parent
this._root = root
tmp59 := NewNixNar_PaddedStr()
err = tmp59.Read(this._io, this, this._root)
if err != nil {
return err
}
this.TargetKey = tmp59
{
_it := this.TargetKey
if !(_it.Body == "target") {
return kaitai.NewValidationExprError(this.TargetKey, this._io, "/types/type_symlink/seq/0")
}
}
tmp60 := NewNixNar_PaddedBytes()
err = tmp60.Read(this._io, this, this._root)
if err != nil {
return err
}
this.TargetVal = tmp60
{
_it := this.TargetVal
tmp61 := _it.Body[0]
for _, tmp62 := range _it.Body {
if tmp61 > tmp62 {
tmp61 = tmp62
}
}
if !( ((len(_it.Body) != 0) && (len(_it.Body) <= 4095) && (tmp61 != 0)) ) {
return kaitai.NewValidationExprError(this.TargetVal, this._io, "/types/type_symlink/seq/1")
}
}
return err
}
/**
* Must be `target`.
*/
/**
* The destination path of the symlink, as raw bytes. Nix 2.36.0
* [doesn't decode targets as text](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/src/libutil/archive.cc#L280-L282)
* either.
*
* The target must be 1 to 4095 bytes long and must not contain a null
* byte.
*/