nix-on-droid/pkgs/proot-termux/default.nix
2022-10-04 00:43:13 +02:00

41 lines
1.2 KiB
Nix

# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE.
{ stdenv
, fetchFromGitHub
, talloc
, static ? true
, outputBinaryName ? "proot-static"
}:
stdenv.mkDerivation {
pname = "proot-termux";
version = "unstable-2022-05-03";
src = fetchFromGitHub {
repo = "proot";
owner = "termux";
rev = "5c462a6ecfddd629b1439f38fbb61216d6fcb359";
sha256 = "sha256-XS4js80NsAN2C4jMuISSqMm/DwYpH/stbABaxzoqZcE=";
};
# ashmem.h is rather small, our needs are even smaller, so just define these:
preConfigure = ''
mkdir -p fake-ashmem/linux; cat > fake-ashmem/linux/ashmem.h << EOF
#include <linux/limits.h>
#include <linux/ioctl.h>
#define __ASHMEMIOC 0x77
#define ASHMEM_NAME_LEN 256
#define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN])
#define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t)
EOF
'';
buildInputs = [ talloc ];
patches = [ ./detranslate-empty.patch ];
makeFlags = [ "-Csrc" "V=1" ];
CFLAGS = [ "-O3" "-I../fake-ashmem" ] ++
(if static then [ "-static" ] else [ ]);
LDFLAGS = if static then [ "-static" ] else [ ];
preInstall = "${stdenv.cc.targetPrefix}strip src/proot";
installPhase = "install -D -m 0755 src/proot $out/bin/${outputBinaryName}";
}