From 125617826334fbf6be4f4f0e312f40b137bcb932 Mon Sep 17 00:00:00 2001 From: Philipp Bartsch Date: Sat, 1 Jul 2023 16:45:18 +0200 Subject: [PATCH] apparmor: fix python import issues With buildPythonApplication the PYTHONPATH is now populated properly, which should address the ModuleNotFoundError issue. I also moved some of the substitutions from postInstall to prePatch, so they don't conflict with the wrapped executables. Because upstream does not seem to hardcode binary paths in the utils anymore, some of the old substituteInPlace rules could be removed. Partial fix for nixpkgs#169056 --- pkgs/os-specific/linux/apparmor/default.nix | 31 +++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/pkgs/os-specific/linux/apparmor/default.nix b/pkgs/os-specific/linux/apparmor/default.nix index f579c00eb5c9..7c3503d16a65 100644 --- a/pkgs/os-specific/linux/apparmor/default.nix +++ b/pkgs/os-specific/linux/apparmor/default.nix @@ -128,9 +128,10 @@ let meta = apparmor-meta "library"; }; - apparmor-utils = stdenv.mkDerivation { + apparmor-utils = python.pkgs.buildPythonApplication { pname = "apparmor-utils"; version = apparmor-version; + format = "other"; src = apparmor-sources; @@ -146,14 +147,25 @@ let libapparmor.python ]; + propagatedBuildInputs = [ + libapparmor.python + + # Used by aa-notify + python.pkgs.notify2 + python.pkgs.psutil + ]; + prePatch = prePatchCommon + # Do not build vim file lib.optionalString stdenv.hostPlatform.isMusl '' sed -i ./utils/Makefile -e "/\/d" '' + '' - for file in utils/apparmor/easyprof.py utils/apparmor/aa.py utils/logprof.conf; do - substituteInPlace $file --replace "/sbin/apparmor_parser" "${apparmor-parser}/bin/apparmor_parser" - done + sed -i -E 's/^(DESTDIR|BINDIR|PYPREFIX)=.*//g' ./utils/Makefile + + sed -i utils/aa-unconfined -e "/my_env\['PATH'\]/d" + + substituteInPlace utils/aa-remove-unknown \ + --replace "/lib/apparmor/rc.apparmor.functions" "${apparmor-parser}/lib/apparmor/rc.apparmor.functions" ''; inherit patches; postPatch = "cd ./utils"; @@ -161,17 +173,6 @@ let installFlags = [ "DESTDIR=$(out)" "BINDIR=$(out)/bin" "VIM_INSTALL_PATH=$(out)/share" "PYPREFIX=" ]; postInstall = '' - sed -i $out/bin/aa-unconfined -e "/my_env\['PATH'\]/d" - for prog in aa-audit aa-autodep aa-cleanprof aa-complain aa-disable aa-enforce aa-genprof aa-logprof aa-mergeprof aa-unconfined ; do - wrapProgram $out/bin/$prog --prefix PYTHONPATH : "$out/lib/${python.sitePackages}:$PYTHONPATH" - done - - substituteInPlace $out/bin/aa-notify \ - --replace /usr/bin/notify-send ${libnotify}/bin/notify-send \ - --replace /usr/bin/perl "${perl}/bin/perl -I ${libapparmor}/${perl.libPrefix}" - - substituteInPlace $out/bin/aa-remove-unknown \ - --replace "/lib/apparmor/rc.apparmor.functions" "${apparmor-parser}/lib/apparmor/rc.apparmor.functions" wrapProgram $out/bin/aa-remove-unknown \ --prefix PATH : ${lib.makeBinPath [ gawk ]}