Nix Archive (NAR): C# parsing library

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.

File extension

nar

KS implementation details

License: MIT

References

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.

Usage

Runtime library

All C# code generated by Kaitai Struct depends on the Kaitai Struct runtime library for C#. You must add this dependency to your project before you can parse or serialize any data.

The C# runtime library is available in the NuGet Gallery. Installation instructions can also be found there.

Code

Parse a local file and get structure in memory:

var data = NixNar.FromFile("path/to/local/file.nar");

Or parse structure from a byte array:

byte[] someArray = new byte[] { ... };
var data = new NixNar(new KaitaiStream(someArray));

After that, one can get various attributes from the structure by accessing properties like:

data.Magic // => Magic string, must be `nix-archive-1`.

C# source code to parse Nix Archive (NAR)

NixNar.cs

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

using System.Linq;
using System.Collections.Generic;

namespace Kaitai
{

    /// <summary>
    /// 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.
    /// </summary>
    /// <remarks>
    /// Reference: <a href="https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/doc/manual/source/protocols/nix-archive/index.md">Git tag "2.36.0"</a>
    /// </remarks>
    public partial class NixNar : KaitaiStruct
    {
        public static NixNar FromFile(string fileName)
        {
            return new NixNar(new KaitaiStream(fileName));
        }

        public NixNar(KaitaiStream p__io, KaitaiStruct p__parent = null, NixNar p__root = null) : base(p__io)
        {
            m_parent = p__parent;
            m_root = p__root ?? this;
            _read();
        }
        private void _read()
        {
            _magic = new PaddedStr(m_io, this, m_root);
            {
                PaddedStr M_ = _magic;
                if (!(M_.Body == "nix-archive-1"))
                {
                    throw new ValidationExprError(_magic, m_io, "/seq/0");
                }
            }
            _rootNode = new Node(0, m_io, this, m_root);
        }

        /// <summary>
        /// A single file system node (regular file, directory, or symlink).
        /// </summary>
        public partial class Node : KaitaiStruct
        {
            public Node(int p_depth, KaitaiStream p__io, KaitaiStruct p__parent = null, NixNar p__root = null) : base(p__io)
            {
                m_parent = p__parent;
                m_root = p__root;
                _depth = p_depth;
                _read();
            }
            private void _read()
            {
                __unnamed0 = m_io.ReadBytes(0);
                {
                    byte[] M_ = __unnamed0;
                    if (!(Depth < 64))
                    {
                        throw new ValidationExprError(__unnamed0, m_io, "/types/node/seq/0");
                    }
                }
                _openParen = new PaddedStr(m_io, this, m_root);
                {
                    PaddedStr M_ = _openParen;
                    if (!(M_.Body == "("))
                    {
                        throw new ValidationExprError(_openParen, m_io, "/types/node/seq/1");
                    }
                }
                _typeKey = new PaddedStr(m_io, this, m_root);
                {
                    PaddedStr M_ = _typeKey;
                    if (!(M_.Body == "type"))
                    {
                        throw new ValidationExprError(_typeKey, m_io, "/types/node/seq/2");
                    }
                }
                _typeVal = new PaddedStr(m_io, this, m_root);
                {
                    PaddedStr M_ = _typeVal;
                    if (!( ((M_.Body == "regular") || (M_.Body == "directory") || (M_.Body == "symlink")) ))
                    {
                        throw new ValidationExprError(_typeVal, m_io, "/types/node/seq/3");
                    }
                }
                switch (TypeVal.Body) {
                case "directory": {
                    _body = new TypeDirectory(m_io, this, m_root);
                    break;
                }
                case "regular": {
                    _body = new TypeRegular(m_io, this, m_root);
                    break;
                }
                case "symlink": {
                    _body = new TypeSymlink(m_io, this, m_root);
                    break;
                }
                }
                if (TypeVal.Body != "directory") {
                    _closeParen = new PaddedStr(m_io, this, m_root);
                    {
                        PaddedStr M_ = _closeParen;
                        if (!(M_.Body == ")"))
                        {
                            throw new ValidationExprError(_closeParen, m_io, "/types/node/seq/5");
                        }
                    }
                }
            }
            private byte[] __unnamed0;
            private PaddedStr _openParen;
            private PaddedStr _typeKey;
            private PaddedStr _typeVal;
            private KaitaiStruct _body;
            private PaddedStr _closeParen;
            private int _depth;
            private NixNar m_root;
            private KaitaiStruct m_parent;
            public byte[] Unnamed_0 { get { return __unnamed0; } }

