derivations.hh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include "types.hh"
  3. #include "hash.hh"
  4. #include <map>
  5. namespace nix {
  6. /* Extension of derivations in the Nix store. */
  7. const string drvExtension = ".drv";
  8. /* Abstract syntax of derivations. */
  9. struct DerivationOutput
  10. {
  11. Path path;
  12. string hashAlgo; /* hash used for expected hash computation */
  13. string hash; /* expected hash, may be null */
  14. DerivationOutput()
  15. {
  16. }
  17. DerivationOutput(Path path, string hashAlgo, string hash)
  18. {
  19. this->path = path;
  20. this->hashAlgo = hashAlgo;
  21. this->hash = hash;
  22. }
  23. void parseHashInfo(bool & recursive, HashType & hashType, Hash & hash) const;
  24. };
  25. typedef std::map<string, DerivationOutput> DerivationOutputs;
  26. /* For inputs that are sub-derivations, we specify exactly which
  27. output IDs we are interested in. */
  28. typedef std::map<Path, StringSet> DerivationInputs;
  29. typedef std::map<string, string> StringPairs;
  30. struct Derivation
  31. {
  32. DerivationOutputs outputs; /* keyed on symbolic IDs */
  33. DerivationInputs inputDrvs; /* inputs that are sub-derivations */
  34. PathSet inputSrcs; /* inputs that are sources */
  35. string platform;
  36. Path builder;
  37. Strings args;
  38. StringPairs env;
  39. };
  40. class StoreAPI;
  41. /* Write a derivation to the Nix store, and return its path. */
  42. Path writeDerivation(StoreAPI & store,
  43. const Derivation & drv, const string & name, bool repair = false);
  44. /* Read a derivation from a file. */
  45. Derivation readDerivation(const Path & drvPath);
  46. /* Print a derivation. */
  47. string unparseDerivation(const Derivation & drv);
  48. /* Check whether a file name ends with the extensions for
  49. derivations. */
  50. bool isDerivation(const string & fileName);
  51. /* Return true iff this is a fixed-output derivation. */
  52. bool isFixedOutputDrv(const Derivation & drv);
  53. Hash hashDerivationModulo(StoreAPI & store, Derivation drv);
  54. /* Memoisation of hashDerivationModulo(). */
  55. typedef std::map<Path, Hash> DrvHashes;
  56. extern DrvHashes drvHashes;
  57. /* Split a string specifying a derivation and a set of outputs
  58. (/nix/store/hash-foo!out1,out2,...) into the derivation path and
  59. the outputs. */
  60. typedef std::pair<string, std::set<string> > DrvPathWithOutputs;
  61. DrvPathWithOutputs parseDrvPathWithOutputs(const string & s);
  62. Path makeDrvPathWithOutputs(const Path & drvPath, const std::set<string> & outputs);
  63. bool wantOutput(const string & output, const std::set<string> & wanted);
  64. PathSet outputPaths(const Derivation & drv);
  65. }