From fc2bde6d7a362a7f75e19f3e445a9b0f528e1681 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Mon, 13 Aug 2018 19:42:47 +0200 Subject: [PATCH] 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. --- nixos/doc/manual/release-notes/rl-1809.xml | 7 +++++++ .../system/activation/switch-to-configuration.pl | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-1809.xml b/nixos/doc/manual/release-notes/rl-1809.xml index d527984f5ef1..0cb4874a1a21 100644 --- a/nixos/doc/manual/release-notes/rl-1809.xml +++ b/nixos/doc/manual/release-notes/rl-1809.xml @@ -422,6 +422,13 @@ inherit (pkgs.nixos { The module option is now defaulted to true. + + + The config activation script of nixos-rebuild now + reloads + all user units for each authenticated user. + + 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*(?\d+)\s+(?\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;