summary refs log tree commit diff
path: root/doc/builders/fetchers.xml
blob: f07c310dcdf1d56ba3dd149b4631b1e63bf967a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<chapter xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xml:id="chap-pkgs-fetchers">
 <title>Fetchers</title>
 <para>
  When using Nix, you will frequently need to download source code and other files from the internet. Nixpkgs comes with a few helper functions that allow you to fetch fixed-output derivations in a structured way.
 </para>
 <para>
  The two fetcher primitives are <function>fetchurl</function> and <function>fetchzip</function>. Both of these have two required arguments, a URL and a hash. The hash is typically <literal>sha256</literal>, although many more hash algorithms are supported. Nixpkgs contributors are currently recommended to use <literal>sha256</literal>. This hash will be used by Nix to identify your source. A typical usage of fetchurl is provided below.
 </para>
<programlisting><![CDATA[
{ stdenv, fetchurl }:

stdenv.mkDerivation {
  name = "hello";
  src = fetchurl {
    url = "http://www.example.org/hello.tar.gz";
    sha256 = "1111111111111111111111111111111111111111111111111111";
  };
}
]]></programlisting>
 <para>
  The main difference between <function>fetchurl</function> and <function>fetchzip</function> is in how they store the contents. <function>fetchurl</function> will store the unaltered contents of the URL within the Nix store. <function>fetchzip</function> on the other hand will decompress the archive for you, making files and directories directly accessible in the future. <function>fetchzip</function> can only be used with archives. Despite the name, <function>fetchzip</function> is not limited to .zip files and can also be used with any tarball.
 </para>
 <para>
  <function>fetchpatch</function> works very similarly to <function>fetchurl</function> with the same arguments expected. It expects patch files as a source and 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.
 </para>
 <para>
  Other fetcher functions allow you to add source code directly from a VCS such as subversion or git. These are mostly straightforward names based on the name of the command used with the VCS system. Because they give you a working repository, they act most like <function>fetchzip</function>.
 </para>
 <variablelist>
  <varlistentry>
   <term>
    <literal>fetchsvn</literal>
   </term>
   <listitem>
    <para>
     Used with Subversion. Expects <literal>url</literal> to a Subversion directory, <literal>rev</literal>, and <literal>sha256</literal>.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>fetchgit</literal>
   </term>
   <listitem>
    <para>
     Used with Git. Expects <literal>url</literal> to a Git repo, <literal>rev</literal>, and <literal>sha256</literal>. <literal>rev</literal> in this case can be full the git commit id (SHA1 hash) or a tag name like <literal>refs/tags/v1.0</literal>.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>fetchfossil</literal>
   </term>
   <listitem>
    <para>
     Used with Fossil. Expects <literal>url</literal> to a Fossil archive, <literal>rev</literal>, and <literal>sha256</literal>.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>fetchcvs</literal>
   </term>
   <listitem>
    <para>
     Used with CVS. Expects <literal>cvsRoot</literal>, <literal>tag</literal>, and <literal>sha256</literal>.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>fetchhg</literal>
   </term>
   <listitem>
    <para>
     Used with Mercurial. Expects <literal>url</literal>, <literal>rev</literal>, and <literal>sha256</literal>.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
 <para>
  A number of fetcher functions wrap part of <function>fetchurl</function> and <function>fetchzip</function>. They are mainly convenience functions intended for commonly used destinations of source code in Nixpkgs. These wrapper fetchers are listed below.
 </para>
 <variablelist>
  <varlistentry>
   <term>
    <literal>fetchFromGitHub</literal>
   </term>
   <listitem>
    <para>
     <function>fetchFromGitHub</function> expects four arguments. <literal>owner</literal> is a string corresponding to the GitHub user or organization that controls this repository. <literal>repo</literal> corresponds to the name of the software repository. These are located at the top of every GitHub HTML page as <literal>owner</literal>/<literal>repo</literal>. <literal>rev</literal> corresponds to the Git commit hash or tag (e.g <literal>v1.0</literal>) that will be downloaded from Git. Finally, <literal>sha256</literal> corresponds to the hash of the extracted directory. Again, other hash algorithms are also available but <literal>sha256</literal> is currently preferred.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>fetchFromGitLab</literal>
   </term>
   <listitem>
    <para>
     This is used with GitLab repositories. The arguments expected are very similar to fetchFromGitHub above.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>fetchFromGitiles</literal>
   </term>
   <listitem>
    <para>
     This is used with Gitiles repositories. The arguments expected
     are similar to fetchgit.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>fetchFromBitbucket</literal>
   </term>
   <listitem>
    <para>
     This is used with BitBucket repositories. The arguments expected are very similar to fetchFromGitHub above.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>fetchFromSavannah</literal>
   </term>
   <listitem>
    <para>
     This is used with Savannah repositories. The arguments expected are very similar to fetchFromGitHub above.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>fetchFromRepoOrCz</literal>
   </term>
   <listitem>
    <para>
     This is used with repo.or.cz repositories. The arguments expected are very similar to fetchFromGitHub above.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</chapter>