-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade
downstreamPlaceholder
to a type with methods
This gets us ready for dynamic derivation dependencies (part of RFC 92).
- Loading branch information
1 parent
5fd1611
commit b279a0f
Showing
9 changed files
with
125 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "downstream-placeholder.hh" | ||
#include "derivations.hh" | ||
|
||
namespace nix { | ||
|
||
std::string DownstreamPlaceholder::render() const | ||
{ | ||
return "/" + hash.to_string(Base32, false); | ||
} | ||
|
||
|
||
inline Hash DownstreamPlaceholder::worker1(const StorePath & drvPath, std::string_view outputName) | ||
{ | ||
auto drvNameWithExtension = drvPath.name(); | ||
auto drvName = drvNameWithExtension.substr(0, drvNameWithExtension.size() - 4); | ||
auto clearText = "nix-upstream-output:" + std::string { drvPath.hashPart() } + ":" + outputPathName(drvName, outputName); | ||
return hashString(htSHA256, clearText); | ||
} | ||
|
||
DownstreamPlaceholder::DownstreamPlaceholder(const StorePath & drvPath, std::string_view outputName) | ||
: hash(worker1(drvPath, outputName)) | ||
{} | ||
|
||
inline Hash DownstreamPlaceholder::worker2(const DownstreamPlaceholder & placeholder, std::string_view outputName) | ||
{ | ||
experimentalFeatureSettings.require(Xp::DynamicDerivations); | ||
auto compressed = compressHash(placeholder.hash, 20); | ||
auto clearText = "nix-computed-output:" | ||
+ compressed.to_string(Base32, false) | ||
+ ":" + std::string { outputName }; | ||
return hashString(htSHA256, clearText); | ||
} | ||
|
||
DownstreamPlaceholder::DownstreamPlaceholder(const DownstreamPlaceholder & placeholder, std::string_view outputName) | ||
: hash(worker2(placeholder, outputName)) | ||
{} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
///@file | ||
|
||
#include "hash.hh" | ||
#include "path.hh" | ||
|
||
namespace nix { | ||
|
||
/** | ||
* Downstream Placeholders are opaque and almost certainly unique values | ||
* used to allow derivations to refer to store objects which are yet to | ||
* be built and for we do not yet have store paths for. | ||
* | ||
* They correspond to `DerivedPaths` that are not `DerivedPath::Opaque`, | ||
* except for the cases involving input addressing or fixed outputs | ||
* where we do know a store path for the derivation output in advance. | ||
* | ||
* Unlike `DerivationPath`, however, `DownstreamPlaceholder` is | ||
* purposefully opaque and obfuscated. This is so they are hard to | ||
* create by accident, and so substituting them (once we know what the | ||
* path to store object is) is unlikely to capture other stuff it | ||
* shouldn't. | ||
* | ||
* We use them with `Derivation`: the `render()` method is called to | ||
* render an opaque string which can be used in the derivation, and the | ||
* resolving logic can substitute those strings for store paths when | ||
* resolving `Derivation.inputDrvs` to `BasicDerivation.inputSrcs`. | ||
*/ | ||
class DownstreamPlaceholder | ||
{ | ||
/** | ||
* `DownstreamPlaceholder` is just a newtype of `Hash`. | ||
* This its only field. | ||
*/ | ||
Hash hash; | ||
|
||
public: | ||
/** | ||
* This creates an opaque and almost certainly unique string | ||
* deterministically from the placeholder. | ||
*/ | ||
std::string render() const; | ||
|
||
/** | ||
* For content-addressed derivations | ||
* | ||
* The derivation is known (we have a store path for it), but the | ||
* output doesn't yet have a known store path. | ||
*/ | ||
DownstreamPlaceholder(const StorePath & drvPath, std::string_view outputName); | ||
|
||
/** | ||
* For dynamic derivations | ||
* | ||
* The derivation is not yet known, and we just have (another) | ||
* placeholder for it. | ||
*/ | ||
DownstreamPlaceholder(const DownstreamPlaceholder & drvPlaceholder, std::string_view outputName); | ||
|
||
private: | ||
/** | ||
* Private worker function for constructor | ||
*/ | ||
static inline Hash worker1(const StorePath & drvPath, std::string_view outputName); | ||
/** | ||
* Private worker function for constructor | ||
*/ | ||
static inline Hash worker2(const DownstreamPlaceholder & placeholder, std::string_view outputName); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters