2021-01-25 08:26:54 +00:00
|
|
|
{ lib
|
2019-10-27 03:18:26 +00:00
|
|
|
, buildBazelPackage
|
|
|
|
, fetchFromGitHub
|
2021-06-06 22:29:00 +01:00
|
|
|
, callPackage
|
|
|
|
, bash
|
2019-10-27 03:18:26 +00:00
|
|
|
, cacert
|
|
|
|
, git
|
|
|
|
, glibcLocales
|
|
|
|
, go
|
2021-03-14 16:05:16 +00:00
|
|
|
, iproute2
|
2019-10-27 03:18:26 +00:00
|
|
|
, iptables
|
|
|
|
, makeWrapper
|
|
|
|
, procps
|
2021-06-06 22:29:00 +01:00
|
|
|
, protobuf
|
2019-10-27 03:18:26 +00:00
|
|
|
, python3
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
preBuild = ''
|
|
|
|
patchShebangs .
|
|
|
|
|
2021-06-06 22:29:00 +01:00
|
|
|
substituteInPlace tools/defs.bzl \
|
|
|
|
--replace "#!/bin/bash" "#!${bash}/bin/bash"
|
|
|
|
|
2019-10-27 03:18:26 +00:00
|
|
|
# Tell rules_go to use the Go binary found in the PATH
|
|
|
|
sed -E -i \
|
2021-06-06 22:29:00 +01:00
|
|
|
-e 's|go_version\s*=\s*"[^"]+"|go_version = "host"|g' \
|
2019-10-27 03:18:26 +00:00
|
|
|
WORKSPACE
|
|
|
|
|
|
|
|
# The gazelle Go tooling needs CA certs
|
|
|
|
export SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt"
|
|
|
|
|
|
|
|
# If we don't reset our GOPATH, the rules_go stdlib builder tries to
|
|
|
|
# install something into it. Ideally that wouldn't happen, but for now we
|
|
|
|
# can also get around it by unsetting GOPATH entirely, since rules_go
|
|
|
|
# doesn't need it.
|
|
|
|
export GOPATH=
|
|
|
|
'';
|
|
|
|
|
2021-06-06 22:29:00 +01:00
|
|
|
# Patch the protoc alias so that it always builds from source.
|
|
|
|
rulesProto = fetchFromGitHub {
|
|
|
|
owner = "bazelbuild";
|
|
|
|
repo = "rules_proto";
|
|
|
|
rev = "f7a30f6f80006b591fa7c437fe5a951eb10bcbcf";
|
|
|
|
sha256 = "10bcw0ir0skk7h33lmqm38n9w4nfs24mwajnngkbs6jb5wsvkqv8";
|
|
|
|
extraPostFetch = ''
|
|
|
|
sed -i 's|name = "protoc"|name = "_protoc_original"|' $out/proto/private/BUILD.release
|
|
|
|
cat <<EOF >>$out/proto/private/BUILD.release
|
|
|
|
alias(name = "protoc", actual = "@com_github_protocolbuffers_protobuf//:protoc", visibility = ["//visibility:public"])
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-10-27 03:18:26 +00:00
|
|
|
in buildBazelPackage rec {
|
|
|
|
name = "gvisor-${version}";
|
2021-06-06 22:29:00 +01:00
|
|
|
version = "20210518.0";
|
2019-10-27 03:18:26 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "google";
|
|
|
|
repo = "gvisor";
|
2021-06-06 22:29:00 +01:00
|
|
|
rev = "release-${version}";
|
|
|
|
sha256 = "15a6mlclnyfc9mx3bjksnnf4vla0xh0rv9kxdp34la4gw3c4hksn";
|
2019-10-27 03:18:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [ git glibcLocales go makeWrapper python3 ];
|
|
|
|
|
|
|
|
bazelTarget = "//runsc:runsc";
|
2021-06-06 22:29:00 +01:00
|
|
|
bazelFlags = [
|
|
|
|
"--override_repository=rules_proto=${rulesProto}"
|
|
|
|
];
|
2019-10-27 03:18:26 +00:00
|
|
|
|
|
|
|
# gvisor uses the Starlark implementation of rules_cc, not the built-in one,
|
|
|
|
# so we shouldn't delete it from our dependencies.
|
|
|
|
removeRulesCC = false;
|
|
|
|
|
|
|
|
fetchAttrs = {
|
|
|
|
inherit preBuild;
|
|
|
|
|
|
|
|
preInstall = ''
|
|
|
|
# Remove the go_sdk (it's just a copy of the go derivation) and all
|
|
|
|
# references to it from the marker files. Bazel does not need to download
|
|
|
|
# this sdk because we have patched the WORKSPACE file to point to the one
|
|
|
|
# currently present in PATH. Without removing the go_sdk from the marker
|
|
|
|
# file, the hash of it will change anytime the Go derivation changes and
|
|
|
|
# that would lead to impurities in the marker files which would result in
|
|
|
|
# a different sha256 for the fetch phase.
|
|
|
|
rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker}
|
|
|
|
|
|
|
|
# Remove the gazelle tools, they contain go binaries that are built
|
|
|
|
# non-deterministically. As long as the gazelle version matches the tools
|
|
|
|
# should be equivalent.
|
|
|
|
rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker}
|
|
|
|
|
|
|
|
# Remove the gazelle repository cache
|
|
|
|
chmod -R +w $bazelOut/external/bazel_gazelle_go_repository_cache
|
|
|
|
rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,\@bazel_gazelle_go_repository_cache.marker}
|
|
|
|
|
|
|
|
# Remove log file(s)
|
|
|
|
rm -f "$bazelOut"/java.log "$bazelOut"/java.log.*
|
|
|
|
'';
|
|
|
|
|
2021-06-06 22:29:00 +01:00
|
|
|
sha256 = "13pahppm431m198v5bffrzq5iw8m79riplbfqp0afh384ln669hb";
|
2019-10-27 03:18:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
buildAttrs = {
|
|
|
|
inherit preBuild;
|
|
|
|
|
|
|
|
installPhase = ''
|
2021-06-06 22:29:00 +01:00
|
|
|
install -Dm755 bazel-out/*/bin/runsc/runsc_/runsc $out/bin/runsc
|
2019-10-27 03:18:26 +00:00
|
|
|
|
|
|
|
# Needed for the 'runsc do' subcomand
|
|
|
|
wrapProgram $out/bin/runsc \
|
2021-03-14 16:05:16 +00:00
|
|
|
--prefix PATH : ${lib.makeBinPath [ iproute2 iptables procps ]}
|
2019-10-27 03:18:26 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-01-11 07:54:33 +00:00
|
|
|
meta = with lib; {
|
2019-10-27 03:18:26 +00:00
|
|
|
description = "Container Runtime Sandbox";
|
2020-04-01 02:11:51 +01:00
|
|
|
homepage = "https://github.com/google/gvisor";
|
2019-10-27 03:18:26 +00:00
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ andrew-d ];
|
|
|
|
platforms = [ "x86_64-linux" ];
|
|
|
|
};
|
|
|
|
}
|