diff options
author | Shea Levy <shea@shealevy.com> | 2013-03-24 08:29:10 -0400 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2013-03-24 08:29:10 -0400 |
commit | 98860f429ddd01ed14f2a6802e5e2d024d1cc352 (patch) | |
tree | 3b846813320e1ba14c40be9fe5716caadf622da8 /pkgs | |
parent | 4fa4ab3a6ef91c2cd52065ba1c7816f2d4ceefc3 (diff) | |
download | nixpkgs-98860f429ddd01ed14f2a6802e5e2d024d1cc352.tar nixpkgs-98860f429ddd01ed14f2a6802e5e2d024d1cc352.tar.gz nixpkgs-98860f429ddd01ed14f2a6802e5e2d024d1cc352.tar.bz2 nixpkgs-98860f429ddd01ed14f2a6802e5e2d024d1cc352.tar.lz nixpkgs-98860f429ddd01ed14f2a6802e5e2d024d1cc352.tar.xz nixpkgs-98860f429ddd01ed14f2a6802e5e2d024d1cc352.tar.zst nixpkgs-98860f429ddd01ed14f2a6802e5e2d024d1cc352.zip |
Add the addPassthru library function
With multiple outputs, adding attributes to a derivation without changing the {drv,out}Path is no longer as trivial as simply using the `//' operator, as we usually want to add the attribute to _each_ output, and even if we only care about one that one output can be reached via multiple paths. For stdenv.mkDerivation, we already had code in place to add passthru and meta attributes to derivations. This commit simply factors part of that code out into a lib function addPassthru, which takes a derivation and an attribute set and appends the attribute set to each output of the derivation. Signed-off-by: Shea Levy <shea@shealevy.com>
Diffstat (limited to 'pkgs')
-rw-r--r-- | pkgs/lib/customisation.nix | 17 | ||||
-rw-r--r-- | pkgs/stdenv/generic/default.nix | 91 |
2 files changed, 55 insertions, 53 deletions
diff --git a/pkgs/lib/customisation.nix b/pkgs/lib/customisation.nix index 18cec3209f9..a35b44e9f6e 100644 --- a/pkgs/lib/customisation.nix +++ b/pkgs/lib/customisation.nix @@ -99,4 +99,21 @@ rec { let f = if builtins.isFunction fn then fn else import fn; in makeOverridable f ((builtins.intersectAttrs (builtins.functionArgs f) autoArgs) // args); + /* Add attributes to each output of a derivation without changing the derivation itself */ + addPassthru = drv: passthru: + let + outputs = drv.outputs or [ "out" ]; + + commonAttrs = drv // (builtins.listToAttrs outputsList) // + ({ all = map (x: x.value) outputsList; }) // passthru; + + outputToAttrListElement = outputName: + { name = outputName; + value = commonAttrs // { + inherit (builtins.getAttr outputName drv) outPath drvPath type outputName; + }; + }; + + outputsList = map outputToAttrListElement outputs; + in builtins.getAttr drv.outputName commonAttrs; } diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index fd7b3218e34..fe4bbbc94dd 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -52,59 +52,44 @@ let if !allowUnfree && (let l = attrs.meta.license or ""; in l == "unfree" || l == "unfree-redistributable" || l == lib.licenses.proprietary) then throw "package ‘${attrs.name}’ has an unfree license, refusing to evaluate" else - let - drv = derivation ( - (removeAttrs attrs ["meta" "passthru" "crossAttrs"]) - // (let - buildInputs = attrs.buildInputs or []; - nativeBuildInputs = attrs.nativeBuildInputs or []; - propagatedBuildInputs = attrs.propagatedBuildInputs or []; - propagatedNativeBuildInputs = attrs.propagatedNativeBuildInputs or []; - crossConfig = attrs.crossConfig or null; - in - { - builder = attrs.realBuilder or shell; - args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; - stdenv = result; - system = result.system; - userHook = config.stdenv.userHook or null; - - # Inputs built by the cross compiler. - buildInputs = lib.optionals (crossConfig != null) buildInputs; - propagatedBuildInputs = lib.optionals (crossConfig != null) - propagatedBuildInputs; - # Inputs built by the usual native compiler. - nativeBuildInputs = nativeBuildInputs ++ lib.optionals - (crossConfig == null) buildInputs; - propagatedNativeBuildInputs = propagatedNativeBuildInputs ++ - lib.optionals (crossConfig == null) propagatedBuildInputs; - })); - - outputs = drv.outputs or [ "out" ]; - - commonAttrs = drv // (builtins.listToAttrs outputsList) // - ({ all = map (x: x.value) outputsList; - # The meta attribute is passed in the resulting attribute set, - # but it's not part of the actual derivation, i.e., it's not - # passed to the builder and is not a dependency. But since we - # include it in the result, it *is* available to nix-env for - # queries. - meta = attrs.meta or {}; - }) // - # Pass through extra attributes that are not inputs, but - # should be made available to Nix expressions using the - # derivation (e.g., in assertions). - (attrs.passthru or {}); - - outputToAttrListElement = outputName: - { name = outputName; - value = commonAttrs // { - inherit (builtins.getAttr outputName drv) outPath drvPath type outputName; - }; - }; - - outputsList = map outputToAttrListElement outputs; - in (builtins.head outputsList).value; + lib.addPassthru (derivation ( + (removeAttrs attrs ["meta" "passthru" "crossAttrs"]) + // (let + buildInputs = attrs.buildInputs or []; + nativeBuildInputs = attrs.nativeBuildInputs or []; + propagatedBuildInputs = attrs.propagatedBuildInputs or []; + propagatedNativeBuildInputs = attrs.propagatedNativeBuildInputs or []; + crossConfig = attrs.crossConfig or null; + in + { + builder = attrs.realBuilder or shell; + args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; + stdenv = result; + system = result.system; + userHook = config.stdenv.userHook or null; + + # Inputs built by the cross compiler. + buildInputs = lib.optionals (crossConfig != null) buildInputs; + propagatedBuildInputs = lib.optionals (crossConfig != null) + propagatedBuildInputs; + # Inputs built by the usual native compiler. + nativeBuildInputs = nativeBuildInputs ++ lib.optionals + (crossConfig == null) buildInputs; + propagatedNativeBuildInputs = propagatedNativeBuildInputs ++ + lib.optionals (crossConfig == null) propagatedBuildInputs; + }))) ( + { + # The meta attribute is passed in the resulting attribute set, + # but it's not part of the actual derivation, i.e., it's not + # passed to the builder and is not a dependency. But since we + # include it in the result, it *is* available to nix-env for + # queries. + meta = attrs.meta or {}; + } // + # Pass through extra attributes that are not inputs, but + # should be made available to Nix expressions using the + # derivation (e.g., in assertions). + (attrs.passthru or {})); # Utility flags to test the type of platform. isDarwin = result.system == "x86_64-darwin"; |