1<chapter xmlns="http://docbook.org/ns/docbook"
2 xmlns:xlink="http://www.w3.org/1999/xlink"
3 xmlns:xi="http://www.w3.org/2001/XInclude"
4 version="5.0"
5 xml:id="sec-getting-sources">
6
7<title>Getting the Sources</title>
8
9<para>By default, NixOS’s <command>nixos-rebuild</command> command
10uses the NixOS and Nixpkgs sources provided by the
11<literal>nixos-unstable</literal> channel (kept in
12<filename>/nix/var/nix/profiles/per-user/root/channels/nixos</filename>).
13To modify NixOS, however, you should check out the latest sources from
14Git. This is as follows:
15
16<screen>
17$ git clone git://github.com/NixOS/nixpkgs.git
18$ cd nixpkgs
19$ git remote add channels git://github.com/NixOS/nixpkgs-channels.git
20$ git remote update channels
21</screen>
22
23This will check out the latest Nixpkgs sources to
24<filename>./nixpkgs</filename> the NixOS sources to
25<filename>./nixpkgs/nixos</filename>. (The NixOS source tree lives in
26a subdirectory of the Nixpkgs repository.) The remote
27<literal>channels</literal> refers to a read-only repository that
28tracks the Nixpkgs/NixOS channels (see <xref linkend="sec-upgrading"/>
29for more information about channels). Thus, the Git branch
30<literal>channels/nixos-14.12</literal> will contain the latest built
31and tested version available in the <literal>nixos-14.12</literal>
32channel.</para>
33
34<para>It’s often inconvenient to develop directly on the master
35branch, since if somebody has just committed (say) a change to GCC,
36then the binary cache may not have caught up yet and you’ll have to
37rebuild everything from source. So you may want to create a local
38branch based on your current NixOS version:
39
40<screen>
41$ nixos-version
4214.04.273.ea1952b (Baboon)
43
44$ git checkout -b local ea1952b
45</screen>
46
47Or, to base your local branch on the latest version available in a
48NixOS channel:
49
50<screen>
51$ git remote update channels
52$ git checkout -b local channels/nixos-14.12
53</screen>
54
55(Replace <literal>nixos-14.12</literal> with the name of the channel
56you want to use.) You can use <command>git merge</command> or
57<command>git rebase</command> to keep your local branch in sync with
58the channel, e.g.
59
60<screen>
61$ git remote update channels
62$ git merge channels/nixos-14.12
63</screen>
64
65You can use <command>git cherry-pick</command> to copy commits from
66your local branch to the upstream branch.</para>
67
68<para>If you want to rebuild your system using your (modified)
69sources, you need to tell <command>nixos-rebuild</command> about them
70using the <option>-I</option> flag:
71
72<screen>
73# nixos-rebuild switch -I nixpkgs=<replaceable>/my/sources</replaceable>/nixpkgs
74</screen>
75
76</para>
77
78<para>If you want <command>nix-env</command> to use the expressions in
79<replaceable>/my/sources</replaceable>, use <command>nix-env -f
80<replaceable>/my/sources</replaceable>/nixpkgs</command>, or change
81the default by adding a symlink in
82<filename>~/.nix-defexpr</filename>:
83
84<screen>
85$ ln -s <replaceable>/my/sources</replaceable>/nixpkgs ~/.nix-defexpr/nixpkgs
86</screen>
87
88You may want to delete the symlink
89<filename>~/.nix-defexpr/channels_root</filename> to prevent root’s
90NixOS channel from clashing with your own tree.</para>
91
92<!-- FIXME: not sure what this means.
93<para>You should not pass the base directory
94<filename><replaceable>/my/sources</replaceable></filename>
95to <command>nix-env</command>, as it will break after interpreting expressions
96in <filename>nixos/</filename> as packages.</para>
97-->
98
99</chapter>