-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand manual on derivation outputs #12442
base: master
Are you sure you want to change the base?
Conversation
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/description-of-the-attribute-inputdrvs-in-the-nix-manual/60190/13 |
```nix | ||
fetchurl { | ||
url = "http://ftp.gnu.org/pub/gnu/hello/hello-2.1.1.tar.gz"; | ||
sha256 = "1md7jsfd8pa45z73bz1kszpp01yw6x5ljkjk2hx7wl800any6465"; | ||
} | ||
``` | ||
|
||
It sometimes happens that the URL of the file changes, e.g., because | ||
servers are reorganised or no longer available. We then must update | ||
the call to `fetchurl`, e.g., | ||
|
||
```nix | ||
fetchurl { | ||
url = "ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz"; | ||
sha256 = "1md7jsfd8pa45z73bz1kszpp01yw6x5ljkjk2hx7wl800any6465"; | ||
} | ||
``` | ||
|
||
If a `fetchurl` derivation was treated like a normal derivation, the | ||
output paths of the derivation and *all derivations depending on it* | ||
would change. For instance, if we were to change the URL of the | ||
Glibc source distribution in Nixpkgs (a package on which almost all | ||
other packages depend) massive rebuilds would be needed. This is | ||
unfortunate for a change which we know cannot have a real effect as | ||
it propagates upwards through the dependency graph. | ||
|
||
For fixed-output derivations, on the other hand, the name of the | ||
output path only depends on the `outputHash*` and `name` attributes, | ||
while all other attributes are ignored for the purpose of computing | ||
the output path. (The `name` attribute is included because it is | ||
part of the path.) | ||
|
||
As an example, here is the (simplified) Nix expression for | ||
`fetchurl`: | ||
|
||
```nix | ||
{ stdenv, curl }: # The curl program is used for downloading. | ||
|
||
{ url, sha256 }: | ||
|
||
stdenv.mkDerivation { | ||
name = baseNameOf (toString url); | ||
builder = ./builder.sh; | ||
buildInputs = [ curl ]; | ||
|
||
# This is a fixed-output derivation; the output must be a regular | ||
# file with SHA256 hash sha256. | ||
outputHashMode = "flat"; | ||
outputHashAlgo = "sha256"; | ||
outputHash = sha256; | ||
|
||
inherit url; | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This motivation is taken from (going back far enough) Eelco's dissertation; it should be reworded to not use the language, since in this new context, we are describing the store without reference to the language.
Motivation
Describe derivation outputs, and topics about them like input addressing in detail.
Context
Very nice that there is more pre-exsting material in the language manual we can move out, and give a better home, with this.
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.