Merge pull request #207227 from hsjobeki/docs/fix-attrsets

Docs/fix attrsets

authored by

Silvan Mosberger and committed by
GitHub
4a816921 a5b85eb4

+38 -27
+36 -25
lib/attrsets.nix
··· 16 17 Example: 18 x = { a = { b = 3; }; } 19 attrByPath ["a" "b"] 6 x 20 => 3 21 attrByPath ["z" "z"] 6 x ··· 23 24 Type: 25 attrByPath :: [String] -> Any -> AttrSet -> Any 26 */ 27 attrByPath = 28 # A list of strings representing the attribute path to return from `set` ··· 96 => error: cannot find attribute `z.z' 97 98 Type: 99 - getAttrFromPath :: [String] -> AttrSet -> Value 100 */ 101 getAttrFromPath = 102 # A list of strings representing the attribute path to get from `set` ··· 109 /* Map each attribute in the given set and merge them into a new attribute set. 110 111 Type: 112 - concatMapAttrs :: 113 - (String -> a -> AttrSet) 114 - -> AttrSet 115 - -> AttrSet 116 117 Example: 118 concatMapAttrs ··· 168 ] { a.b.c = 0; } 169 => { a = { b = { d = 1; }; }; x = { y = "xy"; }; } 170 171 - Type: 172 - updateManyAttrsByPath :: [AttrSet] -> AttrSet -> AttrSet 173 */ 174 updateManyAttrsByPath = let 175 # When recursing into attributes, instead of updating the `path` of each ··· 252 Example: 253 attrValues {c = 3; a = 1; b = 2;} 254 => [1 2 3] 255 Type: 256 attrValues :: AttrSet -> [Any] 257 */ ··· 341 342 Type: 343 foldAttrs :: (Any -> Any -> Any) -> Any -> [AttrSets] -> Any 344 */ 345 foldAttrs = 346 # A function, given a value and a collector combines the two. ··· 394 { a = 2; b = 20; } 395 ] 396 Type: 397 - cartesianProductOfSets :: AttrSet -> [AttrSet] 398 */ 399 cartesianProductOfSets = 400 # Attribute set with attributes that are lists of values ··· 413 => { name = "some"; value = 6; } 414 415 Type: 416 - nameValuePair :: String -> Any -> AttrSet 417 */ 418 nameValuePair = 419 # Attribute name ··· 600 => { } 601 602 Type: 603 - optionalAttrs :: Bool -> AttrSet 604 */ 605 optionalAttrs = 606 # Condition under which the `as` attribute set is returned. ··· 646 => { a = ["x" "y"]; b = ["z"] } 647 648 Type: 649 - zipAttrsWith :: (String -> [ Any ] -> Any) -> [ AttrSet ] -> AttrSet 650 */ 651 zipAttrsWith = 652 builtins.zipAttrsWith or (f: sets: zipAttrsWithNames (concatMap attrNames sets) f sets); ··· 737 } 738 739 Type: 740 - recursiveUpdate :: AttrSet -> AttrSet -> AttrSet 741 */ 742 recursiveUpdate = 743 # Left attribute set of the merge. ··· 795 /* Turns a list of strings into a human-readable description of those 796 strings represented as an attribute path. The result of this function is 797 not intended to be machine-readable. 798 799 Example: 800 showAttrPath [ "foo" "10" "bar" ] ··· 831 If the output does not exist, fallback to `.out` and then to the default. 832 833 Example: 834 - getOutput pkgs.openssl 835 => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r" 836 837 Type: 838 - getOutput :: Derivation -> String 839 */ 840 getBin = getOutput "bin"; 841 ··· 844 If the output does not exist, fallback to `.out` and then to the default. 845 846 Example: 847 - getOutput pkgs.openssl 848 => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-lib" 849 850 Type: 851 - getOutput :: Derivation -> String 852 */ 853 getLib = getOutput "lib"; 854 ··· 857 If the output does not exist, fallback to `.out` and then to the default. 858 859 Example: 860 - getOutput pkgs.openssl 861 => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-dev" 862 863 Type: 864 - getOutput :: Derivation -> String 865 */ 866 getDev = getOutput "dev"; 867 ··· 870 If the output does not exist, fallback to `.out` and then to the default. 871 872 Example: 873 - getOutput pkgs.openssl 874 => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-man" 875 876 Type: 877 - getOutput :: Derivation -> String 878 */ 879 getMan = getOutput "man"; 880 881 - /* Pick the outputs of packages to place in `buildInputs` */ 882 chooseDevOutputs = 883 # List of packages to pick `dev` outputs from 884 drvs: ··· 900 901 Type: 902 recurseIntoAttrs :: AttrSet -> AttrSet 903 */ 904 recurseIntoAttrs = 905 # An attribute set to scan for derivations. ··· 909 /* Undo the effect of recurseIntoAttrs. 910 911 Type: 912 - recurseIntoAttrs :: AttrSet -> AttrSet 913 */ 914 dontRecurseIntoAttrs = 915 # An attribute set to not scan for derivations. ··· 919 /* `unionOfDisjoint x y` is equal to `x // y // z` where the 920 attrnames in `z` are the intersection of the attrnames in `x` and 921 `y`, and all values `assert` with an error message. This 922 - operator is commutative, unlike (//). */ 923 unionOfDisjoint = x: y: 924 let 925 intersection = builtins.intersectAttrs x y; ··· 930 in 931 (x // y) // mask; 932 933 - # deprecated 934 zipWithNames = zipAttrsWithNames; 935 - # deprecated 936 zip = builtins.trace 937 "lib.zip is deprecated, use lib.zipAttrsWith instead" zipAttrsWith; 938 }
··· 16 17 Example: 18 x = { a = { b = 3; }; } 19 + # ["a" "b"] is equivalent to x.a.b 20 + # 6 is a default value to return if the path does not exist in attrset 21 attrByPath ["a" "b"] 6 x 22 => 3 23 attrByPath ["z" "z"] 6 x ··· 25 26 Type: 27 attrByPath :: [String] -> Any -> AttrSet -> Any 28 + 29 */ 30 attrByPath = 31 # A list of strings representing the attribute path to return from `set` ··· 99 => error: cannot find attribute `z.z' 100 101 Type: 102 + getAttrFromPath :: [String] -> AttrSet -> Any 103 */ 104 getAttrFromPath = 105 # A list of strings representing the attribute path to get from `set` ··· 112 /* Map each attribute in the given set and merge them into a new attribute set. 113 114 Type: 115 + concatMapAttrs :: (String -> a -> AttrSet) -> AttrSet -> AttrSet 116 117 Example: 118 concatMapAttrs ··· 168 ] { a.b.c = 0; } 169 => { a = { b = { d = 1; }; }; x = { y = "xy"; }; } 170 171 + Type: updateManyAttrsByPath :: [{ path :: [String], update :: (Any -> Any) }] -> AttrSet -> AttrSet 172 */ 173 updateManyAttrsByPath = let 174 # When recursing into attributes, instead of updating the `path` of each ··· 251 Example: 252 attrValues {c = 3; a = 1; b = 2;} 253 => [1 2 3] 254 + 255 Type: 256 attrValues :: AttrSet -> [Any] 257 */ ··· 341 342 Type: 343 foldAttrs :: (Any -> Any -> Any) -> Any -> [AttrSets] -> Any 344 + 345 */ 346 foldAttrs = 347 # A function, given a value and a collector combines the two. ··· 395 { a = 2; b = 20; } 396 ] 397 Type: 398 + cartesianProductOfSets :: AttrSet -> [AttrSet] 399 */ 400 cartesianProductOfSets = 401 # Attribute set with attributes that are lists of values ··· 414 => { name = "some"; value = 6; } 415 416 Type: 417 + nameValuePair :: String -> Any -> { name :: String, value :: Any } 418 */ 419 nameValuePair = 420 # Attribute name ··· 601 => { } 602 603 Type: 604 + optionalAttrs :: Bool -> AttrSet -> AttrSet 605 */ 606 optionalAttrs = 607 # Condition under which the `as` attribute set is returned. ··· 647 => { a = ["x" "y"]; b = ["z"] } 648 649 Type: 650 + zipAttrsWith :: (String -> [ Any ] -> Any) -> [ AttrSet ] -> AttrSet 651 */ 652 zipAttrsWith = 653 builtins.zipAttrsWith or (f: sets: zipAttrsWithNames (concatMap attrNames sets) f sets); ··· 738 } 739 740 Type: 741 + recursiveUpdate :: AttrSet -> AttrSet -> AttrSet 742 */ 743 recursiveUpdate = 744 # Left attribute set of the merge. ··· 796 /* Turns a list of strings into a human-readable description of those 797 strings represented as an attribute path. The result of this function is 798 not intended to be machine-readable. 799 + Create a new attribute set with `value` set at the nested attribute location specified in `attrPath`. 800 801 Example: 802 showAttrPath [ "foo" "10" "bar" ] ··· 833 If the output does not exist, fallback to `.out` and then to the default. 834 835 Example: 836 + getBin pkgs.openssl 837 => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r" 838 839 Type: 840 + getBin :: Derivation -> String 841 */ 842 getBin = getOutput "bin"; 843 ··· 846 If the output does not exist, fallback to `.out` and then to the default. 847 848 Example: 849 + getLib pkgs.openssl 850 => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-lib" 851 852 Type: 853 + getLib :: Derivation -> String 854 */ 855 getLib = getOutput "lib"; 856 ··· 859 If the output does not exist, fallback to `.out` and then to the default. 860 861 Example: 862 + getDev pkgs.openssl 863 => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-dev" 864 865 Type: 866 + getDev :: Derivation -> String 867 */ 868 getDev = getOutput "dev"; 869 ··· 872 If the output does not exist, fallback to `.out` and then to the default. 873 874 Example: 875 + getMan pkgs.openssl 876 => "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-man" 877 878 Type: 879 + getMan :: Derivation -> String 880 */ 881 getMan = getOutput "man"; 882 883 + /* Pick the outputs of packages to place in `buildInputs` 884 + 885 + Type: chooseDevOutputs :: [Derivation] -> [String] 886 + 887 + */ 888 chooseDevOutputs = 889 # List of packages to pick `dev` outputs from 890 drvs: ··· 906 907 Type: 908 recurseIntoAttrs :: AttrSet -> AttrSet 909 + 910 */ 911 recurseIntoAttrs = 912 # An attribute set to scan for derivations. ··· 916 /* Undo the effect of recurseIntoAttrs. 917 918 Type: 919 + dontRecurseIntoAttrs :: AttrSet -> AttrSet 920 */ 921 dontRecurseIntoAttrs = 922 # An attribute set to not scan for derivations. ··· 926 /* `unionOfDisjoint x y` is equal to `x // y // z` where the 927 attrnames in `z` are the intersection of the attrnames in `x` and 928 `y`, and all values `assert` with an error message. This 929 + operator is commutative, unlike (//). 930 + 931 + Type: unionOfDisjoint :: AttrSet -> AttrSet -> AttrSet 932 + */ 933 unionOfDisjoint = x: y: 934 let 935 intersection = builtins.intersectAttrs x y; ··· 940 in 941 (x // y) // mask; 942 943 + # DEPRECATED 944 zipWithNames = zipAttrsWithNames; 945 + 946 + # DEPRECATED 947 zip = builtins.trace 948 "lib.zip is deprecated, use lib.zipAttrsWith instead" zipAttrsWith; 949 }
+2 -2
lib/options.nix
··· 104 /* Creates an Option attribute set for an option that specifies the 105 package a module should use for some purpose. 106 107 - Type: mkPackageOption :: pkgs -> string -> { default :: [string], example :: null | string | [string] } -> option 108 - 109 The package is specified as a list of strings representing its attribute path in nixpkgs. 110 111 Because of this, you need to pass nixpkgs itself as the first argument. ··· 115 You can also pass an example value, either a literal string or a package's attribute path. 116 117 You can omit the default path if the name of the option is also attribute path in nixpkgs. 118 119 Example: 120 mkPackageOption pkgs "hello" { }
··· 104 /* Creates an Option attribute set for an option that specifies the 105 package a module should use for some purpose. 106 107 The package is specified as a list of strings representing its attribute path in nixpkgs. 108 109 Because of this, you need to pass nixpkgs itself as the first argument. ··· 113 You can also pass an example value, either a literal string or a package's attribute path. 114 115 You can omit the default path if the name of the option is also attribute path in nixpkgs. 116 + 117 + Type: mkPackageOption :: pkgs -> string -> { default :: [string], example :: null | string | [string] } -> option 118 119 Example: 120 mkPackageOption pkgs "hello" { }