Home Explore Blog CI



nixpkgs

4th chunk of `doc/build-helpers/fetchers.chapter.md`
6a59d1320cf88517c04ba536da079bb246fe107da3eff98b0000000100000fc0
`fetchurl` returns a [fixed-output derivation](https://nixos.org/manual/nix/stable/glossary.html#gloss-fixed-output-derivation) which downloads content from a given URL and stores the unaltered contents within the Nix store.

It uses {manpage}`curl(1)` internally, and allows its behaviour to be modified by specifying a few attributes in the argument to `fetchurl` (see the documentation for attributes `curlOpts`, `curlOptsList`, and `netrcPhase`).

The resulting [store path](https://nixos.org/manual/nix/stable/store/store-path) is determined by the hash given to `fetchurl`, and also the `name` (or `pname` and `version`) values.

If neither `name` nor `pname` and `version` are specified when calling `fetchurl`, it will default to using the [basename](https://nixos.org/manual/nix/stable/language/builtins.html#builtins-baseNameOf) of `url` or the first element of `urls`.
If `pname` and `version` are specified, `fetchurl` will use those values and will ignore `name`, even if it is also specified.

### Inputs {#sec-pkgs-fetchers-fetchurl-inputs}

`fetchurl` requires an attribute set with the following attributes:

`url` (String; _optional_)
: The URL to download from.

  :::{.note}
  Either `url` or `urls` must be specified, but not both.
  :::

  All URLs of the format [specified here](https://curl.se/docs/url-syntax.html#rfc-3986-plus) are supported.

  _Default value:_ `""`.

`urls` (List of String; _optional_)
: A list of URLs, specifying download locations for the same content.
  Each URL will be tried in order until one of them succeeds with some content or all of them fail.
  See [](#ex-fetchers-fetchurl-nixpkgs-version-multiple-urls) to understand how this attribute affects the behaviour of `fetchurl`.

  :::{.note}
  Either `url` or `urls` must be specified, but not both.
  :::

  _Default value:_ `[]`.

`hash` (String; _optional_)
: Hash of the derivation output of `fetchurl`, following the format for integrity metadata as defined by [SRI](https://www.w3.org/TR/SRI/).
  For more information, see [](#chap-pkgs-fetchers-caveats).

  :::{.note}
  It is recommended that you use the `hash` attribute instead of the other hash-specific attributes that exist for backwards compatibility.

  If `hash` is not specified, you must specify `outputHash` and `outputHashAlgo`, or one of `sha512`, `sha256`, or `sha1`.
  :::

  _Default value:_ `""`.

`outputHash` (String; _optional_)
: Hash of the derivation output of `fetchurl` in the format expected by Nix.
  See [the documentation on the Nix manual](https://nixos.org/manual/nix/stable/language/advanced-attributes.html#adv-attr-outputHash) for more information about its format.

  :::{.note}
  It is recommended that you use the `hash` attribute instead.

  If `outputHash` is specified, you must also specify `outputHashAlgo`.
  :::

  _Default value:_ `""`.

`outputHashAlgo` (String; _optional_)
: Algorithm used to generate the value specified in `outputHash`.
  See [the documentation on the Nix manual](https://nixos.org/manual/nix/stable/language/advanced-attributes.html#adv-attr-outputHashAlgo) for more information about the values it supports.

  :::{.note}
  It is recommended that you use the `hash` attribute instead.

  The value specified in `outputHashAlgo` will be ignored if `outputHash` isn't also specified.
  :::

  _Default value:_ `""`.

`sha1` (String; _optional_)
: SHA-1 hash of the derivation output of `fetchurl` in the format expected by Nix.
  See [the documentation on the Nix manual](https://nixos.org/manual/nix/stable/language/advanced-attributes.html#adv-attr-outputHash) for more information about its format.

  :::{.note}
  It is recommended that you use the `hash` attribute instead.
  :::

  _Default value:_ `""`.

`sha256` (String; _optional_)
: SHA-256 hash of the derivation output of `fetchurl` in the format expected by Nix.
  See [the documentation on the Nix manual](https://nixos.org/manual/nix/stable/language/advanced-attributes.html#adv-attr-outputHash) for more information about its format.

Title: `fetchurl` Inputs: URL, Hashes, and Algorithms
Summary
This section details the input attributes required by the `fetchurl` function in Nixpkgs. It elaborates on the `url` and `urls` attributes, which specify the download location(s) for the content, noting that only one of these attributes should be specified. The section then focuses on the various hash attributes (`hash`, `outputHash`, `outputHashAlgo`, `sha1`, `sha256`) used for verifying the integrity of the downloaded content, emphasizing the recommendation to use the unified `hash` attribute over the older, separate hash attributes for improved compatibility and clarity.