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