The pkgdb search
command may be used to search for packages which match a
set of query
filters in a set of registry inputs.
This command accepts JSON input and emits JSON output, which are described below.
pkgdb
search accepts either a path to a JSON file or inline JSON with
the following abstract schema:
SearchQuery ::= {
name = null | <STRING>
pname = null | <STRING>
version = null | <STRING>
semver = null | <STRING>
match = null | <STRING>
match-name = null | <STRING>
}
SearchParams ::= {
manifest = null | <STRING> | Manifest
, global-manifest = <STRING> | GlobalManifest
, lockfile = null | <STRING> | Lockfile
, query = SearchQuery
}
SearchQuery
match-name
: Partially match a package'sname
orpname
fields as well as on a calculated columnattrName
.- May not be used with
match
. attrName
is the last attribute path element forpackages
andlegacyPackages
subtrees.- Exact matches cause search results to appear before ( higher ) than partial matches.
- May not be used with
match
: Partially match a package'sname
,pname
, ordescription
fields as well as on a calculated columnattrName
.- May not be used with
query.match-name
. attrName
is the last attribute path element forpackages
andlegacyPackages
subtrees.- Exact matches cause search results to appear before ( higher ) than partial matches.
- May not be used with
semver
: a node-semver range filter.- These use the exact syntax found in tools such as
npm
,yarn
,pip
, and many other package managers.
- These use the exact syntax found in tools such as
name
: Exactly match the derivation'sname
attribute.pname
: Exactly match the derivation'spname
attribute.- For derivations which lack a
pname
field it will be parsed from the derivation'sname
attribute usingbuiltins.parseDrvName
.
- For derivations which lack a
version
: Exactly match a derivation'sversion
field.- For derivations that lack a
version
field it will be parsed from the derivation'sname
attribute usingbuiltins.parseDrvName
.
- For derivations that lack a
manifest
: An optional path to a Manifest, or an inline JSON manifest.global-manifest
: A path to a GlobalManifest or an inline JSON GlobalManifest.- Note that this parameter is not optional, whereas
manifest
andlockfile
are.
- Note that this parameter is not optional, whereas
lockfile
: An optional path to an existing Lockfile, or an inline JSON Lockfile.
See the corresponding documentation for global manifests, manifests, and lockfiles for details on those schemas.
Below is an example query that searches four flakes for
any package matching the string "hello" with major version 2 , usable
on x86_64-linux
.
{
"global-manifest": "/path/to/global-manifest.toml"
, "query": { "match": "hello", "semver": "2" }
}
In the example above we'll make a few observations to clarify how defaults are
applied to inputs
by showing the explicit form of the same params:
{
"global-manifest": "/path/to/global-manifest.toml"
, "manifest": null,
, "lockfile": null,
, "query": {
"name": null
, "pname": null
, "version": null
, "semver": "2"
, "match": "hello"
, "match-name": null
}
}
inputs.<NAME>.subtrees
was applied to all inputs which didn't explicitly specify them.inputs.<NAME>.from
flake references were parsed and locked.allow
andsemver
fields were added with their default values.priority
list added missing inputs in lexicographical order.- in this case lexicographical is alphabetical because there are no numbers or symbols in the names.
- Missing
query.*
fields were filled withnull
.
Search results are printed as JSON objects with one result per line ordered such that high ranking results appear before low ranking results.
This single result per line format is printed in chunks as each input is
processed, and is suitable for streaming across a pipe.
Tools such as jq
or sed
may be used in combination with pkgdb search
so
that results are displayed to users as they are processed.
Each output line has the following format:
Result ::= {
id = <INT>
, input = <INPUT-NAME>
, subtree = "packages" | "legacyPackages"
, absPath = [<STRING>...]
, relPath = [<STRING>...]
, pname = <STRING>
, version = null | <STRING>
, description = null | <STRING>
, license = null | License
, broken = true | false
, unfree = true | false
}
Note that because the input
field only prints the short-name of its input,
it is strongly recommended that the caller use locked flake references.
For the example query parameters given above, we get the following results:
{"absPath":["legacyPackages","x86_64-linux","hello"],"broken":false,"description":"A program that produces a familiar, friendly greeting","id":6095,"input":"nixpkgs","license":"GPL-3.0-or-later","pname":"hello","relPath":["hello"],"subtree":"legacyPackages","system":"x86_64-linux","unfree":false,"version":"2.12.1"}