nixos/switch-to-configuration: reload user units

When rebuilding you have to manually run `systemctl --user
daemon-reload`. It gathers all authenticated users using
`loginctl list-user` and runs `daemon-reload` for each of them.

This is a first step towards a `nixos-rebuild` which is able to reload
user units from systemd. The entire task is fairly hard, however I
consider this patch usable as it allows to restart units without running
`daemon-reload` for each authenticated user.

Changed files
+19
nixos
doc
manual
release-notes
modules
system
+7
nixos/doc/manual/release-notes/rl-1809.xml
···
The module option <option>nix.useSandbox</option> is now defaulted to <literal>true</literal>.
</para>
</listitem>
</itemizedlist>
</section>
</section>
···
The module option <option>nix.useSandbox</option> is now defaulted to <literal>true</literal>.
</para>
</listitem>
+
<listitem>
+
<para>
+
The config activation script of <literal>nixos-rebuild</literal> now
+
<link xlink:href="https://www.freedesktop.org/software/systemd/man/systemctl.html#Manager%20Lifecycle%20Commands">reloads</link>
+
all user units for each authenticated user.
+
</para>
+
</listitem>
</itemizedlist>
</section>
</section>
+12
nixos/modules/system/activation/switch-to-configuration.pl
···
# Make systemd reload its units.
system("@systemd@/bin/systemctl", "daemon-reload") == 0 or $res = 3;
# Set the new tmpfiles
print STDERR "setting up tmpfiles\n";
system("@systemd@/bin/systemd-tmpfiles", "--create", "--remove", "--exclude-prefix=/dev") == 0 or $res = 3;
···
# Make systemd reload its units.
system("@systemd@/bin/systemctl", "daemon-reload") == 0 or $res = 3;
+
# Reload user units
+
open my $listActiveUsers, '-|', '@systemd@/bin/loginctl', 'list-users', '--no-legend';
+
while (my $f = <$listActiveUsers>) {
+
next unless $f =~ /^\s*(?<uid>\d+)\s+(?<user>\S+)/;
+
my ($uid, $name) = ($+{uid}, $+{user});
+
print STDERR "reloading user units for $name...\n";
+
+
system("su", "-l", $name, "-c", "XDG_RUNTIME_DIR=/run/user/$uid @systemd@/bin/systemctl --user daemon-reload");
+
}
+
+
close $listActiveUsers;
+
# Set the new tmpfiles
print STDERR "setting up tmpfiles\n";
system("@systemd@/bin/systemd-tmpfiles", "--create", "--remove", "--exclude-prefix=/dev") == 0 or $res = 3;