From 1774d83af6bda802ab4a14d0ab9126a72f776801 Mon Sep 17 00:00:00 2001 From: WORLDofPEACE Date: Fri, 12 Feb 2021 04:36:23 -0500 Subject: [PATCH 1/2] nixos/dbus: support dbus-broker --- .../services/networking/avahi-daemon.nix | 2 +- nixos/modules/services/networking/wicd.nix | 2 +- nixos/modules/services/system/dbus.nix | 161 ++++++++++++------ .../services/x11/display-managers/lightdm.nix | 2 +- nixos/modules/system/boot/systemd.nix | 2 +- 5 files changed, 116 insertions(+), 53 deletions(-) diff --git a/nixos/modules/services/networking/avahi-daemon.nix b/nixos/modules/services/networking/avahi-daemon.nix index 0b7d5575c11fc..ca037b63fefa1 100644 --- a/nixos/modules/services/networking/avahi-daemon.nix +++ b/nixos/modules/services/networking/avahi-daemon.nix @@ -278,7 +278,7 @@ in }; }; - services.dbus.enable = true; + services.dbus.enable = mkDefault true; services.dbus.packages = [ pkgs.avahi ]; networking.firewall.allowedUDPPorts = mkIf cfg.openFirewall [ 5353 ]; diff --git a/nixos/modules/services/networking/wicd.nix b/nixos/modules/services/networking/wicd.nix index aa10a50f876a7..85b2a2fece6d4 100644 --- a/nixos/modules/services/networking/wicd.nix +++ b/nixos/modules/services/networking/wicd.nix @@ -34,7 +34,7 @@ with lib; script = "${pkgs.wicd}/sbin/wicd -f"; }; - services.dbus.enable = true; + services.dbus.enable = mkDefault true; services.dbus.packages = [pkgs.wicd]; }; } diff --git a/nixos/modules/services/system/dbus.nix b/nixos/modules/services/system/dbus.nix index d4cacb85694b9..2fe0061816755 100644 --- a/nixos/modules/services/system/dbus.nix +++ b/nixos/modules/services/system/dbus.nix @@ -8,6 +8,8 @@ let cfg = config.services.dbus; + brokerCfg = config.services.dbus-broker; + homeDir = "/run/dbus"; configDir = pkgs.makeDBusConf { @@ -23,6 +25,17 @@ in options = { + services.dbus-broker.enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable dbus-broker, implementation of a message bus + as defined by the D-Bus specification. Its aim is to provide high + performance and reliability, while keeping compatibility to the D-Bus + reference implementation. You must disable services.dbus.enable to use this. + ''; + }; + services.dbus = { enable = mkOption { @@ -79,61 +92,111 @@ in ###### implementation - config = mkIf cfg.enable { - warnings = optional (cfg.socketActivated != null) ( - let - files = showFiles options.services.dbus.socketActivated.files; - in - "The option 'services.dbus.socketActivated' in ${files} no longer has" - + " any effect and can be safely removed: the user D-Bus session is" - + " now always socket activated." - ); - - environment.systemPackages = [ pkgs.dbus.daemon pkgs.dbus ]; - - environment.etc."dbus-1".source = configDir; - - users.users.messagebus = { - uid = config.ids.uids.messagebus; - description = "D-Bus system message bus daemon user"; - home = homeDir; - group = "messagebus"; - }; - - users.groups.messagebus.gid = config.ids.gids.messagebus; + config = mkMerge [ + # You still need the dbus reference implementation installed to use dbus-broker + (mkIf (cfg.enable || brokerCfg.enable) { + warnings = optional (cfg.socketActivated != null) ( + let + files = showFiles options.services.dbus.socketActivated.files; + in + "The option 'services.dbus.socketActivated' in ${files} no longer has" + + " any effect and can be safely removed: the user D-Bus session is" + + " now always socket activated." + ); + + assertions = [ + { assertion = brokerCfg.enable -> !cfg.enable; + message = '' + You cannot use services.dbus.enable with services.dbus-broker.enable. Please disable DBus. + ''; + } + ]; + + environment.etc."dbus-1".source = configDir; + + users.users.messagebus = { + uid = config.ids.uids.messagebus; + description = "D-Bus system message bus daemon user"; + home = homeDir; + group = "messagebus"; + }; - systemd.packages = [ pkgs.dbus.daemon ]; + users.groups.messagebus.gid = config.ids.gids.messagebus; - security.wrappers.dbus-daemon-launch-helper = { - source = "${pkgs.dbus.daemon}/libexec/dbus-daemon-launch-helper"; - owner = "root"; - group = "messagebus"; - setuid = true; - setgid = false; - permissions = "u+rx,g+rx,o-rx"; - }; + systemd.packages = [ + pkgs.dbus.daemon + ]; - services.dbus.packages = [ - pkgs.dbus.out - config.system.path - ]; + services.dbus.packages = [ + pkgs.dbus.out + config.system.path + ]; - systemd.services.dbus = { - # Don't restart dbus-daemon. Bad things tend to happen if we do. - reloadIfChanged = true; - restartTriggers = [ configDir ]; - environment = { LD_LIBRARY_PATH = config.system.nssModules.path; }; - }; - - systemd.user = { - services.dbus = { + systemd.services.dbus = { # Don't restart dbus-daemon. Bad things tend to happen if we do. reloadIfChanged = true; - restartTriggers = [ configDir ]; + restartTriggers = [ + configDir + ]; + environment = { + LD_LIBRARY_PATH = config.system.nssModules.path; + }; }; - sockets.dbus.wantedBy = [ "sockets.target" ]; - }; - environment.pathsToLink = [ "/etc/dbus-1" "/share/dbus-1" ]; - }; + systemd.user = { + services.dbus = { + # Don't restart dbus-daemon. Bad things tend to happen if we do. + reloadIfChanged = true; + restartTriggers = [ + configDir + ]; + }; + sockets.dbus.wantedBy = [ + "sockets.target" + ]; + }; + + environment.pathsToLink = [ + "/etc/dbus-1" + "/share/dbus-1" + ]; + }) + + (mkIf cfg.enable { + environment.systemPackages = [ + pkgs.dbus + pkgs.dbus.daemon + ]; + + security.wrappers.dbus-daemon-launch-helper = { + source = "${pkgs.dbus.daemon}/libexec/dbus-daemon-launch-helper"; + owner = "root"; + group = "messagebus"; + setuid = true; + setgid = false; + permissions = "u+rx,g+rx,o-rx"; + }; + }) + + (mkIf brokerCfg.enable { + environment.systemPackages = [ + pkgs.dbus-broker + ]; + + systemd.packages = [ + pkgs.dbus-broker + ]; + + # NixOS Systemd Module doesn't respect 'Install' + # https://github.com/NixOS/nixpkgs/issues/108643 + systemd.services.dbus-broker.aliases = [ + "dbus.service" + ]; + + systemd.user.services.dbus-broker.aliases = [ + "dbus.service" + ]; + }) + + ]; } diff --git a/nixos/modules/services/x11/display-managers/lightdm.nix b/nixos/modules/services/x11/display-managers/lightdm.nix index 2dafee9e36e3d..3021d43a799da 100644 --- a/nixos/modules/services/x11/display-managers/lightdm.nix +++ b/nixos/modules/services/x11/display-managers/lightdm.nix @@ -258,7 +258,7 @@ in environment.etc."lightdm/lightdm.conf".source = lightdmConf; environment.etc."lightdm/users.conf".source = usersConf; - services.dbus.enable = true; + services.dbus.enable = mkDefault true; services.dbus.packages = [ lightdm ]; # lightdm uses the accounts daemon to remember language/window-manager per user diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 6b672c7b2eb48..e4e58bdb94e80 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -1046,7 +1046,7 @@ in "systemd/system-shutdown" = { source = hooks "shutdown" cfg.shutdown; }; }); - services.dbus.enable = true; + services.dbus.enable = mkDefault true; users.users.systemd-network.uid = config.ids.uids.systemd-network; users.groups.systemd-network.gid = config.ids.gids.systemd-network; From 7d69145adbd339220ce39a0bd63544b9e57f23b4 Mon Sep 17 00:00:00 2001 From: WORLDofPEACE Date: Fri, 12 Feb 2021 04:37:03 -0500 Subject: [PATCH 2/2] dbus-broker: 22 -> 26 * add me as maintainer * add system-console-users * fix-paths.patch This I'm not 100% on. We make it so the systemd service isn't configured to have /run/current-system/sw/share in XDG_DATA_DIRS, and dbus-broker falls back to /usr/share. This makes it so nothing will get launched from /run/current-system/sw/share, and everything is limited to the configs (and how I believe this should be working). However, I have suspicion that maybe dbus-daemon knows about /run/current-system/sw/share. --- .../os-specific/linux/dbus-broker/default.nix | 55 ++++++++++++++----- .../linux/dbus-broker/fix-paths.patch | 16 ++++++ 2 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 pkgs/os-specific/linux/dbus-broker/fix-paths.patch diff --git a/pkgs/os-specific/linux/dbus-broker/default.nix b/pkgs/os-specific/linux/dbus-broker/default.nix index bffc90260c18a..647aaa7a60f2e 100644 --- a/pkgs/os-specific/linux/dbus-broker/default.nix +++ b/pkgs/os-specific/linux/dbus-broker/default.nix @@ -1,21 +1,50 @@ -{ lib, stdenv, fetchFromGitHub, docutils, meson, ninja, pkg-config -, dbus, linuxHeaders, systemd }: +{ lib +, stdenv +, fetchFromGitHub +, docutils +, meson +, ninja +, pkg-config +, dbus +, linuxHeaders +, systemd +}: stdenv.mkDerivation rec { pname = "dbus-broker"; - version = "22"; + version = "26"; src = fetchFromGitHub { - owner = "bus1"; - repo = "dbus-broker"; - rev = "v${version}"; - sha256 = "0vxr73afix5wjxy8g4cckwhl242rrlazm52673iwmdyfz5nskj2x"; + owner = "bus1"; + repo = "dbus-broker"; + rev = "v${version}"; + sha256 = "QjYjAvnLgMRL/4Jj1XBXl9z47zVHclOqZrAF2khC424="; fetchSubmodules = true; }; - nativeBuildInputs = [ docutils meson ninja pkg-config ]; + patches = [ + # Make launcher.c use nixos dbus configuration paths + # In the future the buildsystem should allow us to configure the **default** + # (as there is a --config-file cmdline) + ./fix-paths.patch + ]; - buildInputs = [ dbus linuxHeaders systemd ]; + mesonFlags = [ + "-D=system-console-users=gdm,sddm,lightdm" + ]; + + nativeBuildInputs = [ + docutils + meson + ninja + pkg-config + ]; + + buildInputs = [ + dbus + linuxHeaders + systemd + ]; PKG_CONFIG_SYSTEMD_SYSTEMDSYSTEMUNITDIR = "${placeholder "out"}/lib/systemd/system"; PKG_CONFIG_SYSTEMD_SYSTEMDUSERUNITDIR = "${placeholder "out"}/lib/systemd/user"; @@ -32,9 +61,9 @@ stdenv.mkDerivation rec { meta = with lib; { description = "Linux D-Bus Message Broker"; - homepage = "https://github.com/bus1/dbus-broker/wiki"; - license = licenses.asl20; - platforms = platforms.linux; - maintainers = with maintainers; [ peterhoeg ]; + homepage = "https://github.com/bus1/dbus-broker/wiki"; + license = licenses.asl20; + platforms = platforms.linux; + maintainers = with maintainers; [ peterhoeg worldofpeace ]; }; } diff --git a/pkgs/os-specific/linux/dbus-broker/fix-paths.patch b/pkgs/os-specific/linux/dbus-broker/fix-paths.patch new file mode 100644 index 0000000000000..7b155bcd965f3 --- /dev/null +++ b/pkgs/os-specific/linux/dbus-broker/fix-paths.patch @@ -0,0 +1,16 @@ +diff --git a/src/launch/launcher.c b/src/launch/launcher.c +index 5ba9b77..e338d92 100644 +--- a/src/launch/launcher.c ++++ b/src/launch/launcher.c +@@ -1007,9 +1007,9 @@ static int launcher_parse_config(Launcher *launcher, ConfigRoot **rootp, NSSCach + if (launcher->configfile) + configfile = launcher->configfile; + else if (launcher->user_scope) +- configfile = "/usr/share/dbus-1/session.conf"; ++ configfile = "/etc/dbus-1/session.conf"; + else +- configfile = "/usr/share/dbus-1/system.conf"; ++ configfile = "/etc/dbus-1/system.conf"; + + config_parser_init(&parser); +