diff options
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r-- | src/libexpr/primops.cc | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 2f1a41a64..3830d8107 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -769,17 +769,17 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * .nixCode = NixCode { .errPos = posDrvName } }); - HashType ht = outputHashAlgo.empty() ? htUnknown : parseHashType(outputHashAlgo); - + std::optional<HashType> ht = parseHashTypeOpt(outputHashAlgo); Hash h = newHashAllowEmpty(*outputHash, ht); auto outPath = state.store->makeFixedOutputPath(ingestionMethod, h, drvName); if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath); drv.outputs.insert_or_assign("out", DerivationOutput { - std::move(outPath), - (ingestionMethod == FileIngestionMethod::Recursive ? "r:" : "") - + printHashType(h.type), - h.to_string(Base16, false), + .path = std::move(outPath), + .hash = FixedOutputHash { + .method = ingestionMethod, + .hash = std::move(h), + }, }); } @@ -793,7 +793,10 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * for (auto & i : outputs) { if (!jsonObject) drv.env[i] = ""; drv.outputs.insert_or_assign(i, - DerivationOutput { StorePath::dummy, "", "" }); + DerivationOutput { + .path = StorePath::dummy, + .hash = std::optional<FixedOutputHash> {}, + }); } Hash h = hashDerivationModulo(*state.store, Derivation(drv), true); @@ -802,7 +805,10 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * auto outPath = state.store->makeOutputPath(i, h, drvName); if (!jsonObject) drv.env[i] = state.store->printStorePath(outPath); drv.outputs.insert_or_assign(i, - DerivationOutput { std::move(outPath), "", "" }); + DerivationOutput { + .path = std::move(outPath), + .hash = std::optional<FixedOutputHash>(), + }); } } @@ -999,8 +1005,8 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Value & v) { string type = state.forceStringNoCtx(*args[0], pos); - HashType ht = parseHashType(type); - if (ht == htUnknown) + std::optional<HashType> ht = parseHashType(type); + if (!ht) throw Error({ .hint = hintfmt("unknown hash type '%1%'", type), .nixCode = NixCode { .errPos = pos } @@ -1009,7 +1015,7 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va PathSet context; // discarded Path p = state.coerceToPath(pos, *args[1], context); - mkString(v, hashFile(ht, state.checkSourcePath(p)).to_string(Base16, false), context); + mkString(v, hashFile(*ht, state.checkSourcePath(p)).to_string(Base16, false), context); } /* Read a directory (without . or ..) */ @@ -1936,8 +1942,8 @@ static void prim_stringLength(EvalState & state, const Pos & pos, Value * * args static void prim_hashString(EvalState & state, const Pos & pos, Value * * args, Value & v) { string type = state.forceStringNoCtx(*args[0], pos); - HashType ht = parseHashType(type); - if (ht == htUnknown) + std::optional<HashType> ht = parseHashType(type); + if (!ht) throw Error({ .hint = hintfmt("unknown hash type '%1%'", type), .nixCode = NixCode { .errPos = pos } @@ -1946,7 +1952,7 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args, PathSet context; // discarded string s = state.forceString(*args[1], context, pos); - mkString(v, hashString(ht, s).to_string(Base16, false), context); + mkString(v, hashString(*ht, s).to_string(Base16, false), context); } |