stdenv/generic/default.nix: Simplify the code using the "or" construct

This commit is contained in:
Eelco Dolstra 2012-08-22 11:42:51 -04:00
parent cdc0c13c00
commit 85047983a1

View file

@ -42,30 +42,23 @@ let
(derivation ( (derivation (
(removeAttrs attrs ["meta" "passthru" "crossAttrs"]) (removeAttrs attrs ["meta" "passthru" "crossAttrs"])
// (let // (let
buildInputs = if attrs ? buildInputs then attrs.buildInputs buildInputs = attrs.buildInputs or [];
else []; buildNativeInputs = attrs.buildNativeInputs or [];
buildNativeInputs = if attrs ? buildNativeInputs then propagatedBuildInputs = attrs.propagatedBuildInputs or [];
attrs.buildNativeInputs else []; propagatedBuildNativeInputs = attrs.propagatedBuildNativeInputs or [];
propagatedBuildInputs = if attrs ? propagatedBuildInputs then crossConfig = attrs.crossConfig or null;
attrs.propagatedBuildInputs else [];
propagatedBuildNativeInputs = if attrs ?
propagatedBuildNativeInputs then
attrs.propagatedBuildNativeInputs else [];
crossConfig = if (attrs ? crossConfig) then attrs.crossConfig else
null;
in in
{ {
builder = if attrs ? realBuilder then attrs.realBuilder else shell; builder = attrs.realBuilder or shell;
args = if attrs ? args then attrs.args else args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
["-e" (if attrs ? builder then attrs.builder else ./default-builder.sh)];
stdenv = result; stdenv = result;
system = result.system; system = result.system;
# That build by the cross compiler # Inputs built by the cross compiler.
buildInputs = lib.optionals (crossConfig != null) buildInputs; buildInputs = lib.optionals (crossConfig != null) buildInputs;
propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs = lib.optionals (crossConfig != null)
propagatedBuildInputs; propagatedBuildInputs;
# That build by the usual native compiler # Inputs built by the usual native compiler.
buildNativeInputs = buildNativeInputs ++ lib.optionals buildNativeInputs = buildNativeInputs ++ lib.optionals
(crossConfig == null) buildInputs; (crossConfig == null) buildInputs;
propagatedBuildNativeInputs = propagatedBuildNativeInputs ++ propagatedBuildNativeInputs = propagatedBuildNativeInputs ++
@ -77,13 +70,11 @@ let
# passed to the builder and is not a dependency. But since we # passed to the builder and is not a dependency. But since we
# include it in the result, it *is* available to nix-env for # include it in the result, it *is* available to nix-env for
# queries. # queries.
// // { meta = attrs.meta or {}; }
{ meta = if attrs ? meta then attrs.meta else {}; }
# Pass through extra attributes that are not inputs, but # Pass through extra attributes that are not inputs, but
# should be made available to Nix expressions using the # should be made available to Nix expressions using the
# derivation (e.g., in assertions). # derivation (e.g., in assertions).
// // (attrs.passthru or {});
(if attrs ? passthru then attrs.passthru else {});
# Utility flags to test the type of platform. # Utility flags to test the type of platform.
isDarwin = result.system == "i686-darwin" isDarwin = result.system == "i686-darwin"