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-building-parts">
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<title>Building Specific Parts of NixOS</title>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
With the command <command>nix-build</command>, you can build specific parts
|
|
|
|
|
of your NixOS configuration. This is done as follows:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>cd <replaceable>/path/to/nixpkgs/nixos</replaceable>
|
|
|
|
|
<prompt>$ </prompt>nix-build -A config.<replaceable>option</replaceable></screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
where <replaceable>option</replaceable> is a NixOS option with type
|
|
|
|
|
“derivation” (i.e. something that can be built). Attributes of interest
|
|
|
|
|
include:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<variablelist>
|
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
|
<term>
|
|
|
|
|
<varname>system.build.toplevel</varname>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</term>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
The top-level option that builds the entire NixOS system. Everything else
|
|
|
|
|
in your configuration is indirectly pulled in by this option. This is
|
|
|
|
|
what <command>nixos-rebuild</command> builds and what
|
|
|
|
|
<filename>/run/current-system</filename> points to afterwards.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
A shortcut to build this is:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>nix-build -A system</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</varlistentry>
|
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
|
<term>
|
2018-09-06 21:17:44 +02:00
|
|
|
|
<varname>system.build.manual.manualHTML</varname>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</term>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
|
|
|
|
The NixOS manual.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</varlistentry>
|
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
|
<term>
|
|
|
|
|
<varname>system.build.etc</varname>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</term>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
A tree of symlinks that form the static parts of
|
|
|
|
|
<filename>/etc</filename>.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</varlistentry>
|
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
|
<term>
|
|
|
|
|
<varname>system.build.initialRamdisk</varname>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</term>
|
2018-06-01 03:03:51 +02:00
|
|
|
|
<term>
|
|
|
|
|
<varname>system.build.kernel</varname>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</term>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
The initial ramdisk and kernel of the system. This allows a quick way to
|
|
|
|
|
test whether the kernel and the initial ramdisk boot correctly, by using
|
|
|
|
|
QEMU’s <option>-kernel</option> and <option>-initrd</option> options:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>nix-build -A config.system.build.initialRamdisk -o initrd
|
|
|
|
|
<prompt>$ </prompt>nix-build -A config.system.build.kernel -o kernel
|
|
|
|
|
<prompt>$ </prompt>qemu-system-x86_64 -kernel ./kernel/bzImage -initrd ./initrd/initrd -hda /dev/null
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</varlistentry>
|
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
|
<term>
|
|
|
|
|
<varname>system.build.nixos-rebuild</varname>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</term>
|
2018-06-01 03:03:51 +02:00
|
|
|
|
<term>
|
|
|
|
|
<varname>system.build.nixos-install</varname>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</term>
|
2018-06-01 03:03:51 +02:00
|
|
|
|
<term>
|
|
|
|
|
<varname>system.build.nixos-generate-config</varname>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</term>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
|
|
|
|
These build the corresponding NixOS commands.
|
|
|
|
|
</para>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</varlistentry>
|
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
|
<term>
|
|
|
|
|
<varname>systemd.units.<replaceable>unit-name</replaceable>.unit</varname>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</term>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
This builds the unit with the specified name. Note that since unit names
|
|
|
|
|
contain dots (e.g. <literal>httpd.service</literal>), you need to put
|
|
|
|
|
them between quotes, like this:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>nix-build -A 'config.systemd.units."httpd.service".unit'
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
You can also test individual units, without rebuilding the whole system,
|
|
|
|
|
by putting them in <filename>/run/systemd/system</filename>:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>cp $(nix-build -A 'config.systemd.units."httpd.service".unit')/httpd.service \
|
2014-08-24 19:18:18 +02:00
|
|
|
|
/run/systemd/system/tmp-httpd.service
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt># </prompt>systemctl daemon-reload
|
|
|
|
|
<prompt># </prompt>systemctl start tmp-httpd.service
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Note that the unit must not have the same name as any unit in
|
|
|
|
|
<filename>/etc/systemd/system</filename> since those take precedence over
|
|
|
|
|
<filename>/run/systemd/system</filename>. That’s why the unit is
|
|
|
|
|
installed as <filename>tmp-httpd.service</filename> here.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</varlistentry>
|
|
|
|
|
</variablelist>
|
|
|
|
|
</para>
|
2016-06-01 16:23:32 +02:00
|
|
|
|
</chapter>
|