From 965cc5da574c8ee2310d0cc0a7d75363f422b4c3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 9 Dec 2017 14:27:24 -0500 Subject: [PATCH 1/2] top-level: Fix splicing in the presence of evaluation errors - No more `or {}`, this was misleading at best since those values wouldn't be used unless the attr they are defined from was present anyways. - `tryEval` for get outputs. This ensures that if some derivations fail, they won't take out the others. This benefited from the `or {}` before, but that was never good enough. `tryEval` is strictly better. --- pkgs/top-level/splice.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/top-level/splice.nix b/pkgs/top-level/splice.nix index b13fa86a9958..d2c339b04df8 100644 --- a/pkgs/top-level/splice.nix +++ b/pkgs/top-level/splice.nix @@ -37,12 +37,15 @@ let inherit name; value = let defaultValue = mash.${name}; - buildValue = buildPkgs.${name} or {}; - runValue = runPkgs.${name} or {}; + buildValue = buildPkgs.${name}; + runValue = runPkgs.${name}; augmentedValue = defaultValue // (lib.optionalAttrs (buildPkgs ? ${name}) { nativeDrv = buildValue; }) // (lib.optionalAttrs (runPkgs ? ${name}) { crossDrv = runValue; }); # Get the set of outputs of a derivation + tryGetOutputs = value0: let + eval = builtins.tryEval value0; + in getOutputs (if eval.success then eval.value else {}); getOutputs = value: lib.genAttrs (value.outputs or (lib.optional (value ? out) "out")) (output: value.${output}); @@ -54,7 +57,7 @@ let # The derivation along with its outputs, which we recur # on to splice them together. else if lib.isDerivation defaultValue then augmentedValue - // splicer (getOutputs buildValue) (getOutputs runValue) + // splicer (tryGetOutputs buildValue) (getOutputs runValue) # Just recur on plain attrsets else if lib.isAttrs defaultValue then splicer buildValue runValue # Don't be fancy about non-derivations. But we could have used used From 6c36d3c9e0b615c4e76fc3b3582e6f3ec1637af3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 10 Dec 2017 16:38:48 -0500 Subject: [PATCH 2/2] top-level: Fix splicing, again --- pkgs/top-level/splice.nix | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkgs/top-level/splice.nix b/pkgs/top-level/splice.nix index d2c339b04df8..ea81b110080d 100644 --- a/pkgs/top-level/splice.nix +++ b/pkgs/top-level/splice.nix @@ -37,26 +37,25 @@ let inherit name; value = let defaultValue = mash.${name}; - buildValue = buildPkgs.${name}; - runValue = runPkgs.${name}; + # `or {}` is for the non-derivation attsert splicing case, where `{}` is the identity. + buildValue = buildPkgs.${name} or {}; + runValue = runPkgs.${name} or {}; augmentedValue = defaultValue // (lib.optionalAttrs (buildPkgs ? ${name}) { nativeDrv = buildValue; }) // (lib.optionalAttrs (runPkgs ? ${name}) { crossDrv = runValue; }); - # Get the set of outputs of a derivation + # Get the set of outputs of a derivation. If one derivation fails to + # evaluate we don't want to diverge the entire splice, so we fall back + # on {} tryGetOutputs = value0: let - eval = builtins.tryEval value0; - in getOutputs (if eval.success then eval.value else {}); + inherit (builtins.tryEval value0) success value; + in getOutputs (lib.optionalAttrs success value); getOutputs = value: lib.genAttrs (value.outputs or (lib.optional (value ? out) "out")) (output: value.${output}); in - # Certain *Cross derivations will fail assertions, but we need their - # nativeDrv. We are assuming anything that fails to evaluate is an - # attrset (including derivation) and thus can be unioned. - if !(builtins.tryEval defaultValue).success then augmentedValue # The derivation along with its outputs, which we recur # on to splice them together. - else if lib.isDerivation defaultValue then augmentedValue + if lib.isDerivation defaultValue then augmentedValue // splicer (tryGetOutputs buildValue) (getOutputs runValue) # Just recur on plain attrsets else if lib.isAttrs defaultValue then splicer buildValue runValue