            /// <summary>
            /// Must be `(`, a token starting the node definition.
            /// </summary>
            public PaddedStr OpenParen { get { return _openParen; } }

            /// <summary>
            /// Must be `type`.
            /// </summary>
            public PaddedStr TypeKey { get { return _typeKey; } }

            /// <summary>
            /// Type of the node (`regular`, `directory`, or `symlink`).
            /// </summary>
            public PaddedStr TypeVal { get { return _typeVal; } }
            public KaitaiStruct Body { get { return _body; } }

            /// <summary>
            /// 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`.
            /// </summary>
            public PaddedStr CloseParen { get { return _closeParen; } }

            /// <summary>
            /// Nesting depth of the node. The root node has depth 0.
            /// </summary>
            public int Depth { get { return _depth; } }
            public NixNar M_Root { get { return m_root; } }
            public KaitaiStruct M_Parent { get { return m_parent; } }
        }

        /// <summary>
        /// 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.
        /// </summary>
        public partial class PaddedBytes : KaitaiStruct
        {
            public static PaddedBytes FromFile(string fileName)
            {
                return new PaddedBytes(new KaitaiStream(fileName));
            }

            public PaddedBytes(KaitaiStream p__io, KaitaiStruct p__parent = null, NixNar p__root = null) : base(p__io)
            {
                m_parent = p__parent;
                m_root = p__root;
                _read();
            }
            private void _read()
            {
                _lenBody = m_io.ReadU8le();
                _body = m_io.ReadBytes(LenBody);
                _padding = m_io.ReadBytes(KaitaiStream.Mod(8 - KaitaiStream.Mod(LenBody, 8), 8));
                {
                    byte[] M_ = _padding;
                    if (!((M_.Length != 0 ? M_.Max() == 0 : true)))
                    {
                        throw new ValidationExprError(_padding, m_io, "/types/padded_bytes/seq/2");
                    }
                }
            }
            private ulong _lenBody;
            private byte[] _body;
            private byte[] _padding;
            private NixNar m_root;
            private KaitaiStruct m_parent;
            public ulong LenBody { get { return _lenBody; } }
            public byte[] Body { get { return _body; } }
            public byte[] Padding { get { return _padding; } }
            public NixNar M_Root { get { return m_root; } }
            public KaitaiStruct M_Parent { get { return m_parent; } }
        }

        /// <summary>
        /// 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.
        /// </summary>
        public partial class PaddedStr : KaitaiStruct
        {
            public static PaddedStr FromFile(string fileName)
            {
                return new PaddedStr(new KaitaiStream(fileName));
            }

            public PaddedStr(KaitaiStream p__io, KaitaiStruct p__parent = null, NixNar p__root = null) : base(p__io)
            {
                m_parent = p__parent;
                m_root = p__root;
                _read();
            }
            private void _read()
            {
                _lenBody = m_io.ReadU8le();
                _body = System.Text.Encoding.GetEncoding("ASCII").GetString(m_io.ReadBytes(LenBody));
                _padding = m_io.ReadBytes(KaitaiStream.Mod(8 - KaitaiStream.Mod(LenBody, 8), 8));
                {
                    byte[] M_ = _padding;
                    if (!((M_.Length != 0 ? M_.Max() == 0 : true)))
                    {
                        throw new ValidationExprError(_padding, m_io, "/types/padded_str/seq/2");
                    }
                }
            }
            private ulong _lenBody;
            private string _body;
            private byte[] _padding;
            private NixNar m_root;
            private KaitaiStruct m_parent;
            public ulong LenBody { get { return _lenBody; } }
            public string Body { get { return _body; } }
            public byte[] Padding { get { return _padding; } }
            public NixNar M_Root { get { return m_root; } }
            public KaitaiStruct M_Parent { get { return m_parent; } }
        }

        /// <summary>
        /// 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.
        /// </summary>
        public partial class TypeDirectory : KaitaiStruct
        {
            public static TypeDirectory FromFile(string fileName)
            {
                return new TypeDirectory(new KaitaiStream(fileName));
            }

