2020-12-16 18:36:46 +01:00
# Fetchers {#chap-pkgs-fetchers}
2022-08-02 18:50:05 +02:00
Building software with Nix often requires downloading source code and other files from the internet.
`nixpkgs` provides *fetchers* for different protocols and services. Fetchers are functions that simplify downloading files.
2020-12-16 18:36:46 +01:00
2023-03-27 22:39:11 +02:00
## Caveats {#chap-pkgs-fetchers-caveats}
2021-09-19 19:32:35 +02:00
2022-08-02 18:52:08 +02:00
Fetchers create [fixed output derivations ](https://nixos.org/manual/nix/stable/#fixed-output-drvs ) from downloaded files.
Nix can reuse the downloaded files via the hash of the resulting derivation.
The fact that the hash belongs to the Nix derivation output and not the file itself can lead to confusion.
For example, consider the following fetcher:
2021-09-19 19:32:35 +02:00
2022-06-22 18:13:16 +02:00
```nix
fetchurl {
url = "http://www.example.org/hello-1.0.tar.gz";
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
hash = "sha256-lTeyxzJNQeMdu1IVdovNMtgn77jRIhSybLdMbTkf2Ww=";
2022-06-22 18:13:16 +02:00
};
```
A common mistake is to update a fetcher’ s URL, or a version parameter, without updating the hash.
```nix
fetchurl {
url = "http://www.example.org/hello-1.1.tar.gz";
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
hash = "sha256-lTeyxzJNQeMdu1IVdovNMtgn77jRIhSybLdMbTkf2Ww=";
2022-06-22 18:13:16 +02:00
};
```
2022-08-02 18:51:38 +02:00
**This will reuse the old contents**.
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
Remember to invalidate the hash argument, in this case by setting the `hash` attribute to an empty string.
2022-06-22 18:13:16 +02:00
```nix
fetchurl {
url = "http://www.example.org/hello-1.1.tar.gz";
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
hash = "";
2022-06-22 18:13:16 +02:00
};
```
2022-08-02 18:51:09 +02:00
Use the resulting error message to determine the correct hash.
2022-08-02 19:07:36 +02:00
```
error: hash mismatch in fixed-output derivation '/path/to/my.drv':
specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
got: sha256-lTeyxzJNQeMdu1IVdovNMtgn77jRIhSybLdMbTkf2Ww=
2022-08-02 19:07:36 +02:00
```
2022-06-22 18:13:16 +02:00
2022-08-02 18:50:22 +02:00
A similar problem arises while testing changes to a fetcher's implementation. If the output of the derivation already exists in the Nix store, test failures can go undetected. The [`invalidateFetcherByDrvHash` ](#tester-invalidateFetcherByDrvHash ) function helps prevent reusing cached derivations.
2021-09-19 19:32:35 +02:00
## `fetchurl` and `fetchzip` {#fetchurl}
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
Two basic fetchers are `fetchurl` and `fetchzip` . Both of these have two required arguments, a URL and a hash. The hash is typically `hash` , although many more hash algorithms are supported. Nixpkgs contributors are currently recommended to use `hash` . This hash will be used by Nix to identify your source. A typical usage of `fetchurl` is provided below.
2020-12-16 18:36:46 +01:00
```nix
{ stdenv, fetchurl }:
stdenv.mkDerivation {
name = "hello";
src = fetchurl {
url = "http://www.example.org/hello.tar.gz";
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
hash = "sha256-BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=";
2020-12-16 18:36:46 +01:00
};
}
```
2022-03-10 20:43:29 +01:00
The main difference between `fetchurl` and `fetchzip` is in how they store the contents. `fetchurl` will store the unaltered contents of the URL within the Nix store. `fetchzip` on the other hand, will decompress the archive for you, making files and directories directly accessible in the future. `fetchzip` can only be used with archives. Despite the name, `fetchzip` is not limited to .zip files and can also be used with any tarball.
2020-12-16 18:36:46 +01:00
2022-06-03 11:17:25 +02:00
## `fetchpatch` {#fetchpatch}
2022-03-10 20:43:29 +01:00
`fetchpatch` works very similarly to `fetchurl` with the same arguments expected. It expects patch files as a source and performs normalization on them before computing the checksum. For example, it will remove comments or other unstable parts that are sometimes added by version control systems and can change over time.
2020-12-16 18:36:46 +01:00
2022-06-03 11:17:25 +02:00
- `relative` : Similar to using `git-diff` 's `--relative` flag, only keep changes inside the specified directory, making paths relative to it.
- `stripLen` : Remove the first `stripLen` components of pathnames in the patch.
2022-11-15 13:33:25 +01:00
- `decode` : Pipe the downloaded data through this command before processing it as a patch.
2022-06-03 11:17:25 +02:00
- `extraPrefix` : Prefix pathnames by this string.
- `excludes` : Exclude files matching these patterns (applies after the above arguments).
- `includes` : Include only files matching these patterns (applies after the above arguments).
- `revert` : Revert the patch.
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
Note that because the checksum is computed after applying these effects, using or modifying these arguments will have no effect unless the `hash` argument is changed as well.
2022-06-03 11:17:25 +02:00
2021-09-19 19:32:35 +02:00
Most other fetchers return a directory rather than a single file.
2020-12-16 18:36:46 +01:00
2021-06-05 21:22:45 +02:00
## `fetchsvn` {#fetchsvn}
2020-12-16 18:36:46 +01:00
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
Used with Subversion. Expects `url` to a Subversion directory, `rev` , and `hash` .
2020-12-16 18:36:46 +01:00
2021-06-05 21:22:45 +02:00
## `fetchgit` {#fetchgit}
2020-12-16 18:36:46 +01:00
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
Used with Git. Expects `url` to a Git repo, `rev` , and `hash` . `rev` in this case can be full the git commit id (SHA1 hash) or a tag name like `refs/tags/v1.0` .
2020-12-16 18:36:46 +01:00
2022-03-10 20:43:29 +01:00
Additionally, the following optional arguments can be given: `fetchSubmodules = true` makes `fetchgit` also fetch the submodules of a repository. If `deepClone` is set to true, the entire repository is cloned as opposing to just creating a shallow clone. `deepClone = true` also implies `leaveDotGit = true` which means that the `.git` directory of the clone won't be removed after checkout.
2020-12-21 14:21:11 +01:00
2022-08-04 21:26:03 +02:00
If only parts of the repository are needed, `sparseCheckout` can be used. This will prevent git from fetching unnecessary blobs from server, see [git sparse-checkout ](https://git-scm.com/docs/git-sparse-checkout ) for more information:
2021-09-08 04:33:50 +02:00
```nix
{ stdenv, fetchgit }:
stdenv.mkDerivation {
name = "hello";
src = fetchgit {
url = "https://...";
2022-11-07 19:42:19 +01:00
sparseCheckout = [
"directory/to/be/included"
"another/directory"
];
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
2021-09-08 04:33:50 +02:00
};
}
```
2021-06-05 21:22:45 +02:00
## `fetchfossil` {#fetchfossil}
2020-12-16 18:36:46 +01:00
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
Used with Fossil. Expects `url` to a Fossil archive, `rev` , and `hash` .
2020-12-16 18:36:46 +01:00
2021-06-05 21:22:45 +02:00
## `fetchcvs` {#fetchcvs}
2020-12-16 18:36:46 +01:00
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
Used with CVS. Expects `cvsRoot` , `tag` , and `hash` .
2020-12-16 18:36:46 +01:00
2021-06-05 21:22:45 +02:00
## `fetchhg` {#fetchhg}
2020-12-16 18:36:46 +01:00
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
Used with Mercurial. Expects `url` , `rev` , and `hash` .
2020-12-16 18:36:46 +01:00
A number of fetcher functions wrap part of `fetchurl` and `fetchzip` . They are mainly convenience functions intended for commonly used destinations of source code in Nixpkgs. These wrapper fetchers are listed below.
2022-03-21 17:39:17 +01:00
## `fetchFromGitea` {#fetchfromgitea}
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
`fetchFromGitea` expects five arguments. `domain` is the gitea server name. `owner` is a string corresponding to the Gitea user or organization that controls this repository. `repo` corresponds to the name of the software repository. These are located at the top of every Gitea HTML page as `owner` /`repo`. `rev` corresponds to the Git commit hash or tag (e.g `v1.0` ) that will be downloaded from Git. Finally, `hash` corresponds to the hash of the extracted directory. Again, other hash algorithms are also available but `hash` is currently preferred.
2022-03-21 17:39:17 +01:00
2021-06-05 21:22:45 +02:00
## `fetchFromGitHub` {#fetchfromgithub}
2020-12-16 18:36:46 +01:00
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
`fetchFromGitHub` expects four arguments. `owner` is a string corresponding to the GitHub user or organization that controls this repository. `repo` corresponds to the name of the software repository. These are located at the top of every GitHub HTML page as `owner` /`repo`. `rev` corresponds to the Git commit hash or tag (e.g `v1.0` ) that will be downloaded from Git. Finally, `hash` corresponds to the hash of the extracted directory. Again, other hash algorithms are also available, but `hash` is currently preferred.
2020-12-16 18:36:46 +01:00
2023-06-07 10:51:48 +02:00
To use a different GitHub instance, use `githubBase` (defaults to `"github.com"` ).
2020-12-21 14:21:11 +01:00
`fetchFromGitHub` uses `fetchzip` to download the source archive generated by GitHub for the specified revision. If `leaveDotGit` , `deepClone` or `fetchSubmodules` are set to `true` , `fetchFromGitHub` will use `fetchgit` instead. Refer to its section for documentation of these options.
2021-06-05 21:22:45 +02:00
## `fetchFromGitLab` {#fetchfromgitlab}
2020-12-16 18:36:46 +01:00
2023-06-07 10:51:48 +02:00
This is used with GitLab repositories. It behaves similarly to `fetchFromGitHub` , and expects `owner` , `repo` , `rev` , and `hash` .
To use a specific GitLab instance, use `domain` (defaults to `"gitlab.com"` ).
2020-12-16 18:36:46 +01:00
2021-06-05 21:22:45 +02:00
## `fetchFromGitiles` {#fetchfromgitiles}
2020-12-16 18:36:46 +01:00
2022-03-10 20:43:29 +01:00
This is used with Gitiles repositories. The arguments expected are similar to `fetchgit` .
2020-12-16 18:36:46 +01:00
2021-06-05 21:22:45 +02:00
## `fetchFromBitbucket` {#fetchfrombitbucket}
2020-12-16 18:36:46 +01:00
2023-06-07 10:51:48 +02:00
This is used with BitBucket repositories. The arguments expected are very similar to `fetchFromGitHub` above.
2020-12-16 18:36:46 +01:00
2021-06-05 21:22:45 +02:00
## `fetchFromSavannah` {#fetchfromsavannah}
2020-12-16 18:36:46 +01:00
2022-03-10 20:43:29 +01:00
This is used with Savannah repositories. The arguments expected are very similar to `fetchFromGitHub` above.
2020-12-16 18:36:46 +01:00
2021-06-05 21:22:45 +02:00
## `fetchFromRepoOrCz` {#fetchfromrepoorcz}
2020-12-16 18:36:46 +01:00
2022-03-10 20:43:29 +01:00
This is used with repo.or.cz repositories. The arguments expected are very similar to `fetchFromGitHub` above.
2020-10-31 11:28:06 +01:00
2021-06-05 21:22:45 +02:00
## `fetchFromSourcehut` {#fetchfromsourcehut}
2020-10-31 11:28:06 +01:00
2021-12-04 17:01:49 +01:00
This is used with sourcehut repositories. Similar to `fetchFromGitHub` above,
doc: use sri hash syntax
The nixpkgs manual contains references to both sri hash and explicit
sha256 attributes. This is at best confusing to new users. Since the
final destination is exclusive use of sri hashes, see nixos/rfcs#131,
might as well push new users in that direction gently.
Notable exceptions to sri hash support are builtins.fetchTarball,
cataclysm-dda, coq, dockerTools.pullimage, elixir.override, and
fetchCrate. None, other than builtins.fetchTarball, are fundamentally
incompatible, but all currently accept explicit sha256 attributes as
input. Because adding backwards compatibility is out of scope for this
change, they have been left intact, but migration to sri format has been
made for any using old hash formats.
All hashes have been manually tested to be accurate, and updates were
only made for missing upstream artefacts or bugs.
2022-12-03 20:49:00 +01:00
it expects `owner` , `repo` , `rev` and `hash` , but don't forget the tilde (~)
2021-12-04 17:01:49 +01:00
in front of the username! Expected arguments also include `vc` ("git" (default)
or "hg"), `domain` and `fetchSubmodules` .
If `fetchSubmodules` is `true` , `fetchFromSourcehut` uses `fetchgit`
or `fetchhg` with `fetchSubmodules` or `fetchSubrepos` set to `true` ,
2022-03-10 20:43:29 +01:00
respectively. Otherwise, the fetcher uses `fetchzip` .
2023-02-05 15:33:51 +01:00
## `requireFile` {#requirefile}
`requireFile` allows requesting files that cannot be fetched automatically, but whose content is known.
This is a useful last-resort workaround for license restrictions that prohibit redistribution, or for downloads that are only accessible after authenticating interactively in a browser.
If the requested file is present in the Nix store, the resulting derivation will not be built, because its expected output is already available.
Otherwise, the builder will run, but fail with a message explaining to the user how to provide the file. The following code, for example:
```
requireFile {
name = "jdk-${version}_linux-x64_bin.tar.gz";
url = "https://www.oracle.com/java/technologies/javase-jdk11-downloads.html";
sha256 = "94bd34f85ee38d3ef59e5289ec7450b9443b924c55625661fffe66b03f2c8de2";
}
```
results in this error message:
```
***
Unfortunately, we cannot download file jdk-11.0.10_linux-x64_bin.tar.gz automatically.
Please go to https://www.oracle.com/java/technologies/javase-jdk11-downloads.html to download it yourself, and add it to the Nix store
using either
nix-store --add-fixed sha256 jdk-11.0.10_linux-x64_bin.tar.gz
or
nix-prefetch-url --type sha256 file:///path/to/jdk-11.0.10_linux-x64_bin.tar.gz
***
```