diff --git a/pkgs/tools/system/minijail/default.nix b/pkgs/tools/system/minijail/default.nix index bf2c6adf76a4..73f8cad580a5 100644 --- a/pkgs/tools/system/minijail/default.nix +++ b/pkgs/tools/system/minijail/default.nix @@ -1,13 +1,4 @@ -{ stdenv, lib, fetchFromGitiles, glibc, libcap, qemu }: - -let - dumpConstants = - if stdenv.buildPlatform == stdenv.hostPlatform then "./dump_constants" - else if stdenv.hostPlatform.isAarch32 then "qemu-arm dump_constants" - else if stdenv.hostPlatform.isAarch64 then "qemu-aarch64 dump_constants" - else if stdenv.hostPlatform.isx86_64 then "qemu-x86_64 dump_constants" - else throw "Unsupported host platform"; -in +{ stdenv, lib, fetchFromGitiles, libcap }: stdenv.mkDerivation rec { pname = "minijail"; @@ -19,24 +10,15 @@ stdenv.mkDerivation rec { sha256 = "sha256-OpwzISZ5iZNQvJAX7UJJ4gELEaVfcQgY9cqMM0YvBzc="; }; - nativeBuildInputs = - lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) qemu; buildInputs = [ libcap ]; makeFlags = [ "ECHO=echo" "LIBDIR=$(out)/lib" ]; - dumpConstantsFlags = lib.optional (stdenv.hostPlatform.libc == "glibc") - "LDFLAGS=-L${glibc.static}/lib"; postPatch = '' substituteInPlace Makefile --replace /bin/echo echo patchShebangs platform2_preinstall.sh ''; - postBuild = '' - make $makeFlags $buildFlags $dumpConstantsFlags dump_constants - ${dumpConstants} > constants.json - ''; - installPhase = '' ./platform2_preinstall.sh ${version} $out/include/chromeos @@ -47,7 +29,6 @@ stdenv.mkDerivation rec { cp -v *.pc $out/lib/pkgconfig cp -v libminijail.h scoped_minijail.h $out/include/chromeos cp -v minijail0 $out/bin - cp -v constants.json $out/share/minijail ''; enableParallelBuilding = true; diff --git a/pkgs/tools/system/minijail/tools.nix b/pkgs/tools/system/minijail/tools.nix index 875ea0dbff95..caaba84c0833 100644 --- a/pkgs/tools/system/minijail/tools.nix +++ b/pkgs/tools/system/minijail/tools.nix @@ -1,9 +1,36 @@ -{ buildPythonApplication, lib, minijail }: +{ lib, stdenv, buildPythonApplication, pkgsBuildTarget, python, minijail }: + +let + targetClang = pkgsBuildTarget.targetPackages.clangStdenv.cc; +in buildPythonApplication { pname = "minijail-tools"; inherit (minijail) version src; + postPatch = '' + substituteInPlace Makefile --replace /bin/echo echo + ''; + + postConfigure = '' + substituteInPlace tools/compile_seccomp_policy.py \ + --replace "'constants.json'" "'$out/share/constants.json'" + ''; + + preBuild = '' + make libconstants.gen.c libsyscalls.gen.c + ${targetClang}/bin/${targetClang.targetPrefix}cc -S -emit-llvm \ + libconstants.gen.c libsyscalls.gen.c + ${python.pythonForBuild.interpreter} tools/generate_constants_json.py \ + --output constants.json \ + libconstants.gen.ll libsyscalls.gen.ll + ''; + + postInstall = '' + mkdir -p $out/share + cp -v constants.json $out/share/constants.json + ''; + meta = with lib; { homepage = "https://android.googlesource.com/platform/external/minijail/+/refs/heads/master/tools/"; description = "A set of tools for minijail";