Crate libnixstore

Source
Expand description

§libnixstore

Is a library that provides simple access to your local nix store, based on c++ bindings. It mimics the already available perl bindings but also adds bindings on top, that might be useful.

Note: This project provides bindings, this makes the project automatically unsafe.

Supported nix version:

  • nix 2.8
  • nix 2.9
  • nix 2.10
  • nix 2.11

§Requirements

It is only available for systems that have the nix package manager installed. To achieve this you should setup a simple shell.nix

with import <nixpkgs> { };
stdenv.mkDerivation {
  name = "xyz";
  nativeBuildInputs = [ rustc cargo gcc pkg-config ];
  buildInputs = [
    # required
    nix
    nlohmann_json
    libsodium
    boost

    # additional packages you might need
    rustfmt
    clippy
    # ...
  ];

  RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}

§Example

fn main() {
    libnixstore::init();
    println!("{}", libnixstore::get_store_dir());
}

Structs§

Drv
PathInfo

Enums§

Radix
Nix’s libstore offers two options for representing the hash-part of store paths.

Functions§

add_temp_root
Add a store path as a temporary root of the garbage collector. The root disappears as soon as we exit.
add_to_store
This is the preparatory part of addToStore();
check_signature
Verify that sig is a valid signature for msg, using the signer’s public_key.
compute_fs_closure
Returns all store paths in the file system closure of storePath
convert_hash
Parse the hash from a string representation in the format [<type>:]<base16|base32|base64> or <type>-<base64> to a string representation of the hash, in base-16, base-32. The result is not prefixed by the hash type.
derivation_from_path
Read a derivation, after ensuring its existence through ensurePath().
dump_path
Dump a store path in NAR format. The data is passed in chunks to callback
export_paths
Export multiple paths in the format expected by nix-store --import.
follow_links_to_store_path
Follow symlinks until we end up with a path in the Nix store. Will transform the results to store paths.
get_bin_dir
Return the path to the directory where the main programs are stored.
get_build_log
Return the build log of the specified store path, if available, or null otherwise.
get_nar_list
Return a JSON representation as String of the contents of a NAR (except file contents).
get_store_dir
Returns the path to the directory where nix store sources and derived files.
hash_file
Compute the hash of the given file.
hash_path
Compute the hash of the given path. The hash is defined as (essentially) hashString(ht, dumpPath(path)).
hash_string
Compute the hash of the given string.
import_paths
Import a sequence of NAR dumps created by export_paths() into the Nix store. Optionally, the contents of the NARs are preloaded into the specified FS accessor to speed up subsequent access.
init
Perform any necessary effectful operation to make the store up and running.
is_valid_path
Check whether a path is valid.
make_fixed_output_path
query_deriver
Return deriver of a valid path. It is permitted to omit the name part of the store path.
query_path_from_hash_part
Query the full store path given the hash part of a valid store path, or empty if the path doesn’t exist.
query_path_hash
Return narhash of a valid path. It is permitted to omit the name part of the store path.
query_path_info
Query information about a valid path. It is permitted to omit the name part of the store path. The radix field affects only the narHash field of the result.
query_raw_realisation
Query the information about a realisation
query_references
Return references of a valid path. It is permitted to omit the name part of the store path.
set_verbosity
Set the loglevel.
sign_string
Return a detached signature of the given string.
topo_sort_paths
Sort a set of paths topologically under the references relation. If p refers to q, then p precedes q in this list.