aboutsummaryrefslogtreecommitdiff
path: root/tests/ca/content-addressed.nix
blob: d328fc92c1b54f6169f18a663e085724ddcc219c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
with import ./config.nix;

let mkCADerivation = args: mkDerivation ({
    __contentAddressed = true;
    outputHashMode = "recursive";
    outputHashAlgo = "sha256";
} // args);
in

{ 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
rec {
  rootLegacy = mkDerivation {
    name = "simple-input-addressed";
    buildCommand = ''
      set -x
      echo "Building a legacy derivation"
      mkdir -p $out
      echo "Hello World" > $out/hello
    '';
  };
  rootCA = mkCADerivation {
    name = "rootCA";
    outputs = [ "out" "dev" "foo"];
    buildCommand = ''
      echo "building a CA derivation"
      echo "The seed is ${toString seed}"
      mkdir -p $out
      echo ${rootLegacy}/hello > $out/dep
      ln -s $out $out/self
      # test symlinks at root
      ln -s $out $dev
      ln -s $out $foo
    '';
  };
  dependentCA = mkCADerivation {
    name = "dependent";
    buildCommand = ''
      echo "building a dependent derivation"
      mkdir -p $out
      cat ${rootCA}/self/dep
      echo ${rootCA}/self/dep > $out/dep
    '';
  };
  transitivelyDependentCA = mkCADerivation {
    name = "transitively-dependent";
    buildCommand = ''
      echo "building transitively-dependent"
      cat ${dependentCA}/dep
      echo ${dependentCA} > $out
    '';
  };
  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
    '';
  };
  dependentFixedOutput = mkDerivation {
    name = "dependent-fixed-output";
    outputHashMode = "recursive";
    outputHashAlgo = "sha256";
    outputHash = "sha256-QvtAMbUl/uvi+LCObmqOhvNOapHdA2raiI4xG5zI5pA=";
    buildCommand = ''
      cat ${dependentCA}/dep
      echo foo > $out
    '';
  };
  runnable = mkCADerivation rec {
    name = "runnable-thing";
    buildCommand = ''
      mkdir -p $out/bin
      echo ${rootCA} # Just to make it depend on it
      echo "" > $out/bin/${name}
      chmod +x $out/bin/${name}
    '';
  };
}