at 18.03-beta 3.7 kB view raw
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-building-parts"> 6 7<title>Building Specific Parts of NixOS</title> 8 9<para>With the command <command>nix-build</command>, you can build 10specific parts of your NixOS configuration. This is done as follows: 11 12<screen> 13$ cd <replaceable>/path/to/nixpkgs/nixos</replaceable> 14$ nix-build -A config.<replaceable>option</replaceable></screen> 15 16where <replaceable>option</replaceable> is a NixOS option with type 17“derivation” (i.e. something that can be built). Attributes of 18interest include: 19 20<variablelist> 21 22 <varlistentry> 23 <term><varname>system.build.toplevel</varname></term> 24 <listitem> 25 <para>The top-level option that builds the entire NixOS system. 26 Everything else in your configuration is indirectly pulled in by 27 this option. This is what <command>nixos-rebuild</command> 28 builds and what <filename>/run/current-system</filename> points 29 to afterwards.</para> 30 31 <para>A shortcut to build this is: 32 33<screen> 34$ nix-build -A system</screen> 35 </para> 36 </listitem> 37 </varlistentry> 38 39 <varlistentry> 40 <term><varname>system.build.manual.manual</varname></term> 41 <listitem><para>The NixOS manual.</para></listitem> 42 </varlistentry> 43 44 <varlistentry> 45 <term><varname>system.build.etc</varname></term> 46 <listitem><para>A tree of symlinks that form the static parts of 47 <filename>/etc</filename>.</para></listitem> 48 </varlistentry> 49 50 <varlistentry> 51 <term><varname>system.build.initialRamdisk</varname></term> 52 <term><varname>system.build.kernel</varname></term> 53 <listitem> 54 <para>The initial ramdisk and kernel of the system. This allows 55 a quick way to test whether the kernel and the initial ramdisk 56 boot correctly, by using QEMU’s <option>-kernel</option> and 57 <option>-initrd</option> options: 58 59<screen> 60$ nix-build -A config.system.build.initialRamdisk -o initrd 61$ nix-build -A config.system.build.kernel -o kernel 62$ qemu-system-x86_64 -kernel ./kernel/bzImage -initrd ./initrd/initrd -hda /dev/null 63</screen> 64 65 </para> 66 </listitem> 67 </varlistentry> 68 69 <varlistentry> 70 <term><varname>system.build.nixos-rebuild</varname></term> 71 <term><varname>system.build.nixos-install</varname></term> 72 <term><varname>system.build.nixos-generate-config</varname></term> 73 <listitem> 74 <para>These build the corresponding NixOS commands.</para> 75 </listitem> 76 </varlistentry> 77 78 <varlistentry> 79 <term><varname>systemd.units.<replaceable>unit-name</replaceable>.unit</varname></term> 80 <listitem> 81 <para>This builds the unit with the specified name. Note that 82 since unit names contain dots 83 (e.g. <literal>httpd.service</literal>), you need to put them 84 between quotes, like this: 85 86<screen> 87$ nix-build -A 'config.systemd.units."httpd.service".unit' 88</screen> 89 90 You can also test individual units, without rebuilding the whole 91 system, by putting them in 92 <filename>/run/systemd/system</filename>: 93 94<screen> 95$ cp $(nix-build -A 'config.systemd.units."httpd.service".unit')/httpd.service \ 96 /run/systemd/system/tmp-httpd.service 97# systemctl daemon-reload 98# systemctl start tmp-httpd.service 99</screen> 100 101 Note that the unit must not have the same name as any unit in 102 <filename>/etc/systemd/system</filename> since those take 103 precedence over <filename>/run/systemd/system</filename>. 104 That’s why the unit is installed as 105 <filename>tmp-httpd.service</filename> here.</para> 106 </listitem> 107 </varlistentry> 108 109</variablelist> 110 111</para> 112 113</chapter>