about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/system/minijail/default.nix
blob: fac934f7bb25b9fe61818f9f762df7d445c7877c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{ 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.mkDerivation rec {
  pname = "minijail";
  version = "16";

  src = fetchFromGitiles {
    url = "https://android.googlesource.com/platform/external/minijail";
    rev = "linux-v${version}";
    sha256 = "0pxazds3w12c30msq6bxs4a9cbds0dkj6n3ca0i1wqvgz864yrgs";
  };

  nativeBuildInputs =
    lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) qemu;
  buildInputs = [ libcap ];

  makeFlags = [ "LIBDIR=$(out)/lib" ];
  dumpConstantsFlags = lib.optional (stdenv.hostPlatform.libc == "glibc")
    "LDFLAGS=-L${glibc.static}/lib";

  postPatch = ''
    substituteInPlace common.mk --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

    mkdir -p $out/lib/pkgconfig $out/include/chromeos $out/bin \
        $out/share/minijail

    cp -v *.so $out/lib
    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
  '';

  meta = with lib; {
    homepage = "https://android.googlesource.com/platform/external/minijail/";
    description = "Sandboxing library and application using Linux namespaces and capabilities";
    license = licenses.bsd3;
    maintainers = with maintainers; [ pcarrier qyliss ];
    platforms = platforms.linux;
  };
}