            public TypeDirectory(KaitaiStream p__io, NixNar.Node p__parent = null, NixNar p__root = null) : base(p__io)
            {
                m_parent = p__parent;
                m_root = p__root;
                _read();
            }
            private void _read()
            {
                _entries = new List<DirEntry>();
                {
                    var i = 0;
                    DirEntry M_;
                    do {
                        M_ = new DirEntry(m_io, this, m_root);
                        _entries.Add(M_);
                        {
                            DirEntry M_ = _entries[i];
                            if (!(( ((i != 0) && (!(M_.IsTerminator)))  ? (KaitaiStream.ByteArrayCompare(M_.Body.Name.Body, Entries[i - 1].Body.Name.Body) > 0) : true)))
                            {
                                throw new ValidationExprError(_entries[i], m_io, "/types/type_directory/seq/0");
                            }
                        }
                        i++;
                    } while (!(M_.IsTerminator));
                }
            }

            /// <summary>
            /// A single entry within a directory, or the terminator, i.e. the `)`
            /// token that ends the directory node.
            /// </summary>
            public partial class DirEntry : KaitaiStruct
            {
                public static DirEntry FromFile(string fileName)
                {
                    return new DirEntry(new KaitaiStream(fileName));
                }

                public DirEntry(KaitaiStream p__io, NixNar.TypeDirectory p__parent = null, NixNar p__root = null) : base(p__io)
                {
                    m_parent = p__parent;
                    m_root = p__root;
                    f_isTerminator = false;
                    _read();
                }
                private void _read()
                {
                    _kind = new PaddedStr(m_io, this, m_root);
                    {
                        PaddedStr M_ = _kind;
                        if (!( ((M_.Body == "entry") || (M_.Body == ")")) ))
                        {
                            throw new ValidationExprError(_kind, m_io, "/types/type_directory/types/dir_entry/seq/0");
                        }
                    }
                    if (!(IsTerminator)) {
                        _body = new DirEntryBody(m_io, this, m_root);
                    }
                }
                private bool f_isTerminator;
                private bool _isTerminator;
                public bool IsTerminator
                {
                    get
                    {
                        if (f_isTerminator)
                            return _isTerminator;
                        f_isTerminator = true;
                        _isTerminator = (bool) (Kind.Body == ")");
                        return _isTerminator;
                    }
                }
                private PaddedStr _kind;
                private DirEntryBody _body;
                private NixNar m_root;
                private NixNar.TypeDirectory m_parent;

                /// <summary>
                /// Must be `entry` (for a child node) or `)` (for the terminator).
                /// </summary>
                public PaddedStr Kind { get { return _kind; } }

                /// <summary>
                /// The entry itself. The terminator has no `body`.
                /// </summary>
                public DirEntryBody Body { get { return _body; } }
                public NixNar M_Root { get { return m_root; } }
                public NixNar.TypeDirectory M_Parent { get { return m_parent; } }
            }
            public partial class DirEntryBody : KaitaiStruct
            {
                public static DirEntryBody FromFile(string fileName)
                {
                    return new DirEntryBody(new KaitaiStream(fileName));
                }

                public DirEntryBody(KaitaiStream p__io, NixNar.TypeDirectory.DirEntry p__parent = null, NixNar p__root = null) : base(p__io)
                {
                    m_parent = p__parent;
                    m_root = p__root;
                    _read();
                }
                private void _read()
                {
                    _openParen = new PaddedStr(m_io, this, m_root);
                    {
                        PaddedStr M_ = _openParen;
                        if (!(M_.Body == "("))
                        {
                            throw new ValidationExprError(_openParen, m_io, "/types/type_directory/types/dir_entry_body/seq/0");
                        }
                    }
                    _nameKey = new PaddedStr(m_io, this, m_root);
                    {
                        PaddedStr M_ = _nameKey;
                        if (!(M_.Body == "name"))
                        {
                            throw new ValidationExprError(_nameKey, m_io, "/types/type_directory/types/dir_entry_body/seq/1");
                        }
                    }
                    _name = new PaddedBytes(m_io, this, m_root);
                    {
                        PaddedBytes M_ = _name;
                        if (!( ((M_.Body.Length != 0) && (M_.Body.Length <= 255) && ((KaitaiStream.ByteArrayCompare(M_.Body, new byte[] { 46 }) != 0)) && ((KaitaiStream.ByteArrayCompare(M_.Body, new byte[] { 46, 46 }) != 0)) && (M_.Body.Min() != 0)) ))
                        {
                            throw new ValidationExprError(_name, m_io, "/types/type_directory/types/dir_entry_body/seq/2");
                        }
                    }
                    _nodeKey = new PaddedStr(m_io, this, m_root);
                    {
                        PaddedStr M_ = _nodeKey;
                        if (!(M_.Body == "node"))
                        {
                            throw new ValidationExprError(_nodeKey, m_io, "/types/type_directory/types/dir_entry_body/seq/3");
                        }
                    }
                    _node = new Node(M_Parent.M_Parent.M_Parent.Depth + 1, m_io, this, m_root);
                    _closeParen = new PaddedStr(m_io, this, m_root);
                    {
                        PaddedStr M_ = _closeParen;
                        if (!(M_.Body == ")"))
                        {
                            throw new ValidationExprError(_closeParen, m_io, "/types/type_directory/types/dir_entry_body/seq/5");
                        }
                    }
                }
                private PaddedStr _openParen;
                private PaddedStr _nameKey;
                private PaddedBytes _name;
                private PaddedStr _nodeKey;
                private Node _node;
                private PaddedStr _closeParen;
                private NixNar m_root;
                private NixNar.TypeDirectory.DirEntry m_parent;
                public PaddedStr OpenParen { get { return _openParen; } }
                public PaddedStr NameKey { get { return _nameKey; } }

