doc: manual fixup after migration

This commit is contained in:
Johannes Kirschbauer 2024-03-19 22:01:38 +01:00
parent f917ed536b
commit 56b5634a90
No known key found for this signature in database

View File

@ -63,11 +63,8 @@ rec {
::: :::
*/ */
attrByPath = attrByPath =
# A list of strings representing the attribute path to return from `set`
attrPath: attrPath:
# Default value if `attrPath` does not resolve to an existing value
default: default:
# The nested attribute set to select values from
set: set:
let let
lenAttrPath = length attrPath; lenAttrPath = length attrPath;
@ -134,9 +131,7 @@ rec {
::: :::
*/ */
hasAttrByPath = hasAttrByPath =
# A list of strings representing the attribute path to check from `set`
attrPath: attrPath:
# The nested attribute set to check
e: e:
let let
lenAttrPath = length attrPath; lenAttrPath = length attrPath;
@ -205,9 +200,7 @@ rec {
::: :::
*/ */
longestValidPathPrefix = longestValidPathPrefix =
# A list of strings representing the longest possible path that may be returned.
attrPath: attrPath:
# The nested attribute set to check.
v: v:
let let
lenAttrPath = length attrPath; lenAttrPath = length attrPath;
@ -270,9 +263,7 @@ rec {
::: :::
*/ */
setAttrByPath = setAttrByPath =
# A list of strings representing the attribute path to set
attrPath: attrPath:
# The value to set at the location described by `attrPath`
value: value:
let let
len = length attrPath; len = length attrPath;
@ -284,15 +275,15 @@ rec {
/** /**
Like `attrByPath`, but without a default value. If it doesn't find the Like `attrByPath`, but without a default value. If it doesn't find the
path it will throw an error. path it will throw an error.
Nix has an [attribute selection operator](https://nixos.org/manual/nix/stable/language/operators#attribute-selection) which is sufficient for such queries, as long as the number of attributes is static. For example: Nix has an [attribute selection operator](https://nixos.org/manual/nix/stable/language/operators#attribute-selection) which is sufficient for such queries, as long as the number of attributes is static. For example:
```nix ```nix
x.a.b == getAttrByPath ["a" "b"] x x.a.b == getAttrByPath ["a" "b"] x
# and # and
x.${f p}."example.com" == getAttrByPath [ (f p) "example.com" ] x x.${f p}."example.com" == getAttrByPath [ (f p) "example.com" ] x
``` ```
# Inputs # Inputs
@ -326,9 +317,7 @@ rec {
::: :::
*/ */
getAttrFromPath = getAttrFromPath =
# A list of strings representing the attribute path to get from `set`
attrPath: attrPath:
# The nested attribute set to find the value in.
set: set:
attrByPath attrPath (abort ("cannot find attribute `" + concatStringsSep "." attrPath + "'")) set; attrByPath attrPath (abort ("cannot find attribute `" + concatStringsSep "." attrPath + "'")) set;
@ -522,9 +511,7 @@ rec {
::: :::
*/ */
attrVals = attrVals =
# The list of attributes to fetch from `set`. Each attribute name must exist on the attrbitue set
nameList: nameList:
# The set to get attribute values from
set: map (x: set.${x}) nameList; set: map (x: set.${x}) nameList;
@ -585,9 +572,7 @@ rec {
::: :::
*/ */
getAttrs = getAttrs =
# A list of attribute names to get out of `set`
names: names:
# The set to get the named attributes from
attrs: genAttrs names (name: attrs.${name}); attrs: genAttrs names (name: attrs.${name});
/** /**
@ -647,9 +632,7 @@ rec {
::: :::
*/ */
filterAttrs = filterAttrs =
# Predicate taking an attribute name and an attribute value, which returns `true` to include the attribute, or `false` to exclude the attribute.
pred: pred:
# The attribute set to filter
set: set:
listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set)); listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));
@ -687,9 +670,7 @@ rec {
::: :::
*/ */
filterAttrsRecursive = filterAttrsRecursive =
# Predicate taking an attribute name and an attribute value, which returns `true` to include the attribute, or `false` to exclude the attribute.
pred: pred:
# The attribute set to filter
set: set:
listToAttrs ( listToAttrs (
concatMap (name: concatMap (name:
@ -709,9 +690,9 @@ rec {
The result of the callback function is often called `acc` for accumulator. It is passed between callbacks from left to right and the final `acc` is the return value of `foldlAttrs`. The result of the callback function is often called `acc` for accumulator. It is passed between callbacks from left to right and the final `acc` is the return value of `foldlAttrs`.
Attention: Attention:
There is a completely different function
`lib.foldAttrs` There is a completely different function `lib.foldAttrs`
which has nothing to do with this function, despite the similar name. which has nothing to do with this function, despite the similar name.
# Inputs # Inputs
@ -824,11 +805,8 @@ rec {
::: :::
*/ */
foldAttrs = foldAttrs =
# A function, given a value and a collector combines the two.
op: op:
# The starting value.
nul: nul:
# A list of attribute sets to fold together by key.
list_of_attrs: list_of_attrs:
foldr (n: a: foldr (n: a:
foldr (name: o: foldr (name: o:
@ -839,7 +817,7 @@ rec {
/** /**
Recursively collect sets that verify a given predicate named `pred` Recursively collect sets that verify a given predicate named `pred`
from the set `attrs`. The recursion is stopped when the predicate is from the set `attrs`. The recursion is stopped when the predicate is
verified. verified.
@ -875,10 +853,8 @@ rec {
::: :::
*/ */
collect = collect =
# Given an attribute's value, determine if recursion should stop. pred:
pred: attrs:
# The attribute set to recursively collect.
attrs:
if pred attrs then if pred attrs then
[ attrs ] [ attrs ]
else if isAttrs attrs then else if isAttrs attrs then
@ -919,7 +895,6 @@ rec {
::: :::
*/ */
cartesianProductOfSets = cartesianProductOfSets =
# Attribute set with attributes that are lists of values
attrsOfLists: attrsOfLists:
foldl' (listOfAttrs: attrName: foldl' (listOfAttrs: attrName:
concatMap (attrs: concatMap (attrs:
@ -960,9 +935,7 @@ rec {
::: :::
*/ */
nameValuePair = nameValuePair =
# Attribute name
name: name:
# Attribute value
value: value:
{ inherit name value; }; { inherit name value; };
@ -1026,9 +999,7 @@ rec {
::: :::
*/ */
mapAttrs' = mapAttrs' =
# A function, given an attribute's name and value, returns a new `nameValuePair`.
f: f:
# Attribute set to map over.
set: set:
listToAttrs (map (attr: f attr set.${attr}) (attrNames set)); listToAttrs (map (attr: f attr set.${attr}) (attrNames set));
@ -1037,7 +1008,6 @@ rec {
Call a function for each attribute in the given set and return Call a function for each attribute in the given set and return
the result in a list. the result in a list.
# Inputs # Inputs
`f` `f`
@ -1067,9 +1037,7 @@ rec {
::: :::
*/ */
mapAttrsToList = mapAttrsToList =
# A function, given an attribute's name and value, returns a new value.
f: f:
# Attribute set to map over.
attrs: attrs:
map (name: f name attrs.${name}) (attrNames attrs); map (name: f name attrs.${name}) (attrNames attrs);
@ -1139,9 +1107,7 @@ rec {
``` ```
*/ */
mapAttrsRecursive = mapAttrsRecursive =
# A function that, given an attribute path as a list of strings and the corresponding attribute value, returns a new value.
f: f:
# Attribute set to recursively map over.
set: set:
mapAttrsRecursiveCond (as: true) f set; mapAttrsRecursiveCond (as: true) f set;
@ -1170,12 +1136,8 @@ rec {
``` ```
*/ */
mapAttrsRecursiveCond = mapAttrsRecursiveCond =
# A function that, given the attribute set the recursion is currently at, determines if to recurse deeper into that attribute set.
cond: cond:
# A function that, given an attribute path as a list of strings and the corresponding attribute value, returns a new value.
# The attribute value is either an attribute set for which `cond` returns false, or something other than an attribute set.
f: f:
# Attribute set to recursively map over.
set: set:
let let
recurse = path: recurse = path:
@ -1221,9 +1183,7 @@ rec {
::: :::
*/ */
genAttrs = genAttrs =
# Names of values in the resulting attribute set.
names: names:
# A function, given the name of the attribute, returns the attribute's value.
f: f:
listToAttrs (map (n: nameValuePair n (f n)) names); listToAttrs (map (n: nameValuePair n (f n)) names);
@ -1260,7 +1220,6 @@ rec {
::: :::
*/ */
isDerivation = isDerivation =
# Value to check.
value: value.type or null == "derivation"; value: value.type or null == "derivation";
/** /**
@ -1280,7 +1239,6 @@ rec {
``` ```
*/ */
toDerivation = toDerivation =
# A store path to convert to a derivation.
path: path:
let let
path' = builtins.storePath path; path' = builtins.storePath path;
@ -1330,9 +1288,7 @@ rec {
::: :::
*/ */
optionalAttrs = optionalAttrs =
# Condition under which the `as` attribute set is returned.
cond: cond:
# The attribute set to return if `cond` is `true`.
as: as:
if cond then as else {}; if cond then as else {};
@ -1374,11 +1330,8 @@ rec {
::: :::
*/ */
zipAttrsWithNames = zipAttrsWithNames =
# List of attribute names to zip.
names: names:
# A function, accepts an attribute name, all the values, and returns a combined value.
f: f:
# List of values from the list of attribute sets.
sets: sets:
listToAttrs (map (name: { listToAttrs (map (name: {
inherit name; inherit name;
@ -1551,11 +1504,8 @@ rec {
::: :::
*/ */
recursiveUpdateUntil = recursiveUpdateUntil =
# Predicate, taking the path to the current attribute as a list of strings for attribute names, and the two values at that path from the original arguments.
pred: pred:
# Left attribute set of the merge.
lhs: lhs:
# Right attribute set of the merge.
rhs: rhs:
let f = attrPath: let f = attrPath:
zipAttrsWith (n: values: zipAttrsWith (n: values:
@ -1613,9 +1563,7 @@ rec {
::: :::
*/ */
recursiveUpdate = recursiveUpdate =
# Left attribute set of the merge.
lhs: lhs:
# Right attribute set of the merge.
rhs: rhs:
recursiveUpdateUntil (path: lhs: rhs: !(isAttrs lhs && isAttrs rhs)) lhs rhs; recursiveUpdateUntil (path: lhs: rhs: !(isAttrs lhs && isAttrs rhs)) lhs rhs;
@ -1654,9 +1602,7 @@ rec {
::: :::
*/ */
matchAttrs = matchAttrs =
# Attribute set structure to match
pattern: pattern:
# Attribute set to check
attrs: attrs:
assert isAttrs pattern; assert isAttrs pattern;
all all
@ -1712,9 +1658,7 @@ rec {
::: :::
*/ */
overrideExisting = overrideExisting =
# Original attribute set
old: old:
# Attribute set with attributes to override in `old`.
new: new:
mapAttrs (name: value: new.${name} or value) old; mapAttrs (name: value: new.${name} or value) old;
@ -1752,7 +1696,6 @@ rec {
::: :::
*/ */
showAttrPath = showAttrPath =
# Attribute path to render to a string
path: path:
if path == [] then "<root attribute path>" if path == [] then "<root attribute path>"
else concatMapStringsSep "." escapeNixIdentifier path; else concatMapStringsSep "." escapeNixIdentifier path;
@ -1937,7 +1880,6 @@ rec {
::: :::
*/ */
recurseIntoAttrs = recurseIntoAttrs =
# An attribute set to scan for derivations.
attrs: attrs:
attrs // { recurseForDerivations = true; }; attrs // { recurseForDerivations = true; };
@ -1958,7 +1900,6 @@ rec {
``` ```
*/ */
dontRecurseIntoAttrs = dontRecurseIntoAttrs =
# An attribute set to not scan for derivations.
attrs: attrs:
attrs // { recurseForDerivations = false; }; attrs // { recurseForDerivations = false; };