17 , gobject-introspection
24 , useSystemd ? stdenv.isLinux
27 # A few tests currently fail on musl (polkitunixusertest, polkitunixgrouptest, polkitidentitytest segfault).
28 # Not yet investigated; it may be due to the "Make netgroup support optional"
29 # patch not updating the tests correctly yet, or doing something wrong,
30 # or being unrelated to that.
31 , doCheck ? (stdenv.isLinux && !stdenv.hostPlatform.isMusl)
35 system = "/run/current-system/sw";
36 setuid = "/run/wrappers/bin";
38 stdenv.mkDerivation rec {
42 outputs = [ "bin" "dev" "out" ]; # small man pages in $bin
44 # Tarballs do not contain subprojects.
45 src = fetchFromGitLab {
46 domain = "gitlab.freedesktop.org";
50 sha256 = "Lj7KSGILc6CBsNqPO0G0PNt6ClikbRG45E8FZbb46yY=";
54 # Allow changing base for paths in pkg-config file as before.
55 # https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/100
57 url = "https://gitlab.freedesktop.org/polkit/polkit/-/commit/7ba07551dfcd4ef9a87b8f0d9eb8b91fabcb41b3.patch";
58 sha256 = "ebbLILncq1hAZTBMsLm+vDGw6j0iQ0crGyhzyLZQgKA=";
60 # Make netgroup support optional (musl does not have it)
61 # Upstream MR: https://gitlab.freedesktop.org/polkit/polkit/merge_requests/10
62 # NOTE: Remove after the next release
64 name = "make-innetgr-optional.patch";
65 url = "https://gitlab.freedesktop.org/polkit/polkit/-/commit/b57deee8178190a7ecc75290fa13cf7daabc2c66.patch";
66 sha256 = "8te6gatT9Fp+fIT05fQBym5mEwHeHfaUNUNEMfSbtLc=";
84 (python3.pythonForBuild.withPackages (pp: with pp; [
86 (python-dbusmock.overridePythonAttrs (attrs: {
87 # Avoid dependency cycle.
96 ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
101 gobject-introspection
106 ] ++ lib.optionals stdenv.isLinux [
107 # On Linux, fall back to elogind when systemd support is off.
108 (if useSystemd then systemdMinimal else elogind)
111 propagatedBuildInputs = [
112 glib # in .pc Requires
120 "--datadir=${system}/share"
122 "-Dsystemdsystemunitdir=${placeholder "out"}/etc/systemd/system"
123 "-Dpolkitd_user=polkituser" #TODO? <nixos> config.ids.uids.polkituser
124 "-Dos_type=redhat" # only affects PAM includes
125 "-Dtests=${lib.boolToString doCheck}"
127 ] ++ lib.optionals stdenv.isLinux [
128 "-Dsession_tracking=${if useSystemd then "libsystemd-login" else "libelogind"}"
131 # HACK: We want to install policy files files to $out/share but polkit
132 # should read them from /run/current-system/sw/share on a NixOS system.
133 # Similarly for config files in /etc.
134 # With autotools, it was possible to override Make variables
135 # at install time but Meson does not support this
136 # so we need to convince it to install all files to a temporary
137 # location using DESTDIR and then move it to proper one in postInstall.
138 DESTDIR = "${placeholder "out"}/dest";
143 patchShebangs test/polkitbackend/polkitbackendjsauthoritytest-wrapper.py
145 # ‘libpolkit-agent-1.so’ should call the setuid wrapper on
146 # NixOS. Hard-coding the path is kinda ugly. Maybe we can just
147 # call through $PATH, but that might have security implications.
148 substituteInPlace src/polkitagent/polkitagentsession.c \
149 --replace 'PACKAGE_PREFIX "/lib/polkit-1/' '"${setuid}/'
150 substituteInPlace test/data/etc/polkit-1/rules.d/10-testing.rules \
151 --replace /bin/true ${coreutils}/bin/true \
152 --replace /bin/false ${coreutils}/bin/false
155 postConfigure = lib.optionalString (!stdenv.hostPlatform.isMusl) ''
157 chmod +x subprojects/mocklibc-1.0/bin/mocklibc
158 patchShebangs subprojects/mocklibc-1.0/bin/mocklibc
164 # tests need access to the system bus
165 dbus-run-session --config-file=${./system_bus.conf} -- sh -c 'DBUS_SYSTEM_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS meson test --print-errorlogs'
171 # Move stuff from DESTDIR to proper location.
172 # We use rsync to merge the directories.
173 rsync --archive "${DESTDIR}/etc" "$out"
174 rm --recursive "${DESTDIR}/etc"
175 rsync --archive "${DESTDIR}${system}"/* "$out"
176 rm --recursive "${DESTDIR}${system}"/*
177 rmdir --parents --ignore-fail-on-non-empty "${DESTDIR}${system}"
178 for o in $outputs; do
179 rsync --archive "${DESTDIR}/''${!o}" "$(dirname "''${!o}")"
180 rm --recursive "${DESTDIR}/''${!o}"
182 # Ensure the DESTDIR is removed.
183 destdirContainer="$(dirname "${DESTDIR}")"
184 pushd "$destdirContainer"; rmdir --parents "''${DESTDIR##$destdirContainer/}${builtins.storeDir}"; popd
188 homepage = "http://www.freedesktop.org/wiki/Software/polkit";
189 description = "A toolkit for defining and handling the policy that allows unprivileged processes to speak to privileged processes";
190 license = licenses.lgpl2Plus;
191 platforms = platforms.linux;
192 maintainers = teams.freedesktop.members ++ (with maintainers; [ ]);