Home Explore Blog Models CI



nixpkgs

12th chunk of `doc/build-helpers/fetchers.chapter.md`
9b8fa19511d4ef46f2d8445dad03d17c0b434a6f6510e042000000010000100d
      debianRevision = "5";
      patch = "Add-quotes-to-SOAPAction-header-in-SoapClient.patch";
      hash = "sha256-xA8Wnrpr31H8wy3zHSNfezFNjUJt1HbSXn3qUMzeKc0=";
    })
  ];

  # ...
}
```

Patches are fetched from `sources.debian.org`, and so must come from a
package version that was uploaded to the Debian archive.  Packages may
be removed from there once that specific version isn't in any suite
anymore (stable, testing, unstable, etc.), so maintainers should use
`copy-tarballs.pl` to archive the patch if it needs to be available
longer-term.



## `fetchsvn` {#fetchsvn}

Used with Subversion. Expects `url` to a Subversion directory, `rev`, and `hash`.

## `fetchgit` {#fetchgit}

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`.

If you want to fetch a tag you should pass the `tag` parameter instead of `rev` which has the same effect as setting `rev = "refs/tags"/${version}"`.
This is safer than just setting `rev = version` w.r.t. possible branch and tag name conflicts.

Additionally, the following optional arguments can be given:

*`fetchSubmodules`* (Boolean)

: Whether to also fetch the submodules of a repository.

*`fetchLFS`* (Boolean)

: Whether to fetch LFS objects.

*`preFetch`* (String)

: Shell code to be executed before the repository has been fetched, to allow
  changing the environment the fetcher runs in.

*`postFetch`* (String)

: Shell code executed after the repository has been fetched successfully.
  This can do things like check or transform the file.

*`leaveDotGit`* (Boolean)

: Whether the `.git` directory of the clone should *not* be removed after checkout.

  Be warned though that the git repository format is not stable and this flag is therefore not suitable for actual use by itself.
  Only use this for testing purposes or in conjunction with removing the `.git` directory in `postFetch`.

*`deepClone`* (Boolean)

: Clone the entire repository as opposing to just creating a shallow clone.
  This implies `leaveDotGit`.

*`fetchTags`* (Boolean)

: Whether to fetch all tags from the remote repository. This is useful when the build process needs to run `git describe` or other commands that require tag information to be available. This parameter implies `leaveDotGit`, as tags are stored in the `.git` directory.

*`sparseCheckout`* (List of String)

: Prevent git from fetching unnecessary blobs from server.
  This is useful if only parts of the repository are needed.

  ::: {.example #ex-fetchgit-sparseCheckout}

  # Use `sparseCheckout` to only include some directories:

  ```nix
  { stdenv, fetchgit }:

  stdenv.mkDerivation {
    name = "hello";
    src = fetchgit {
      url = "https://...";
      sparseCheckout = [
        "directory/to/be/included"
        "another/directory"
      ];
      hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
    };
  }
  ```
  :::

  See [git sparse-checkout](https://git-scm.com/docs/git-sparse-checkout) for more information.

*`rootDir`* (String)

: When not empty, copy only contents of the subdirectory of the repository to the result. Automatically sets `sparseCheckout` and `nonConeMode` to avoid checking out any extra pieces. Incompatible with `leaveDotGit`.

Some additional parameters for niche use-cases can be found listed in the function parameters in the declaration of `fetchgit`: `pkgs/build-support/fetchgit/default.nix`.
Future parameters additions might also happen without immediately being documented here.

## `fetchfossil` {#fetchfossil}

Used with Fossil. Expects `url` to a Fossil archive, `rev`, and `hash`.

## `fetchcvs` {#fetchcvs}

Used with CVS. Expects `cvsRoot`, `tag`, and `hash`.

## `fetchhg` {#fetchhg}

Used with Mercurial. Expects `url`, `rev`, `hash`, overridable with [`<pkg>.overrideAttrs`](#sec-pkg-overrideAttrs).

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.

Title: Advanced Fetchers: `fetchgit` Options, `fetchDebianPatch` Caveats, and Other Version Control Fetchers (`fetchsvn`, `fetchfossil`, `fetchcvs`, `fetchhg`)
Summary
This section begins with a warning regarding `fetchDebianPatch`, noting that patches sourced from `sources.debian.org` may be removed if the package version is no longer in any Debian suite, advising maintainers to archive long-term patches using `copy-tarballs.pl`. It then introduces `fetchsvn` for Subversion repositories and `fetchgit` for Git repositories, both requiring a `url`, `rev` (commit ID or tag), and `hash`. `fetchgit` also supports a `tag` parameter for safer tag fetching and offers numerous optional arguments: `fetchSubmodules`, `fetchLFS`, `preFetch`/`postFetch` hooks, `leaveDotGit`, `deepClone`, `fetchTags`, `sparseCheckout` (with an example), and `rootDir` for extracting subdirectories. The document then briefly outlines `fetchfossil` for Fossil archives, `fetchcvs` for CVS, and `fetchhg` for Mercurial. It concludes by mentioning that a number of fetcher functions wrap `fetchurl` and `fetchzip` as convenience functions for common source code destinations.