lol

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.

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