From e6b079612981bbe3e294d72a8cdc530cb224f18a Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 30 Oct 2021 07:39:01 +0200 Subject: [PATCH 1/3] polkit: format the expression Use lib.optionals instead of lib.optional, move phases to the bottom, have one input per line. --- pkgs/development/libraries/polkit/default.nix | 113 ++++++++++++------ 1 file changed, 74 insertions(+), 39 deletions(-) diff --git a/pkgs/development/libraries/polkit/default.nix b/pkgs/development/libraries/polkit/default.nix index 83f59d2041c6..2f0195f053c5 100644 --- a/pkgs/development/libraries/polkit/default.nix +++ b/pkgs/development/libraries/polkit/default.nix @@ -1,7 +1,24 @@ -{ lib, stdenv, fetchurl, pkg-config, glib, expat, pam, perl, fetchpatch -, intltool, spidermonkey_78, gobject-introspection, libxslt, docbook_xsl, dbus -, docbook_xml_dtd_412, gtk-doc, coreutils -, useSystemd ? stdenv.isLinux, systemd, elogind +{ lib +, stdenv +, fetchurl +, pkg-config +, glib +, expat +, pam +, perl +, fetchpatch +, intltool +, spidermonkey_78 +, gobject-introspection +, libxslt +, docbook-xsl-nons +, dbus +, docbook_xml_dtd_412 +, gtk-doc +, coreutils +, useSystemd ? stdenv.isLinux +, systemd +, elogind # needed until gobject-introspection does cross-compile (https://github.com/NixOS/nixpkgs/pull/88222) , withIntrospection ? (stdenv.buildPlatform == stdenv.hostPlatform) # A few tests currently fail on musl (polkitunixusertest, polkitunixgrouptest, polkitidentitytest segfault). @@ -12,16 +29,15 @@ }: let - system = "/run/current-system/sw"; setuid = "/run/wrappers/bin"; - in - stdenv.mkDerivation rec { pname = "polkit"; version = "0.119"; + outputs = [ "bin" "dev" "out" ]; # small man pages in $bin + src = fetchurl { url = "https://www.freedesktop.org/software/${pname}/releases/${pname}-${version}.tar.gz"; sha256 = "0p0zzmr0kh3mpmqya4q27y4h9b920zp5ya0i8909ahp9hvdrymy8"; @@ -38,25 +54,65 @@ stdenv.mkDerivation rec { }) ]; - postPatch = lib.optionalString stdenv.isDarwin '' - sed -i -e "s/-Wl,--as-needed//" configure.ac - ''; + nativeBuildInputs = [ + glib + gtk-doc + pkg-config + intltool + perl - outputs = [ "bin" "dev" "out" ]; # small man pages in $bin + # man pages + libxslt + docbook-xsl-nons + docbook_xml_dtd_412 + ]; - nativeBuildInputs = - [ glib gtk-doc pkg-config intltool perl ] - ++ [ libxslt docbook_xsl docbook_xml_dtd_412 ]; # man pages - buildInputs = - [ expat pam spidermonkey_78 ] + buildInputs = [ + expat + pam + spidermonkey_78 + ] ++ lib.optionals stdenv.isLinux [ # On Linux, fall back to elogind when systemd support is off. - ++ lib.optional stdenv.isLinux (if useSystemd then systemd else elogind) - ++ lib.optional withIntrospection gobject-introspection; + (if useSystemd then systemd else elogind) + ] ++ lib.optionals withIntrospection [ + gobject-introspection + ]; propagatedBuildInputs = [ glib # in .pc Requires ]; + checkInputs = [ + dbus + ]; + + configureFlags = [ + "--datadir=${system}/share" + "--sysconfdir=/etc" + "--with-systemdsystemunitdir=${placeholder "out"}/etc/systemd/system" + "--with-polkitd-user=polkituser" #TODO? config.ids.uids.polkituser + "--with-os-type=NixOS" # not recognized but prevents impurities on non-NixOS + (if withIntrospection then "--enable-introspection" else "--disable-introspection") + ] ++ lib.optionals (!doCheck) [ + "--disable-test" + ]; + + makeFlags = [ + "INTROSPECTION_GIRDIR=${placeholder "out"}/share/gir-1.0" + "INTROSPECTION_TYPELIBDIR=${placeholder "out"}/lib/girepository-1.0" + ]; + + installFlags = [ + "datadir=${placeholder "out"}/share" + "sysconfdir=${placeholder "out"}/etc" + ]; + + inherit doCheck; + + postPatch = lib.optionalString stdenv.isDarwin '' + sed -i -e "s/-Wl,--as-needed//" configure.ac + ''; + preConfigure = '' chmod +x test/mocklibc/bin/mocklibc{,-test}.in patchShebangs . @@ -74,27 +130,6 @@ stdenv.mkDerivation rec { sed '/libsystemd autoconfigured/s/.*/:/' -i configure ''; - configureFlags = [ - "--datadir=${system}/share" - "--sysconfdir=/etc" - "--with-systemdsystemunitdir=${placeholder "out"}/etc/systemd/system" - "--with-polkitd-user=polkituser" #TODO? config.ids.uids.polkituser - "--with-os-type=NixOS" # not recognized but prevents impurities on non-NixOS - (if withIntrospection then "--enable-introspection" else "--disable-introspection") - ] ++ lib.optional (!doCheck) "--disable-test"; - - makeFlags = [ - "INTROSPECTION_GIRDIR=${placeholder "out"}/share/gir-1.0" - "INTROSPECTION_TYPELIBDIR=${placeholder "out"}/lib/girepository-1.0" - ]; - - installFlags = [ - "datadir=${placeholder "out"}/share" - "sysconfdir=${placeholder "out"}/etc" - ]; - - inherit doCheck; - checkInputs = [ dbus ]; checkPhase = '' runHook preCheck From 54417ca86353be6292c4198957eb0c467493211b Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 30 Oct 2021 07:45:28 +0200 Subject: [PATCH 2/3] =?UTF-8?q?polkit:=200.119=20=E2=86=92=200.120?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://lists.freedesktop.org/archives/polkit-devel/2021-October/000608.html --- pkgs/development/libraries/polkit/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/development/libraries/polkit/default.nix b/pkgs/development/libraries/polkit/default.nix index 2f0195f053c5..a0a612257be2 100644 --- a/pkgs/development/libraries/polkit/default.nix +++ b/pkgs/development/libraries/polkit/default.nix @@ -7,7 +7,7 @@ , pam , perl , fetchpatch -, intltool +, gettext , spidermonkey_78 , gobject-introspection , libxslt @@ -34,13 +34,13 @@ let in stdenv.mkDerivation rec { pname = "polkit"; - version = "0.119"; + version = "0.120"; outputs = [ "bin" "dev" "out" ]; # small man pages in $bin src = fetchurl { url = "https://www.freedesktop.org/software/${pname}/releases/${pname}-${version}.tar.gz"; - sha256 = "0p0zzmr0kh3mpmqya4q27y4h9b920zp5ya0i8909ahp9hvdrymy8"; + sha256 = "7npZmoUxF78nNUhyVxn6kvq9LxNpFcekkGzumFZ67gM="; }; patches = [ @@ -58,7 +58,7 @@ stdenv.mkDerivation rec { glib gtk-doc pkg-config - intltool + gettext perl # man pages From 527b98a125d381a1f03c2fa8393f80205c6dd052 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 30 Oct 2021 13:28:44 +0200 Subject: [PATCH 3/3] polkit: port to Meson Autotools build will be removed in the next release. Examples are no longer installed. Musl patch does not work. --- pkgs/development/libraries/polkit/default.nix | 101 ++++++++++++------ 1 file changed, 66 insertions(+), 35 deletions(-) diff --git a/pkgs/development/libraries/polkit/default.nix b/pkgs/development/libraries/polkit/default.nix index a0a612257be2..b2d1b35f05e1 100644 --- a/pkgs/development/libraries/polkit/default.nix +++ b/pkgs/development/libraries/polkit/default.nix @@ -1,11 +1,15 @@ { lib , stdenv -, fetchurl +, fetchFromGitLab , pkg-config , glib , expat , pam +, meson +, ninja , perl +, rsync +, python3 , fetchpatch , gettext , spidermonkey_78 @@ -38,12 +42,16 @@ stdenv.mkDerivation rec { outputs = [ "bin" "dev" "out" ]; # small man pages in $bin - src = fetchurl { - url = "https://www.freedesktop.org/software/${pname}/releases/${pname}-${version}.tar.gz"; - sha256 = "7npZmoUxF78nNUhyVxn6kvq9LxNpFcekkGzumFZ67gM="; + # Tarballs do not contain subprojects. + src = fetchFromGitLab { + domain = "gitlab.freedesktop.org"; + owner = "polkit"; + repo = "polkit"; + rev = version; + sha256 = "oEaRf1g13zKMD+cP1iwIA6jaCDwvNfGy2i8xY8vuVSo="; }; - patches = [ + patches = lib.optionals stdenv.hostPlatform.isMusl [ # Make netgroup support optional (musl does not have it) # Upstream MR: https://gitlab.freedesktop.org/polkit/polkit/merge_requests/10 # We use the version of the patch that Alpine uses successfully. @@ -59,7 +67,17 @@ stdenv.mkDerivation rec { gtk-doc pkg-config gettext + meson + ninja perl + rsync + (python3.withPackages (pp: with pp; [ + dbus-python + (python-dbusmock.overridePythonAttrs (attrs: { + # Avoid dependency cycle. + doCheck = false; + })) + ])) # man pages libxslt @@ -86,36 +104,33 @@ stdenv.mkDerivation rec { dbus ]; - configureFlags = [ + mesonFlags = [ "--datadir=${system}/share" "--sysconfdir=/etc" - "--with-systemdsystemunitdir=${placeholder "out"}/etc/systemd/system" - "--with-polkitd-user=polkituser" #TODO? config.ids.uids.polkituser - "--with-os-type=NixOS" # not recognized but prevents impurities on non-NixOS - (if withIntrospection then "--enable-introspection" else "--disable-introspection") - ] ++ lib.optionals (!doCheck) [ - "--disable-test" + "-Dsystemdsystemunitdir=${placeholder "out"}/etc/systemd/system" + "-Dpolkitd_user=polkituser" #TODO? config.ids.uids.polkituser + "-Dos_type=redhat" # only affects PAM includes + "-Dintrospection=${lib.boolToString withIntrospection}" + "-Dtests=${lib.boolToString doCheck}" + "-Dgtk_doc=${lib.boolToString true}" + "-Dman=true" + ] ++ lib.optionals stdenv.isLinux [ + "-Dsession_tracking=${if useSystemd then "libsystemd-login" else "libelogind"}" ]; - makeFlags = [ - "INTROSPECTION_GIRDIR=${placeholder "out"}/share/gir-1.0" - "INTROSPECTION_TYPELIBDIR=${placeholder "out"}/lib/girepository-1.0" - ]; - - installFlags = [ - "datadir=${placeholder "out"}/share" - "sysconfdir=${placeholder "out"}/etc" - ]; + # HACK: We want to install policy files files to $out/share but polkit + # should read them from /run/current-system/sw/share on a NixOS system. + # Similarly for config files in /etc. + # With autotools, it was possible to override Make variables + # at install time but Meson does not support this + # so we need to convince it to install all files to a temporary + # location using DESTDIR and then move it to proper one in postInstall. + DESTDIR = "${placeholder "out"}/dest"; inherit doCheck; - postPatch = lib.optionalString stdenv.isDarwin '' - sed -i -e "s/-Wl,--as-needed//" configure.ac - ''; - - preConfigure = '' - chmod +x test/mocklibc/bin/mocklibc{,-test}.in - patchShebangs . + postPatch = '' + patchShebangs test/polkitbackend/polkitbackendjsauthoritytest-wrapper.py # ‘libpolkit-agent-1.so’ should call the setuid wrapper on # NixOS. Hard-coding the path is kinda ugly. Maybe we can just @@ -125,24 +140,40 @@ stdenv.mkDerivation rec { substituteInPlace test/data/etc/polkit-1/rules.d/10-testing.rules \ --replace /bin/true ${coreutils}/bin/true \ --replace /bin/false ${coreutils}/bin/false + ''; - '' + lib.optionalString useSystemd /* bogus chroot detection */ '' - sed '/libsystemd autoconfigured/s/.*/:/' -i configure + postConfigure = '' + # Unpacked by meson + chmod +x subprojects/mocklibc-1.0/bin/mocklibc + patchShebangs subprojects/mocklibc-1.0/bin/mocklibc ''; checkPhase = '' runHook preCheck - # unfortunately this test needs python-dbusmock, but python-dbusmock needs polkit, - # leading to a circular dependency - substituteInPlace test/Makefile --replace polkitbackend "" - # tests need access to the system bus - dbus-run-session --config-file=${./system_bus.conf} -- sh -c 'DBUS_SYSTEM_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS make check' + dbus-run-session --config-file=${./system_bus.conf} -- sh -c 'DBUS_SYSTEM_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS meson test --print-errorlogs' runHook postCheck ''; + postInstall = '' + # Move stuff from DESTDIR to proper location. + # We use rsync to merge the directories. + rsync --archive "${DESTDIR}/etc" "$out" + rm --recursive "${DESTDIR}/etc" + rsync --archive "${DESTDIR}${system}"/* "$out" + rm --recursive "${DESTDIR}${system}"/* + rmdir --parents --ignore-fail-on-non-empty "${DESTDIR}${system}" + for o in $outputs; do + rsync --archive "${DESTDIR}/''${!o}" "$(dirname "''${!o}")" + rm --recursive "${DESTDIR}/''${!o}" + done + # Ensure the DESTDIR is removed. + destdirContainer="$(dirname "${DESTDIR}")" + pushd "$destdirContainer"; rmdir --parents "''${DESTDIR##$destdirContainer/}${builtins.storeDir}"; popd + ''; + meta = with lib; { homepage = "http://www.freedesktop.org/wiki/Software/polkit"; description = "A toolkit for defining and handling the policy that allows unprivileged processes to speak to privileged processes";