Allow building/testing individual systemd units

This commit is contained in:
Eelco Dolstra 2013-11-18 13:18:58 +01:00
parent 174f5813ef
commit 08a85c2152
2 changed files with 66 additions and 28 deletions

View File

@ -652,6 +652,37 @@ $ qemu-system-x86_64 -kernel ./kernel/bzImage -initrd ./initrd/initrd -hda /dev/
</listitem>
</varlistentry>
<varlistentry>
<term><varname>systemd.units.<replaceable>unit-name</replaceable>.unit</varname></term>
<listitem>
<para>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:
<screen>
$ nix-build -A 'config.systemd.units."httpd.service".unit'
</screen>
You can also test individual units, without rebuilding the whole
system, by putting them in
<filename>/run/systemd/system</filename>:
<screen>
$ cp $(nix-build -A 'config.systemd.units."httpd.service".unit')/httpd.service \
/run/systemd/system/tmp-httpd.service
$ systemctl daemon-reload
$ systemctl start tmp-httpd.service
</screen>
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>.
Thats why the unit is installed as
<filename>tmp-httpd.service</filename> here.</para>
</listitem>
</varlistentry>
</variablelist>
</para>

View File

@ -311,8 +311,6 @@ let
'';
};
nixosUnits = mapAttrsToList makeUnit cfg.units;
units = pkgs.runCommand "units" { preferLocalBuild = true; }
''
mkdir -p $out
@ -338,7 +336,7 @@ let
done
done
for i in ${toString nixosUnits}; do
for i in ${toString (mapAttrsToList (n: v: v.unit) cfg.units)}; do
ln -s $i/* $out/
done
@ -387,7 +385,8 @@ in
description = "Definition of systemd units.";
default = {};
type = types.attrsOf types.optionSet;
options = {
options = { name, config, ... }:
{ options = {
text = mkOption {
type = types.str;
description = "Text of this systemd unit.";
@ -412,6 +411,14 @@ in
type = types.listOf types.string;
description = "Units that want (i.e. depend on) this unit.";
};
unit = mkOption {
internal = true;
description = "The generated unit.";
};
};
config = {
unit = makeUnit name config;
};
};
};