2021-05-11 11:52:17 +03:00
|
|
|
with import ./config.nix;
|
|
|
|
|
|
|
|
let mkCADerivation = args: mkDerivation ({
|
|
|
|
__contentAddressed = true;
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
} // args);
|
|
|
|
in
|
2020-08-07 22:09:26 +03:00
|
|
|
|
|
|
|
{ seed ? 0 }:
|
|
|
|
# A simple content-addressed derivation.
|
|
|
|
# The derivation can be arbitrarily modified by passing a different `seed`,
|
|
|
|
# but the output will always be the same
|
2020-08-22 23:44:47 +03:00
|
|
|
rec {
|
2020-09-04 01:14:21 +03:00
|
|
|
rootLegacy = mkDerivation {
|
2020-09-04 01:44:56 +03:00
|
|
|
name = "simple-input-addressed";
|
2020-08-22 23:44:47 +03:00
|
|
|
buildCommand = ''
|
|
|
|
set -x
|
2020-09-04 01:14:21 +03:00
|
|
|
echo "Building a legacy derivation"
|
2020-08-22 23:44:47 +03:00
|
|
|
mkdir -p $out
|
|
|
|
echo "Hello World" > $out/hello
|
|
|
|
'';
|
|
|
|
};
|
2021-05-11 11:52:17 +03:00
|
|
|
rootCA = mkCADerivation {
|
2020-09-23 17:30:42 +03:00
|
|
|
name = "rootCA";
|
2022-04-20 17:39:47 +03:00
|
|
|
outputs = [ "out" "dev" "foo" ];
|
2020-09-04 01:14:21 +03:00
|
|
|
buildCommand = ''
|
|
|
|
echo "building a CA derivation"
|
|
|
|
echo "The seed is ${toString seed}"
|
|
|
|
mkdir -p $out
|
|
|
|
echo ${rootLegacy}/hello > $out/dep
|
2020-11-25 12:20:03 +02:00
|
|
|
ln -s $out $out/self
|
|
|
|
# test symlinks at root
|
2020-09-04 17:38:45 +03:00
|
|
|
ln -s $out $dev
|
2020-11-25 12:20:03 +02:00
|
|
|
ln -s $out $foo
|
2020-09-04 01:14:21 +03:00
|
|
|
'';
|
|
|
|
};
|
2021-05-11 11:52:17 +03:00
|
|
|
dependentCA = mkCADerivation {
|
2020-08-22 23:44:47 +03:00
|
|
|
name = "dependent";
|
|
|
|
buildCommand = ''
|
|
|
|
echo "building a dependent derivation"
|
|
|
|
mkdir -p $out
|
2020-11-25 12:20:03 +02:00
|
|
|
cat ${rootCA}/self/dep
|
|
|
|
echo ${rootCA}/self/dep > $out/dep
|
2020-08-22 23:44:47 +03:00
|
|
|
'';
|
|
|
|
};
|
2021-05-11 11:52:17 +03:00
|
|
|
transitivelyDependentCA = mkCADerivation {
|
2020-08-22 23:44:47 +03:00
|
|
|
name = "transitively-dependent";
|
|
|
|
buildCommand = ''
|
|
|
|
echo "building transitively-dependent"
|
2020-09-04 01:44:56 +03:00
|
|
|
cat ${dependentCA}/dep
|
|
|
|
echo ${dependentCA} > $out
|
2020-08-22 23:44:47 +03:00
|
|
|
'';
|
|
|
|
};
|
2020-09-23 17:30:42 +03:00
|
|
|
dependentNonCA = mkDerivation {
|
|
|
|
name = "dependent-non-ca";
|
|
|
|
buildCommand = ''
|
|
|
|
echo "Didn't cut-off"
|
|
|
|
echo "building dependent-non-ca"
|
|
|
|
mkdir -p $out
|
|
|
|
echo ${rootCA}/non-ca-hello > $out/dep
|
|
|
|
'';
|
|
|
|
};
|
2023-06-30 18:11:12 +03:00
|
|
|
dependentForBuildCA = mkCADerivation {
|
|
|
|
name = "dependent-for-build-ca";
|
|
|
|
buildCommand = ''
|
|
|
|
echo "Depends on rootCA for building only"
|
|
|
|
mkdir -p $out
|
|
|
|
echo ${rootCA}
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
dependentForBuildNonCA = mkDerivation {
|
|
|
|
name = "dependent-for-build-non-ca";
|
|
|
|
buildCommand = ''
|
|
|
|
echo "Depends on rootCA for building only"
|
|
|
|
mkdir -p $out
|
|
|
|
echo ${rootCA}
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
};
|
2020-11-25 19:20:35 +02:00
|
|
|
dependentFixedOutput = mkDerivation {
|
|
|
|
name = "dependent-fixed-output";
|
|
|
|
outputHashMode = "recursive";
|
2022-04-01 13:40:49 +03:00
|
|
|
outputHash = "sha512-7aJcmSuEuYP5tGKcmGY8bRr/lrCjJlOxP2mIUjO/vMQeg6gx/65IbzRWES8EKiPDOs9z+wF30lEfcwxM/cT4pw==";
|
2020-11-25 19:20:35 +02:00
|
|
|
buildCommand = ''
|
|
|
|
cat ${dependentCA}/dep
|
|
|
|
echo foo > $out
|
|
|
|
'';
|
2021-05-11 11:52:17 +03:00
|
|
|
};
|
|
|
|
runnable = mkCADerivation rec {
|
|
|
|
name = "runnable-thing";
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
echo ${rootCA} # Just to make it depend on it
|
2022-06-22 23:41:14 +03:00
|
|
|
echo "#! ${shell}" > $out/bin/${name}
|
2021-05-11 11:52:17 +03:00
|
|
|
chmod +x $out/bin/${name}
|
|
|
|
'';
|
2020-11-25 19:20:35 +02:00
|
|
|
};
|
2020-08-07 22:09:26 +03:00
|
|
|
}
|