Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::StructuredAttrs Struct Reference

Public Member Functions

bool operator== (const StructuredAttrs &other) const
std::pair< std::string_view, std::string > unparse () const
nlohmann::json::object_t prepareStructuredAttrs (Store &store, const derivation::Options< StorePath > &drvOptions, const StorePathSet &inputPaths, const std::map< std::string, derivation::Output > &outputs) const

Static Public Member Functions

static StructuredAttrs parse (std::string_view encoded)
static std::optional< StructuredAttrs > tryExtract (StringPairs &env)
static void checkKeyNotInUse (const StringPairs &env)
static std::string writeShell (const nlohmann::json::object_t &prepared)

Public Attributes

nlohmann::json::object_t structuredAttrs
std::optional< std::string > verbatim

Static Public Attributes

static constexpr std::string_view envVarName {"__json"}

Member Function Documentation

◆ checkKeyNotInUse()

void nix::StructuredAttrs::checkKeyNotInUse ( const StringPairs & env)
static

Ensures that the structured attrs "env var" is not in used, so we are free to use it instead.

◆ operator==()

bool nix::StructuredAttrs::operator== ( const StructuredAttrs & other) const

Compares encodings, not just values, since that is what must round-trip. Dumping is only needed when exactly one side has a verbatim encoding to compare against.

◆ parse()

StructuredAttrs nix::StructuredAttrs::parse ( std::string_view encoded)
static

Unconditionally parse from a JSON string. Used by tryExtract.

◆ tryExtract()

std::optional< StructuredAttrs > nix::StructuredAttrs::tryExtract ( StringPairs & env)
static

Like tryParse, but removes the env var which encoded the structured attrs from the map if one is found.

◆ unparse()

std::pair< std::string_view, std::string > nix::StructuredAttrs::unparse ( ) const

Opposite of tryParse, at least if one makes a map from this single key-value PR.

◆ writeShell()

std::string nix::StructuredAttrs::writeShell ( const nlohmann::json::object_t & prepared)
static

As a convenience to bash scripts, write a shell file that maps all attributes that are representable in bash - namely, strings, integers, nulls, Booleans, and arrays and objects consisting entirely of those values. (So nested arrays or objects are not supported.)

Parameters
preparedThis should be the result of prepareStructuredAttrs, not the original structuredAttrs field.

Member Data Documentation

◆ verbatim

std::optional<std::string> nix::StructuredAttrs::verbatim

The encoding we parsed, kept verbatim because it was not the canonical one unparse would produce. Derivations in the wild predate us caring about this, and their encoding is part of their identity, so we must be able to reproduce it exactly.


The documentation for this struct was generated from the following files: