cleverca22
10/24/2016 - 5:53 PM

context.nix

with import <nixpkgs> {};

{
  # a normal dependency at build and runtime
  case1 = rec {
    a = writeText "1a.txt" "file #1";
    b = writeText "1b.txt" "file #2 refers to ${a}";
  };
  # b doesnt depent on a, so a never even got built
  # but b does contain a's path!
  case2 = rec {
    a = writeText "2a.txt" "file #1";
    b = writeText "2b.txt" "file #2 refers to ${builtins.unsafeDiscardStringContext a}";
  };
  # c depends on b at build-time, but never references it in the output, so no runtime dep
  # b depends on a properly, so a must be build before b, and hence, before c
  # but since c doesnt depend on a, a wont be copied to the correct build slave, or imported into the sandbox(chroot)
  case3 = rec {
    a = writeText "3a.txt" "file #1";
    b = runCommand "3b.txt" { inherit a; } ''
      echo "file #2" > $out
    '';
    c = runCommand "3c.txt" { inherit b; } ''
      echo "file #3 refers to ${builtins.unsafeDiscardStringContext a}" > $out
    '';
  };
}