about summary refs log tree commit diff
path: root/nixos/modules/system/activation
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2018-08-13 19:42:47 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2018-08-14 13:38:18 +0200
commitfc2bde6d7a362a7f75e19f3e445a9b0f528e1681 (patch)
tree856d124bb0b16a530a8c713d01a6c4fb98a892ae /nixos/modules/system/activation
parent249ba3d3ed76e34f61ab7bb2024b013f3feaafb9 (diff)
downloadnixlib-fc2bde6d7a362a7f75e19f3e445a9b0f528e1681.tar
nixlib-fc2bde6d7a362a7f75e19f3e445a9b0f528e1681.tar.gz
nixlib-fc2bde6d7a362a7f75e19f3e445a9b0f528e1681.tar.bz2
nixlib-fc2bde6d7a362a7f75e19f3e445a9b0f528e1681.tar.lz
nixlib-fc2bde6d7a362a7f75e19f3e445a9b0f528e1681.tar.xz
nixlib-fc2bde6d7a362a7f75e19f3e445a9b0f528e1681.tar.zst
nixlib-fc2bde6d7a362a7f75e19f3e445a9b0f528e1681.zip
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.
Diffstat (limited to 'nixos/modules/system/activation')
-rw-r--r--nixos/modules/system/activation/switch-to-configuration.pl12
1 files changed, 12 insertions, 0 deletions
diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl
index ecd35767e01d..b3fe6caf62dc 100644
--- a/nixos/modules/system/activation/switch-to-configuration.pl
+++ b/nixos/modules/system/activation/switch-to-configuration.pl
@@ -412,6 +412,18 @@ system("@systemd@/bin/systemctl", "reset-failed");
 # 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;