Attribute-Set Functions
<function>lib.attrset.attrByPath</function> attrByPath :: [String] -> Any -> AttrSet Return an attribute from within nested attribute sets. attrPath A list of strings representing the path through the nested attribute set set. default Default value if attrPath does not resolve to an existing value. set The nested attributeset to select values from. Extracting a value from a nested attribute set 3 ]]> No value at the path, instead using the default 0 ]]>
<function>lib.attrsets.hasAttrByPath</function> hasAttrByPath :: [String] -> AttrSet -> Bool Determine if an attribute exists within a nested attribute set. attrPath A list of strings representing the path through the nested attribute set set. set The nested attributeset to check. A nested value does exist inside a set true ]]>
<function>lib.attrsets.setAttrByPath</function> setAttrByPath :: [String] -> Any -> AttrSet Create a new attribute set with value set at the nested attribute location specified in attrPath. attrPath A list of strings representing the path through the nested attribute set. value The value to set at the location described by attrPath. Creating a new nested attribute set { a = { b = 3; }; } ]]>
<function>lib.attrsets.getAttrFromPath</function> getAttrFromPath :: [String] -> AttrSet -> Value Like except without a default, and it will throw if the value doesn't exist. attrPath A list of strings representing the path through the nested attribute set set. set The nested attribute set to find the value in. Succesfully getting a value from an attribute set 3 ]]> Throwing after failing to get a value from an attribute set error: cannot find attribute `x.y' ]]>
<function>lib.attrsets.attrVals</function> attrVals :: [String] -> AttrSet -> [Any] Return the specified attributes from a set. All values must exist. nameList The list of attributes to fetch from set. Each attribute name must exist on the attrbitue set. set The set to get attribute values from. Getting several values from an attribute set [ 1 2 3 ] ]]> Getting missing values from an attribute set
<function>lib.attrsets.attrValues</function> attrValues :: AttrSet -> [Any] Get all the attribute values from an attribute set. Provides a backwards-compatible interface of builtins.attrValues for Nix version older than 1.8. attrs The attribute set. [ 1 2 3 ] ]]>
<function>lib.attrsets.catAttrs</function> catAttrs :: String -> AttrSet -> [Any] Collect each attribute named `attr' from the list of attribute sets, sets. Sets that don't contain the named attribute are ignored. Provides a backwards-compatible interface of builtins.catAttrs for Nix version older than 1.9. attr Attribute name to select from each attribute set in sets. sets The list of attribute sets to select attr from. Collect an attribute from a list of attribute sets. Attribute sets which don't have the attribute are ignored. [ 1 2 ] ]]>
<function>lib.attrsets.filterAttrs</function> filterAttrs :: (String -> Any -> Bool) -> AttrSet -> AttrSet Filter an attribute set by removing all attributes for which the given predicate return false. pred String -> Any -> Bool Predicate which returns true to include an attribute, or returns false to exclude it. name The attribute's name value The attribute's value Returns true to include the attribute, false to exclude the attribute. set The attribute set to filter Filtering an attributeset { foo = 1; } ]]>
<function>lib.attrsets.filterAttrsRecursive</function> filterAttrsRecursive :: (String -> Any -> Bool) -> AttrSet -> AttrSet Filter an attribute set recursively by removing all attributes for which the given predicate return false. pred String -> Any -> Bool Predicate which returns true to include an attribute, or returns false to exclude it. name The attribute's name value The attribute's value Returns true to include the attribute, false to exclude the attribute. set The attribute set to filter Recursively filtering an attribute set { levelA = { example = "hi"; levelB = { hello = "there"; this-one-is-present = { }; }; }; } ]]>
<function>lib.attrsets.foldAttrs</function> foldAttrs :: (Any -> Any -> Any) -> Any -> [AttrSets] -> Any Apply fold function to values grouped by key. op Any -> Any -> Any Given a value val and a collector col, combine the two. val An attribute's value col The result of previous op calls with other values and nul. nul The null-value, the starting value. list_of_attrs A list of attribute sets to fold together by key. Combining an attribute of lists in to one attribute set { a = [ 2 3 ]; b = [ 7 6 ]; } ]]>
<function>lib.attrsets.collect</function> collect :: (Any -> Bool) -> AttrSet -> [Any] Recursively collect sets that verify a given predicate named pred from the set attrs. The recursion stops when pred returns true. pred Any -> Bool Given an attribute's value, determine if recursion should stop. value The attribute set value. attrs The attribute set to recursively collect. Collecting all lists from an attribute set [["b"] [1]] ]]> Collecting all attribute-sets which contain the <literal>outPath</literal> attribute name. [{ outPath = "a/"; } { outPath = "b/"; }] ]]>
<function>lib.attrsets.nameValuePair</function> nameValuePair :: String -> Any -> AttrSet Utility function that creates a {name, value} pair as expected by builtins.listToAttrs. name The attribute name. value The attribute value. Creating a name value pair { name = "some"; value = 6; } ]]>
<function>lib.attrsets.mapAttrs</function> Apply a function to each element in an attribute set, creating a new attribute set. Provides a backwards-compatible interface of builtins.mapAttrs for Nix version older than 2.1. fn String -> Any -> Any Given an attribute's name and value, return a new value. name The name of the attribute. value The attribute's value. Modifying each value of an attribute set { x = "x-foo"; y = "y-bar"; } ]]>
<function>lib.attrsets.mapAttrs'</function> mapAttrs' :: (String -> Any -> { name = String; value = Any }) -> AttrSet -> AttrSet Like mapAttrs, but allows the name of each attribute to be changed in addition to the value. The applied function should return both the new name and value as a nameValuePair. fn String -> Any -> { name = String; value = Any } Given an attribute's name and value, return a new name value pair. name The name of the attribute. value The attribute's value. set The attribute set to map over. Change the name and value of each attribute of an attribute set { foo_x = "bar-a"; foo_y = "bar-b"; } ]]>
<function>lib.attrsets.mapAttrsToList</function> mapAttrsToList :: (String -> Any -> Any) -> AttrSet -> Any Call fn for each attribute in the given set and return the result in a list. fn String -> Any -> Any Given an attribute's name and value, return a new value. name The name of the attribute. value The attribute's value. set The attribute set to map over. Combine attribute values and names in to a list [ "x=a" "y=b" ] ]]>
<function>lib.attrsets.mapAttrsRecursive</function> mapAttrsRecursive :: ([String] > Any -> Any) -> AttrSet -> AttrSet Like mapAttrs, except that it recursively applies itself to attribute sets. Also, the first argument of the argument function is a list of the names of the containing attributes. f [ String ] -> Any -> Any Given a list of attribute names and value, return a new value. name_path The list of attribute names to this value. For example, the name_path for the example string in the attribute set { foo = { bar = "example"; }; } is [ "foo" "bar" ]. value The attribute's value. set The attribute set to recursively map over. A contrived example of using <function>lib.attrsets.mapAttrsRecursive</function> { n = { a = "n-a-A"; m = { b = "n-m-b-B"; c = "n-m-c-C"; }; }; d = "d-D"; } ]]>
<function>lib.attrsets.mapAttrsRecursiveCond</function> mapAttrsRecursiveCond :: (AttrSet -> Bool) -> ([ String ] -> Any -> Any) -> AttrSet -> AttrSet Like mapAttrsRecursive, but it takes an additional predicate function that tells it whether to recursive into an attribute set. If it returns false, mapAttrsRecursiveCond does not recurse, but does apply the map function. It is returns true, it does recurse, and does not apply the map function. cond (AttrSet -> Bool) Determine if mapAttrsRecursive should recurse deeper in to the attribute set. attributeset An attribute set. f [ String ] -> Any -> Any Given a list of attribute names and value, return a new value. name_path The list of attribute names to this value. For example, the name_path for the example string in the attribute set { foo = { bar = "example"; }; } is [ "foo" "bar" ]. value The attribute's value. set The attribute set to recursively map over. Only convert attribute values to JSON if the containing attribute set is marked for recursion { dorecur = { hello = "\"there\""; recurse = "true"; }; dontrecur = "{\"converted-to\":\"json\"}"; } ]]>