You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/manual/source/store/derivation/outputs.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,15 @@ stdenv.mkDerivation {
116
116
}
117
117
```
118
118
119
+
If a fetchurl derivation followed the normal translation scheme, the output paths of the derivation and *all derivations depending on it* would change.
120
+
For instance, if we were to change the URL of the Glibc source distribution—a component on which almost all other components depend—massive rebuilds will ensue.
121
+
This is unfortunate for a change which we know cannot have a real effect as it propagates upwards through the dependency graph.
122
+
123
+
Fixed-output derivations solve this problem by allowing a derivation to state to Nix that its output will hash to a specific value.
124
+
When Nix builds the derivation, it will hash the output and check that the hash corresponds to the declared value.
125
+
If there is a hash mismatch, the build fails and the output is not registered as valid.
126
+
For fixed-output derivations, the computation of the output path only depends on the declared hash and hash algorithm, *not* on any other attributes of the derivation.
127
+
119
128
### (Floating) Content-Addressing
120
129
121
130
> **Warning**
@@ -137,8 +146,22 @@ It also implicitly requires that the machine to build the derivation must have t
137
146
That is to say, with input addressing the outputs store path is a function not of the output itself, but the derivation that produced it.
138
147
Even if two store paths have the same contents, if they are produced in different ways, and one is input-addressed, then they will have different store paths, and thus guaranteed to not be the same store object.
139
148
149
+
### Modulo fixed-output derivations
150
+
140
151
**TODO hash derivation modulo.**
141
152
153
+
So how do we compute the hash part of the output path of a derivation?
154
+
This is done by the function `hashDrv`, shown in Figure 5.10.
155
+
It distinguishes between two cases.
156
+
If the derivation is a fixed-output derivation, then it computes a hash over just the `outputHash` attributes.
157
+
158
+
If the derivation is not a fixed-output derivation, we replace each element in the derivation’s inputDrvs with the result of a call to `hashDrv` for that element.
159
+
(The derivation at each store path in `inputDrvs` is converted from its on-disk ATerm representation back to a `StoreDrv` by the function `parseDrv`.) In essence, `hashDrv` partitions store derivations into equivalence classes, and for hashing purpose it replaces each store path in a derivation graph with its equivalence class.
160
+
161
+
The recursion in Figure 5.10 is inefficient:
162
+
it will call itself once for each path by which a subderivation can be reached, i.e., `O(V k)` times for a derivation graph with `V` derivations and with out-degree of at most `k`.
163
+
In the actual implementation, memoisation is used to reduce this to `O(V + E)` complexity for a graph with E edges.
0 commit comments