-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add documentation for NAR spec in kaitai #14345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| meta: | ||
| id: nix_nar | ||
| title: Nix Archive (NAR) | ||
| file-extension: nar | ||
| endian: le | ||
| doc: | | ||
| Nix Archive (NAR) format. A simple, reproducible binary archive | ||
| format used by the Nix package manager to serialize file system objects. | ||
| doc-ref: 'https://nixos.org/manual/nix/stable/command-ref/nix-store.html#nar-format' | ||
|
|
||
| seq: | ||
| - id: magic | ||
| type: padded_str | ||
| doc: "Magic string, must be 'nix-archive-1'." | ||
| valid: | ||
| expr: _.body == 'nix-archive-1' | ||
| - id: root_node | ||
| type: node | ||
| doc: "The root of the archive, which is always a single node." | ||
|
|
||
| types: | ||
| padded_str: | ||
| doc: | | ||
| A string, prefixed with its length (u8le) and | ||
| padded with null bytes to the next 8-byte boundary. | ||
| seq: | ||
| - id: len_str | ||
| type: u8 | ||
| - id: body | ||
| type: str | ||
| size: len_str | ||
| encoding: 'ascii' | ||
| - id: padding | ||
| size: (8 - (len_str % 8)) % 8 | ||
|
|
||
| node: | ||
| doc: "A single filesystem node (file, directory, or symlink)." | ||
| seq: | ||
| - id: open_paren | ||
| type: padded_str | ||
| doc: "Must be '(', a token starting the node definition." | ||
| valid: | ||
| expr: _.body == '(' | ||
| - id: type_key | ||
| type: padded_str | ||
| doc: "Must be 'type'." | ||
| valid: | ||
| expr: _.body == 'type' | ||
| - id: type_val | ||
| type: padded_str | ||
| doc: "The type of the node: 'regular', 'directory', or 'symlink'." | ||
| - id: body | ||
| type: | ||
| switch-on: type_val.body | ||
| cases: | ||
| "'directory'": type_directory | ||
| "'regular'": type_regular | ||
| "'symlink'": type_symlink | ||
| - id: close_paren | ||
| type: padded_str | ||
| valid: | ||
| expr: _.body == ')' | ||
| if: "type_val.body != 'directory'" | ||
| doc: "Must be ')', a token ending the node definition." | ||
|
|
||
| type_directory: | ||
| doc: "A directory node, containing a list of entries. Entries must be ordered by their names." | ||
| seq: | ||
| - id: entries | ||
| type: dir_entry | ||
| repeat: until | ||
| repeat-until: _.kind.body == ')' | ||
| types: | ||
| dir_entry: | ||
| doc: "A single entry within a directory, or a terminator." | ||
| seq: | ||
fzakaria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - id: kind | ||
| type: padded_str | ||
| valid: | ||
| expr: _.body == 'entry' or _.body == ')' | ||
| doc: "Must be 'entry' (for a child node) or '' (for terminator)." | ||
| - id: open_paren | ||
| type: padded_str | ||
| valid: | ||
| expr: _.body == '(' | ||
| if: 'kind.body == "entry"' | ||
| - id: name_key | ||
| type: padded_str | ||
| valid: | ||
| expr: _.body == 'name' | ||
| if: 'kind.body == "entry"' | ||
| - id: name | ||
| type: padded_str | ||
| if: 'kind.body == "entry"' | ||
| - id: node_key | ||
| type: padded_str | ||
| valid: | ||
| expr: _.body == 'node' | ||
| if: 'kind.body == "entry"' | ||
| - id: node | ||
| type: node | ||
| if: 'kind.body == "entry"' | ||
| doc: "The child node, present only if kind is 'entry'." | ||
| - id: close_paren | ||
| type: padded_str | ||
| valid: | ||
| expr: _.body == ')' | ||
| if: 'kind.body == "entry"' | ||
| instances: | ||
| is_terminator: | ||
| value: kind.body == ')' | ||
|
|
||
| type_regular: | ||
| doc: "A regular file node." | ||
| seq: | ||
| # Read attributes (like 'executable') until we hit 'contents' | ||
| - id: attributes | ||
| type: reg_attribute | ||
| repeat: until | ||
| repeat-until: _.key.body == "contents" | ||
| # After the 'contents' token, read the file data | ||
| - id: file_data | ||
| type: file_content | ||
| instances: | ||
| is_executable: | ||
| value: 'attributes[0].key.body == "executable"' | ||
| doc: "True if the file has the 'executable' attribute." | ||
| types: | ||
| reg_attribute: | ||
| doc: "An attribute of the file, e.g., 'executable' or 'contents'." | ||
| seq: | ||
| - id: key | ||
| type: padded_str | ||
| doc: "Attribute key, e.g., 'executable' or 'contents'." | ||
| valid: | ||
| expr: _.body == 'executable' or _.body == 'contents' | ||
| - id: value | ||
| type: padded_str | ||
| if: 'key.body == "executable"' | ||
| valid: | ||
| expr: _.body == '' | ||
| doc: "Must be '' if key is 'executable'." | ||
| file_content: | ||
| doc: "The raw data of the file, prefixed by length." | ||
| seq: | ||
| - id: len_contents | ||
| type: u8 | ||
| # # This relies on the property of instances that they are lazily evaluated and cached. | ||
| - size: 0 | ||
| if: nar_offset < 0 | ||
| - id: contents | ||
| size: len_contents | ||
| - id: padding | ||
| size: (8 - (len_contents % 8)) % 8 | ||
| instances: | ||
| nar_offset: | ||
| value: _io.pos | ||
|
|
||
| type_symlink: | ||
| doc: "A symbolic link node." | ||
| seq: | ||
| - id: target_key | ||
| type: padded_str | ||
| doc: "Must be 'target'." | ||
| valid: | ||
| expr: _.body == 'target' | ||
| - id: target_val | ||
| type: padded_str | ||
| doc: "The destination path of the symlink." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../.version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Run with: | ||
| # meson test --suite kaitai-struct | ||
| # Run with: (without shell / configure) | ||
| # nix build .#nix-kaitai-struct-checks | ||
|
|
||
| project( | ||
| 'nix-kaitai-struct-checks', | ||
| 'cpp', | ||
| version : files('.version'), | ||
| default_options : [ | ||
| 'cpp_std=c++23', | ||
| # TODO(Qyriad): increase the warning level | ||
| 'warning_level=1', | ||
| 'errorlogs=true', # Please print logs for tests that fail | ||
| ], | ||
| meson_version : '>= 1.1', | ||
| license : 'LGPL-2.1-or-later', | ||
| ) | ||
|
|
||
| kaitai_runtime_dep = dependency('kaitai-struct-cpp-stl-runtime', required : true) | ||
| gtest_dep = dependency('gtest') | ||
| gtest_main_dep = dependency('gtest_main', required : true) | ||
|
|
||
| # Find the Kaitai Struct compiler | ||
| ksc = find_program('ksc', required : true) | ||
|
|
||
| kaitai_generated_srcs = custom_target( | ||
| 'kaitai-generated-sources', | ||
| input : [ 'nar.ksy' ], | ||
| output : [ 'nix_nar.cpp', 'nix_nar.h' ], | ||
| command : [ | ||
| ksc, | ||
| '@INPUT@', | ||
| '--target', 'cpp_stl', | ||
| '--outdir', | ||
| meson.current_build_dir(), | ||
| ], | ||
| ) | ||
|
|
||
| nar_kaitai_lib = library( | ||
| 'nix-nar-kaitai-lib', | ||
| kaitai_generated_srcs, | ||
| dependencies : [ kaitai_runtime_dep ], | ||
| install : true, | ||
| ) | ||
|
|
||
| nar_kaitai_dep = declare_dependency( | ||
| link_with : nar_kaitai_lib, | ||
| sources : kaitai_generated_srcs[1], | ||
| ) | ||
|
|
||
| # The nar directory is a committed symlink to the actual nars location | ||
| nars_dir = meson.current_source_dir() / 'nars' | ||
|
|
||
| # Get all example files | ||
| nars = [ | ||
| 'dot.nar', | ||
| ] | ||
|
|
||
| test_deps = [ | ||
| nar_kaitai_dep, | ||
| kaitai_runtime_dep, | ||
| gtest_main_dep, | ||
| ] | ||
|
|
||
| this_exe = executable( | ||
| meson.project_name(), | ||
| 'test-parse-nar.cc', | ||
| dependencies : test_deps, | ||
| ) | ||
|
|
||
| test( | ||
| meson.project_name(), | ||
| this_exe, | ||
| env : [ 'NIX_NARS_DIR=' + nars_dir ], | ||
| protocol : 'gtest', | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../doc/manual/source/protocols/nix-archive/nar.ksy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../libutil-tests/data/nars |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../nix-meson-build-support |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.