15 , gobject-introspection
23 , useSystemd ? lib.meta.availableOn stdenv.hostPlatform systemdMinimal
27 , withIntrospection ? lib.meta.availableOn stdenv.hostPlatform gobject-introspection && stdenv.hostPlatform.emulatorAvailable buildPackages
28 # A few tests currently fail on musl (polkitunixusertest, polkitunixgrouptest, polkitidentitytest segfault).
29 # Not yet investigated; it may be due to the "Make netgroup support optional"
30 # patch not updating the tests correctly yet, or doing something wrong,
31 # or being unrelated to that.
32 , doCheck ? (stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isMusl)
36 system = "/run/current-system/sw";
37 setuid = "/run/wrappers/bin";
39 stdenv.mkDerivation rec {
43 outputs = [ "bin" "dev" "out" ]; # small man pages in $bin
45 # Tarballs do not contain subprojects.
46 src = fetchFromGitHub {
50 hash = "sha256-Vc9G2xK6U1cX+xW2BnKp3oS/ACbSXS/lztbFP5oJOlM=";
54 # Allow changing base for paths in pkg-config file as before.
55 # https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/100
56 ./0001-build-Use-datarootdir-in-Meson-generated-pkg-config-.patch
60 # FIXME: remove in the next release
61 # https://github.com/NixOS/nixpkgs/issues/18012
63 url = "https://github.com/polkit-org/polkit/commit/f93c7466039ea3403e0576928aeb620b806d0cce.patch";
64 sha256 = "sha256-cF0nNovYmyr+XixpBgQFF0A+oJeSPGZgTkgDQkQuof8=";
84 ] ++ lib.optionals withIntrospection [
87 ] ++ lib.optionals (withIntrospection && !stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
96 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
97 # On Linux, fall back to elogind when systemd support is off.
98 (if useSystemd then systemdMinimal else elogind)
101 propagatedBuildInputs = [
102 glib # in .pc Requires
105 nativeCheckInputs = [
107 (python3.pythonOnBuildForHost.withPackages (pp: with pp; [
109 (python-dbusmock.overridePythonAttrs (attrs: {
110 # Avoid dependency cycle.
117 PKG_CONFIG_SYSTEMD_SYSTEMDSYSTEMUNITDIR = "${placeholder "out"}/lib/systemd/system";
118 PKG_CONFIG_SYSTEMD_SYSUSERS_DIR = "${placeholder "out"}/lib/sysusers.d";
120 # HACK: We want to install policy files files to $out/share but polkit
121 # should read them from /run/current-system/sw/share on a NixOS system.
122 # Similarly for config files in /etc.
123 # With autotools, it was possible to override Make variables
124 # at install time but Meson does not support this
125 # so we need to convince it to install all files to a temporary
126 # location using DESTDIR and then move it to proper one in postInstall.
128 } // lib.optionalAttrs stdenv.cc.isGNU {
129 NIX_CFLAGS_COMPILE = "-Wno-error=implicit-function-declaration";
133 "--datadir=${system}/share"
135 "-Dpolkitd_user=polkituser" #TODO? <nixos> config.ids.uids.polkituser
136 "-Dos_type=redhat" # only affects PAM includes
137 "-Dintrospection=${lib.boolToString withIntrospection}"
138 "-Dtests=${lib.boolToString doCheck}"
139 "-Dgtk_doc=${lib.boolToString withIntrospection}"
141 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
142 "-Dsession_tracking=${if useSystemd then "libsystemd-login" else "libelogind"}"
149 patchShebangs test/polkitbackend/polkitbackendjsauthoritytest-wrapper.py
151 # ‘libpolkit-agent-1.so’ should call the setuid wrapper on
152 # NixOS. Hard-coding the path is kinda ugly. Maybe we can just
153 # call through $PATH, but that might have security implications.
154 substituteInPlace src/polkitagent/polkitagentsession.c \
155 --replace 'PACKAGE_PREFIX "/lib/polkit-1/' '"${setuid}/'
156 substituteInPlace test/data/etc/polkit-1/rules.d/10-testing.rules \
157 --replace /bin/true ${coreutils}/bin/true \
158 --replace /bin/false ${coreutils}/bin/false
161 postConfigure = lib.optionalString doCheck ''
163 chmod +x subprojects/mocklibc-1.0/bin/mocklibc
164 patchShebangs subprojects/mocklibc-1.0/bin/mocklibc
170 # tests need access to the system bus
171 dbus-run-session --config-file=${./system_bus.conf} -- sh -c 'DBUS_SYSTEM_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS meson test --print-errorlogs'
177 # Move stuff from DESTDIR to proper location.
178 # We need to be careful with the ordering to merge without conflicts.
179 for o in $(getAllOutputNames); do
180 mv "$DESTDIR/''${!o}" "''${!o}"
182 mv "$DESTDIR/etc" "$out"
183 mv "$DESTDIR${system}/share"/* "$out/share"
184 # Ensure we did not forget to install anything.
185 rmdir --parents --ignore-fail-on-non-empty "$DESTDIR${builtins.storeDir}" "$DESTDIR${system}/share"
190 homepage = "https://github.com/polkit-org/polkit";
191 description = "Toolkit for defining and handling the policy that allows unprivileged processes to speak to privileged processes";
192 license = licenses.lgpl2Plus;
193 platforms = platforms.linux;
195 # mandatory libpolkit-gobject shared library
196 lib.systems.inspect.platformPatterns.isStatic
198 maintainers = teams.freedesktop.members ++ (with maintainers; [ ]);