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