                /// <summary>
                /// 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.
                /// </summary>
                public PaddedBytes Name { get { return _name; } }
                public PaddedStr NodeKey { get { return _nodeKey; } }

                /// <summary>
                /// The child node.
                /// </summary>
                public Node Node { get { return _node; } }
                public PaddedStr CloseParen { get { return _closeParen; } }
                public NixNar M_Root { get { return m_root; } }
                public NixNar.TypeDirectory.DirEntry M_Parent { get { return m_parent; } }
            }
            private List<DirEntry> _entries;
            private NixNar m_root;
            private NixNar.Node m_parent;
            public List<DirEntry> Entries { get { return _entries; } }
            public NixNar M_Root { get { return m_root; } }
            public NixNar.Node M_Parent { get { return m_parent; } }
        }

        /// <summary>
        /// A regular file node.
        /// </summary>
        public partial class TypeRegular : KaitaiStruct
        {
            public static TypeRegular FromFile(string fileName)
            {
                return new TypeRegular(new KaitaiStream(fileName));
            }

            public TypeRegular(KaitaiStream p__io, NixNar.Node p__parent = null, NixNar p__root = null) : base(p__io)
            {
                m_parent = p__parent;
                m_root = p__root;
                f_isExecutable = false;
                _read();
            }
            private void _read()
            {
                _firstKey = new PaddedStr(m_io, this, m_root);
                {
                    PaddedStr M_ = _firstKey;
                    if (!( ((M_.Body == "executable") || (M_.Body == "contents")) ))
                    {
                        throw new ValidationExprError(_firstKey, m_io, "/types/type_regular/seq/0");
                    }
                }
                if (IsExecutable) {
                    _executableVal = new PaddedStr(m_io, this, m_root);
                    {
                        PaddedStr M_ = _executableVal;
                        if (!(M_.Body == ""))
                        {
                            throw new ValidationExprError(_executableVal, m_io, "/types/type_regular/seq/1");
                        }
                    }
                }
                if (IsExecutable) {
                    _contentsKey = new PaddedStr(m_io, this, m_root);
                    {
                        PaddedStr M_ = _contentsKey;
                        if (!(M_.Body == "contents"))
                        {
                            throw new ValidationExprError(_contentsKey, m_io, "/types/type_regular/seq/2");
                        }
                    }
                }
                _fileData = new FileContent(m_io, this, m_root);
            }

            /// <summary>
            /// The contents of the file, prefixed with their length and padded
            /// with null bytes to the next 8-byte boundary.
            /// </summary>
            public partial class FileContent : KaitaiStruct
            {
                public static FileContent FromFile(string fileName)
                {
                    return new FileContent(new KaitaiStream(fileName));
                }

                public FileContent(KaitaiStream p__io, NixNar.TypeRegular p__parent = null, NixNar p__root = null) : base(p__io)
                {
                    m_parent = p__parent;
                    m_root = p__root;
                    f_narOffset = false;
                    _read();
                }
                private void _read()
                {
                    _lenContents = m_io.ReadU8le();
                    if (NarOffset < 0) {
                        __unnamed1 = m_io.ReadBytes(0);
                    }
                    _contents = m_io.ReadBytes(LenContents);
                    _padding = m_io.ReadBytes(KaitaiStream.Mod(8 - KaitaiStream.Mod(LenContents, 8), 8));
                    {
                        byte[] M_ = _padding;
                        if (!((M_.Length != 0 ? M_.Max() == 0 : true)))
                        {
                            throw new ValidationExprError(_padding, m_io, "/types/type_regular/types/file_content/seq/3");
                        }
                    }
                }
                private bool f_narOffset;
                private int _narOffset;

