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