mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
"content-address*ed*" derivation is misleading because all derivations are *themselves* content-addressed. What may or may not be content-addressed is not derivation itself, but the *output* of the derivation. The outputs are not *part* of the derivation (for then the derivation wouldn't be complete before we built it) but rather separate entities produced by the derivation. "content-adddress*ed*" is not correctly because it can only describe what the derivation *is*, and that is not what we are trying to do. "content-address*ing*" is correct because it describes what the derivation *does* --- it produces content-addressed data.
33 lines
905 B
Nix
33 lines
905 B
Nix
with import ./config.nix;
|
|
|
|
# A simple content-addressing derivation.
|
|
# The derivation can be arbitrarily modified by passing a different `seed`,
|
|
# but the output will always be the same
|
|
rec {
|
|
hello = mkDerivation {
|
|
name = "hello";
|
|
buildCommand = ''
|
|
set -x
|
|
echo "Building a CA derivation"
|
|
mkdir -p $out
|
|
echo "Hello World" > $out/hello
|
|
'';
|
|
};
|
|
producingDrv = mkDerivation {
|
|
name = "hello.drv";
|
|
buildCommand = ''
|
|
echo "Copying the derivation"
|
|
cp ${builtins.unsafeDiscardOutputDependency hello.drvPath} $out
|
|
'';
|
|
__contentAddressed = true;
|
|
outputHashMode = "text";
|
|
outputHashAlgo = "sha256";
|
|
};
|
|
wrapper = mkDerivation {
|
|
name = "use-dynamic-drv-in-non-dynamic-drv";
|
|
buildCommand = ''
|
|
echo "Copying the output of the dynamic derivation"
|
|
cp -r ${builtins.outputOf producingDrv.outPath "out"} $out
|
|
'';
|
|
};
|
|
}
|