                /// <summary>
                /// 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.
                /// </summary>
                public int NarOffset
                {
                    get
                    {
                        if (f_narOffset)
                            return _narOffset;
                        f_narOffset = true;
                        _narOffset = (int) (M_Io.Pos);
                        return _narOffset;
                    }
                }
                private ulong _lenContents;
                private byte[] __unnamed1;
                private byte[] _contents;
                private byte[] _padding;
                private NixNar m_root;
                private NixNar.TypeRegular m_parent;
                public ulong LenContents { get { return _lenContents; } }
                public byte[] Unnamed_1 { get { return __unnamed1; } }

                /// <summary>
                /// 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.
                /// </summary>
                public byte[] Contents { get { return _contents; } }
                public byte[] Padding { get { return _padding; } }
                public NixNar M_Root { get { return m_root; } }
                public NixNar.TypeRegular M_Parent { get { return m_parent; } }
            }
            private bool f_isExecutable;
            private bool _isExecutable;

            /// <summary>
            /// True if the file has the `executable` attribute.
            /// </summary>
            public bool IsExecutable
            {
                get
                {
                    if (f_isExecutable)
                        return _isExecutable;
                    f_isExecutable = true;
                    _isExecutable = (bool) (FirstKey.Body == "executable");
                    return _isExecutable;
                }
            }
            private PaddedStr _firstKey;
            private PaddedStr _executableVal;
            private PaddedStr _contentsKey;
            private FileContent _fileData;
            private NixNar m_root;
            private NixNar.Node m_parent;

            /// <summary>
            /// Either `executable` or `contents`.
            /// </summary>
            public PaddedStr FirstKey { get { return _firstKey; } }

            /// <summary>
            /// Must be empty.
            /// </summary>
            public PaddedStr ExecutableVal { get { return _executableVal; } }
            public PaddedStr ContentsKey { get { return _contentsKey; } }
            public FileContent FileData { get { return _fileData; } }
            public NixNar M_Root { get { return m_root; } }
            public NixNar.Node M_Parent { get { return m_parent; } }
        }

        /// <summary>
        /// A symbolic link node.
        /// </summary>
        public partial class TypeSymlink : KaitaiStruct
        {
            public static TypeSymlink FromFile(string fileName)
            {
                return new TypeSymlink(new KaitaiStream(fileName));
            }

            public TypeSymlink(KaitaiStream p__io, NixNar.Node p__parent = null, NixNar p__root = null) : base(p__io)
            {
                m_parent = p__parent;
                m_root = p__root;
                _read();
            }
            private void _read()
            {
                _targetKey = new PaddedStr(m_io, this, m_root);
                {
                    PaddedStr M_ = _targetKey;
                    if (!(M_.Body == "target"))
                    {
                        throw new ValidationExprError(_targetKey, m_io, "/types/type_symlink/seq/0");
                    }
                }
                _targetVal = new PaddedBytes(m_io, this, m_root);
                {
                    PaddedBytes M_ = _targetVal;
                    if (!( ((M_.Body.Length != 0) && (M_.Body.Length <= 4095) && (M_.Body.Min() != 0)) ))
                    {
                        throw new ValidationExprError(_targetVal, m_io, "/types/type_symlink/seq/1");
                    }
                }
            }
            private PaddedStr _targetKey;
            private PaddedBytes _targetVal;
            private NixNar m_root;
            private NixNar.Node m_parent;

            /// <summary>
            /// Must be `target`.
            /// </summary>
            public PaddedStr TargetKey { get { return _targetKey; } }

            /// <summary>
            /// 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.
            /// </summary>
            public PaddedBytes TargetVal { get { return _targetVal; } }
            public NixNar M_Root { get { return m_root; } }
            public NixNar.Node M_Parent { get { return m_parent; } }
        }
        private PaddedStr _magic;
        private Node _rootNode;
        private NixNar m_root;
        private KaitaiStruct m_parent;

        /// <summary>
        /// Magic string, must be `nix-archive-1`.
        /// </summary>
        public PaddedStr Magic { get { return _magic; } }

        /// <summary>
        /// The root of the archive, which is always a single node.
        /// </summary>
        public Node RootNode { get { return _rootNode; } }
        public NixNar M_Root { get { return m_root; } }
        public KaitaiStruct M_Parent { get { return m_parent; } }
    }
}