2014-08-24 19:18:18 +02:00
|
|
|
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
|
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
|
|
|
version="5.0"
|
|
|
|
|
xml:id="sec-getting-sources">
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<title>Getting the Sources</title>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
By default, NixOS’s <command>nixos-rebuild</command> command uses the NixOS
|
|
|
|
|
and Nixpkgs sources provided by the <literal>nixos</literal> channel (kept in
|
|
|
|
|
<filename>/nix/var/nix/profiles/per-user/root/channels/nixos</filename>). To
|
|
|
|
|
modify NixOS, however, you should check out the latest sources from Git. This
|
|
|
|
|
is as follows:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>git clone https://github.com/NixOS/nixpkgs
|
|
|
|
|
<prompt>$ </prompt>cd nixpkgs
|
2019-10-17 19:43:07 +02:00
|
|
|
|
<prompt>$ </prompt>git remote update origin
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
This will check out the latest Nixpkgs sources to
|
|
|
|
|
<filename>./nixpkgs</filename> the NixOS sources to
|
|
|
|
|
<filename>./nixpkgs/nixos</filename>. (The NixOS source tree lives in a
|
2019-10-17 19:43:07 +02:00
|
|
|
|
subdirectory of the Nixpkgs repository.) The
|
|
|
|
|
<literal>nixpkgs</literal> repository has branches that correspond
|
|
|
|
|
to each Nixpkgs/NixOS channel (see <xref linkend="sec-upgrading"/> for more
|
2019-09-19 19:17:30 +02:00
|
|
|
|
information about channels). Thus, the Git branch
|
2019-10-17 19:43:07 +02:00
|
|
|
|
<literal>origin/nixos-17.03</literal> will contain the latest built and
|
2019-09-19 19:17:30 +02:00
|
|
|
|
tested version available in the <literal>nixos-17.03</literal> channel.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
It’s often inconvenient to develop directly on the master branch, since if
|
|
|
|
|
somebody has just committed (say) a change to GCC, then the binary cache may
|
|
|
|
|
not have caught up yet and you’ll have to rebuild everything from source.
|
|
|
|
|
So you may want to create a local branch based on your current NixOS version:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>nixos-version
|
2017-03-25 20:14:04 +01:00
|
|
|
|
17.09pre104379.6e0b727 (Hummingbird)
|
2015-05-20 14:16:00 +02:00
|
|
|
|
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>git checkout -b local 6e0b727
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Or, to base your local branch on the latest version available in a NixOS
|
|
|
|
|
channel:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-10-17 19:43:07 +02:00
|
|
|
|
<prompt>$ </prompt>git remote update origin
|
|
|
|
|
<prompt>$ </prompt>git checkout -b local origin/nixos-17.03
|
2015-05-20 14:16:00 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
(Replace <literal>nixos-17.03</literal> with the name of the channel you want
|
|
|
|
|
to use.) You can use <command>git merge</command> or <command>git
|
|
|
|
|
rebase</command> to keep your local branch in sync with the channel, e.g.
|
2015-05-20 14:16:00 +02:00
|
|
|
|
<screen>
|
2019-10-17 19:43:07 +02:00
|
|
|
|
<prompt>$ </prompt>git remote update origin
|
|
|
|
|
<prompt>$ </prompt>git merge origin/nixos-17.03
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
You can use <command>git cherry-pick</command> to copy commits from your
|
|
|
|
|
local branch to the upstream branch.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
If you want to rebuild your system using your (modified) sources, you need to
|
|
|
|
|
tell <command>nixos-rebuild</command> about them using the
|
|
|
|
|
<option>-I</option> flag:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt># </prompt>nixos-rebuild switch -I nixpkgs=<replaceable>/my/sources</replaceable>/nixpkgs
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
If you want <command>nix-env</command> to use the expressions in
|
|
|
|
|
<replaceable>/my/sources</replaceable>, use <command>nix-env -f
|
|
|
|
|
<replaceable>/my/sources</replaceable>/nixpkgs</command>, or change the
|
|
|
|
|
default by adding a symlink in <filename>~/.nix-defexpr</filename>:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>ln -s <replaceable>/my/sources</replaceable>/nixpkgs ~/.nix-defexpr/nixpkgs
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
You may want to delete the symlink
|
|
|
|
|
<filename>~/.nix-defexpr/channels_root</filename> to prevent root’s NixOS
|
|
|
|
|
channel from clashing with your own tree (this may break the
|
|
|
|
|
command-not-found utility though). If you want to go back to the default
|
|
|
|
|
state, you may just remove the <filename>~/.nix-defexpr</filename> directory
|
|
|
|
|
completely, log out and log in again and it should have been recreated with a
|
|
|
|
|
link to the root channels.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<!-- FIXME: not sure what this means.
|
|
|
|
|
<para>You should not pass the base directory
|
|
|
|
|
<filename><replaceable>/my/sources</replaceable></filename>
|
|
|
|
|
to <command>nix-env</command>, as it will break after interpreting expressions
|
|
|
|
|
in <filename>nixos/</filename> as packages.</para>
|
|
|
|
|
-->
|
2014-12-14 11:26:08 +01:00
|
|
|
|
</chapter>
|