Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
Classes | Concepts | Typedefs | Functions | Variables
flox::pkgdb Namespace Reference

Interfaces for caching package metadata in SQLite3 databases. More...

Classes

class  DbPackage
 Package metadata loaded from a ‘PkgDb’ cache. More...
 
struct  DbPathMixin
 Adds a single package database path to a state blob. More...
 
class  GetCommand
 Minimal set of DB queries, largely focused on looking up info that is non-trivial to query with a "plain" SQLite statement. More...
 
class  ListCommand
 
class  PkgDb
 A SQLite3 database used to cache derivation/package information about a single locked flake. More...
 
class  PkgDbInput
 A RegistryInput that opens a PkgDb associated with a flake. More...
 
class  PkgDbInputFactory
 Factory for PkgDbInput. More...
 
struct  PkgDbMixin
 Adds a single package database and optionally an associated flake to a state blob. More...
 
class  PkgDbReadOnly
 A SQLite3 database used to cache derivation/package information about a single locked flake. More...
 
class  PkgDbRegistryMixin
 Provides a registry of PkgDb managers. More...
 
class  PkgQuery
 A query used to lookup packages in a database. More...
 
class  ScrapeCommand
 Scrape a flake prefix producing a SQLite3 database with package metadata. More...
 
struct  SqlVersions
 SQLite3 schema versions. More...
 

Concepts

concept  pkgdb_typename
 Restricts template parameters to classes that extend flox::pkgdb::PkgDbReadOnly.
 

Typedefs

using row_id = uint64_t
 
using Fingerprint = nix::flake::Fingerprint
 
using SQLiteDb = sqlite3pp::database
 
using sql_rc = int
 
using Target = std::tuple< flox::AttrPath, flox::Cursor, row_id >
 A set of arguments used by flox::pkgdb::PkgDb::scrape.
 
using Todos = std::queue< Target, std::list< Target > >
 A queue of flox::pkgdb::Target to be completed.
 

Functions

void to_json (nlohmann::json &jto, const PkgQueryArgs &descriptor)
 Convert an flox::pkgdb::PkgQueryArgs to a JSON object.
 
static void addIn (std::stringstream &oss, const std::vector< std::string > &elems)
 
void prim_getFingerprint (nix::EvalState &state, const nix::PosIdx pos, nix::Value **args, nix::Value &value)
 Lookup a flake's fingerprint hash.
 
static nix::RegisterPrimOp primop_getFingerprint ({ .name="__getFingerprint",.args={ "flakeRef" },.arity=0,.doc=R"( This hash uniquely identifies a revision of a locked flake. Takes a single argument: - `flakeRef`: Either an attribute set or string flake-ref. )",.fun=prim_getFingerprint,.experimentalFeature=nix::Xp::Flakes })
 
bool isSQLError (int rcode)
 Predicate to detect failing SQLite3 return codes.
 
std::ostream & operator<< (std::ostream &oss, const SqlVersions &versions)
 Emit version information to an output stream.
 
std::filesystem::path getPkgDbCachedir ()
 Get the default pkgdb cache directory to save databases.
 
std::filesystem::path genPkgDbName (const Fingerprint &fingerprint, const std::filesystem::path &cacheDir=getPkgDbCachedir())
 Get an absolute path to the ‘PkgDb’ for a given fingerprint hash.
 

Variables

constexpr SqlVersions sqlVersions = { .tables = 2, .views = 3 }
 

Detailed Description

Interfaces for caching package metadata in SQLite3 databases.

Typedef Documentation

◆ Fingerprint

using flox::pkgdb::Fingerprint = typedef nix::flake::Fingerprint

A unique hash associated with a locked flake.

◆ row_id

using flox::pkgdb::row_id = typedef uint64_t

A row index in a SQLite3 table.

◆ sql_rc

using flox::pkgdb::sql_rc = typedef int

SQLITE_* result code.

Function Documentation

◆ getPkgDbCachedir()

std::filesystem::path flox::pkgdb::getPkgDbCachedir ( )

Get the default pkgdb cache directory to save databases.

The environment variable PKGDB_CACHEDIR is respected if it is set, otherwise we use ${XDG_CACHE_HOME:-$HOME/.cache}/flox/pkgdb-v<SCHEMA-MAJOR>.

◆ isSQLError()

bool flox::pkgdb::isSQLError ( int  rcode)

Predicate to detect failing SQLite3 return codes.

Parameters
rcodeA SQLite3 return code.
Returns
true iff rc is a SQLite3 error.

◆ prim_getFingerprint()

void flox::pkgdb::prim_getFingerprint ( nix::EvalState &  state,
const nix::PosIdx  pos,
nix::Value **  args,
nix::Value &  value 
)

Lookup a flake's fingerprint hash.

This hash uniquely identifies a revision of a locked flake.

Takes a single argument flakeRef: Either an attribute set or string.

Parameters
stateThe nix evaluator's state.
posThe position ( file name and line/column numbers ) of the call. This is generally used for error reporting.
argsThe arguments to the primitive.
valueAn allocated nix::Value to store the result in.

Variable Documentation

◆ sqlVersions

constexpr SqlVersions flox::pkgdb::sqlVersions = { .tables = 2, .views = 3 }
constexpr

The current SQLite3 schema versions.