From f7215c9b5b47dfb0a6dbe87ff33d7730729a32e5 Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Tue, 20 Sep 2016 15:21:08 +0800 Subject: [PATCH] dbus: add socket activation but do not enable it The following changes are included: 1) install user unit files from upstream dbus 2) use absolute paths to config for --system and --session instances 3) make socket activation of user units configurable There has been a number of PRs to address this, so this one does the bare minimum, which is to make the functionality available and configurable but defaults to off. Related PRs: - #18382 - #18222 --- nixos/modules/services/system/dbus.nix | 47 +++++++++++++++---- .../services/x11/display-managers/default.nix | 9 +--- pkgs/development/libraries/dbus/default.nix | 5 +- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/nixos/modules/services/system/dbus.nix b/nixos/modules/services/system/dbus.nix index 6c4833afbe8b..6eb7f268fc87 100644 --- a/nixos/modules/services/system/dbus.nix +++ b/nixos/modules/services/system/dbus.nix @@ -8,7 +8,7 @@ let cfg = config.services.dbus; - homeDir = "/var/run/dbus"; + homeDir = "/run/dbus"; systemExtraxml = concatStrings (flip concatMap cfg.packages (d: [ "${d}/share/dbus-1/system-services" @@ -20,6 +20,8 @@ let "${d}/etc/dbus-1/session.d" ])); + daemonArgs = "--address=systemd: --nofork --nopidfile --systemd-activation"; + configDir = pkgs.stdenv.mkDerivation { name = "dbus-conf"; @@ -29,6 +31,14 @@ let buildCommand = '' mkdir -p $out + cp ${pkgs.dbus.out}/share/dbus-1/{system,session}.conf $out + + # avoid circular includes + sed -ri 's@(/etc/dbus-1/(system|session)\.conf)@@g' $out/{system,session}.conf + + # include by full path + sed -ri "s@/etc/dbus-1/(system|session)-@$out/\1-@" $out/{system,session}.conf + sed '${./dbus-system-local.conf.in}' \ -e 's,@servicehelper@,${config.security.wrapperDir}/dbus-daemon-launch-helper,g' \ -e 's,@extra@,${systemExtraxml},' \ @@ -75,11 +85,16 @@ in ''; }; + socketActivated = mkOption { + type = types.bool; + default = false; + description = '' + Make the user instance socket activated. + ''; + }; }; - }; - ###### implementation config = mkIf cfg.enable { @@ -117,13 +132,29 @@ in config.system.path ]; - # Don't restart dbus-daemon. Bad things tend to happen if we do. - systemd.services.dbus.reloadIfChanged = true; + systemd.services.dbus = { + # Don't restart dbus-daemon. Bad things tend to happen if we do. + reloadIfChanged = true; + restartTriggers = [ configDir ]; + serviceConfig.ExecStart = [ + "" + "${lib.getBin pkgs.dbus}/bin/dbus-daemon --config-file=${configDir}/system.conf ${daemonArgs}" + ]; + }; - systemd.services.dbus.restartTriggers = [ configDir ]; + systemd.user = { + services.dbus = { + # Don't restart dbus-daemon. Bad things tend to happen if we do. + reloadIfChanged = true; + restartTriggers = [ configDir ]; + serviceConfig.ExecStart = [ + "" + "${lib.getBin pkgs.dbus}/bin/dbus-daemon --config-file=${configDir}/session.conf ${daemonArgs}" + ]; + }; + sockets.dbus.wantedBy = mkIf cfg.socketActivated [ "sockets.target" ]; + }; environment.pathsToLink = [ "/etc/dbus-1" "/share/dbus-1" ]; - }; - } diff --git a/nixos/modules/services/x11/display-managers/default.nix b/nixos/modules/services/x11/display-managers/default.nix index 75d80609f73f..ce82af4ca68c 100644 --- a/nixos/modules/services/x11/display-managers/default.nix +++ b/nixos/modules/services/x11/display-managers/default.nix @@ -134,13 +134,8 @@ let (*) echo "$0: Desktop manager '$desktopManager' not found.";; esac - # FIXME: gdbus should not be in glib.dev! - ${optionalString (cfg.startDbusSession && cfg.updateDbusEnvironment) '' - ${pkgs.glib.dev}/bin/gdbus call --session \ - --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus \ - --method org.freedesktop.DBus.UpdateActivationEnvironment \ - "{$(env | ${pkgs.gnused}/bin/sed "s/'/\\\\'/g; s/\([^=]*\)=\(.*\)/'\1':'\2'/" \ - | ${pkgs.coreutils}/bin/paste -sd,)}" + ${optionalString cfg.updateDbusEnvironment '' + ${lib.getBin pkgs.dbus}/bin/dbus-update-activation-environment --systemd --all ''} test -n "$waitPID" && wait "$waitPID" diff --git a/pkgs/development/libraries/dbus/default.nix b/pkgs/development/libraries/dbus/default.nix index 789aae18aaa3..531188d7419c 100644 --- a/pkgs/development/libraries/dbus/default.nix +++ b/pkgs/development/libraries/dbus/default.nix @@ -44,7 +44,11 @@ self = stdenv.mkDerivation { "--localstatedir=/var" "--sysconfdir=/etc" "--with-session-socket-dir=/tmp" + "--with-system-pid-file=/run/dbus/pid" + "--with-system-socket=/run/dbus/system_bus_socket" "--with-systemdsystemunitdir=$(out)/etc/systemd/system" + "--with-systemduserunitdir=$(out)/etc/systemd/user" + "--enable-user-session" # this package installs nothing into those dirs and they create a dependency "--datadir=/run/current-system/sw/share" "--libexecdir=$(out)/libexec" # we don't need dbus-daemon-launch-helper @@ -81,4 +85,3 @@ self = stdenv.mkDerivation { }; }; in self -