gnu: linux-libre: Update to 5.1.4.
[guix.git] / nix / libstore / derivations.hh
blob8d5e4d05d469e0d0ab6dd66ccaabc6faa6ccfd70
1 #pragma once
3 #include "types.hh"
4 #include "hash.hh"
6 #include <map>
9 namespace nix {
12 /* Extension of derivations in the Nix store. */
13 const string drvExtension = ".drv";
16 /* Abstract syntax of derivations. */
18 struct DerivationOutput
20 Path path;
21 string hashAlgo; /* hash used for expected hash computation */
22 string hash; /* expected hash, may be null */
23 DerivationOutput()
26 DerivationOutput(Path path, string hashAlgo, string hash)
28 this->path = path;
29 this->hashAlgo = hashAlgo;
30 this->hash = hash;
32 void parseHashInfo(bool & recursive, HashType & hashType, Hash & hash) const;
35 typedef std::map<string, DerivationOutput> DerivationOutputs;
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;
41 typedef std::map<string, string> StringPairs;
43 struct Derivation
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;
55 class StoreAPI;
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);
62 /* Read a derivation from a file. */
63 Derivation readDerivation(const Path & drvPath);
65 /* Print a derivation. */
66 string unparseDerivation(const Derivation & drv);
68 /* Check whether a file name ends with the extensions for
69 derivations. */
70 bool isDerivation(const string & fileName);
72 /* Return true iff this is a fixed-output derivation. */
73 bool isFixedOutputDrv(const Derivation & drv);
75 Hash hashDerivationModulo(StoreAPI & store, Derivation drv);
77 /* Memoisation of hashDerivationModulo(). */
78 typedef std::map<Path, Hash> DrvHashes;
80 extern DrvHashes drvHashes;
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);
88 Path makeDrvPathWithOutputs(const Path & drvPath, const std::set<string> & outputs);
90 bool wantOutput(const string & output, const std::set<string> & wanted);
92 PathSet outputPaths(const Derivation & drv);