git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #73097 from andrew-d/andrew/gvisor-redux

gvisor: init at 2019-11-14

commit3140fa89c51233397f496f49014f6b23216667c2 authorFlorian Klink <flokli@flokli.de> dateThu 5 Dec 2019, 01:28 (7 years ago) parent39bce33c37902d
5 files changed+191
nixos/tests/all-tests.nix+1 nixos/tests/gvisor.nix+49 pkgs/applications/virtualization/gvisor/containerd-shim.nix+36 pkgs/applications/virtualization/gvisor/default.nix+101 pkgs/top-level/all-packages.nix+4
nixos/tests/all-tests.nix+1
@@ -103,6 +103,7 @@ in
103103 grafana = handleTest ./grafana.nix {};
104104 graphite = handleTest ./graphite.nix {};
105105 graylog = handleTest ./graylog.nix {};
106+ gvisor = handleTest ./gvisor.nix {};
106107 hadoop.hdfs = handleTestOn [ "x86_64-linux" ] ./hadoop/hdfs.nix {};
107108 hadoop.yarn = handleTestOn [ "x86_64-linux" ] ./hadoop/yarn.nix {};
108109 handbrake = handleTestOn ["x86_64-linux"] ./handbrake.nix {};
nixos/tests/gvisor.nixnew file+49
@@ -0,0 +1,49 @@
1+# This test runs a container through gvisor and checks if simple container starts
2+
3+import ./make-test-python.nix ({ pkgs, ...} : {
4+ name = "gvisor";
5+ meta = with pkgs.stdenv.lib.maintainers; {
6+ maintainers = [ andrew-d ];
7+ };
8+
9+ nodes = {
10+ gvisor =
11+ { pkgs, ... }:
12+ {
13+ virtualisation.docker = {
14+ enable = true;
15+ extraOptions = "--add-runtime runsc=${pkgs.gvisor}/bin/runsc";
16+ };
17+
18+ networking = {
19+ dhcpcd.enable = false;
20+ defaultGateway = "192.168.1.1";
21+ interfaces.eth1.ipv4.addresses = pkgs.lib.mkOverride 0 [
22+ { address = "192.168.1.2"; prefixLength = 24; }
23+ ];
24+ };
25+ };
26+ };
27+
28+ testScript = ''
29+ start_all()
30+
31+ gvisor.wait_for_unit("network.target")
32+ gvisor.wait_for_unit("sockets.target")
33+
34+ # Start by verifying that gvisor itself works
35+ output = gvisor.succeed(
36+ "${pkgs.gvisor}/bin/runsc -alsologtostderr do ${pkgs.coreutils}/bin/echo hello world"
37+ )
38+ assert output.strip() == "hello world"
39+
40+ # Also test the Docker runtime
41+ gvisor.succeed("tar cv --files-from /dev/null | docker import - scratchimg")
42+ gvisor.succeed(
43+ "docker run -d --name=sleeping --runtime=runsc -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
44+ )
45+ gvisor.succeed("docker ps | grep sleeping")
46+ gvisor.succeed("docker stop sleeping")
47+ '';
48+})
49+
pkgs/applications/virtualization/gvisor/containerd-shim.nixnew file+36
@@ -0,0 +1,36 @@
1+{ lib, fetchFromGitHub, buildGoModule, go-bindata }:
2+
3+buildGoModule rec {
4+ name = "gvisor-containerd-shim-${version}";
5+ version = "2019-10-09";
6+
7+ src = fetchFromGitHub {
8+ owner = "google";
9+ repo = "gvisor-containerd-shim";
10+ rev = "f299b553afdd8455a0057862004061ea12e660f5";
11+ sha256 = "077bhrmjrpcxv1z020yxhx2c4asn66j21gxlpa6hz0av3lfck9lm";
12+ };
13+
14+ modSha256 = "1jdhgbrn59ahnabwnig99i21f6kimmqx9f3dg10ffwfs3dx0gzlg";
15+
16+ buildPhase = ''
17+ make
18+ '';
19+
20+ doCheck = true;
21+ checkPhase = ''
22+ make test
23+ '';
24+
25+ installPhase = ''
26+ make install DESTDIR="$out"
27+ '';
28+
29+ meta = with lib; {
30+ description = "containerd shim for gVisor";
31+ homepage = https://github.com/google/gvisor-containerd-shim;
32+ license = licenses.asl20;
33+ maintainers = with maintainers; [ andrew-d ];
34+ platforms = [ "x86_64-linux" ];
35+ };
36+}
pkgs/applications/virtualization/gvisor/default.nixnew file+101
@@ -0,0 +1,101 @@
1+{ stdenv
2+, buildBazelPackage
3+, fetchFromGitHub
4+, cacert
5+, git
6+, glibcLocales
7+, go
8+, iproute
9+, iptables
10+, makeWrapper
11+, procps
12+, python3
13+}:
14+
15+let
16+ preBuild = ''
17+ patchShebangs .
18+
19+ # Tell rules_go to use the Go binary found in the PATH
20+ sed -E -i \
21+ -e 's|go_version\s*=\s*"[^"]+",|go_version = "host",|g' \
22+ WORKSPACE
23+
24+ # The gazelle Go tooling needs CA certs
25+ export SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt"
26+
27+ # If we don't reset our GOPATH, the rules_go stdlib builder tries to
28+ # install something into it. Ideally that wouldn't happen, but for now we
29+ # can also get around it by unsetting GOPATH entirely, since rules_go
30+ # doesn't need it.
31+ export GOPATH=
32+ '';
33+
34+in buildBazelPackage rec {
35+ name = "gvisor-${version}";
36+ version = "2019-11-14";
37+
38+ src = fetchFromGitHub {
39+ owner = "google";
40+ repo = "gvisor";
41+ rev = "release-20191114.0";
42+ sha256 = "0kyixjjlws9iz2r2srgpdd4rrq94vpxkmh2rmmzxd9mcqy2i9bg1";
43+ };
44+
45+ nativeBuildInputs = [ git glibcLocales go makeWrapper python3 ];
46+
47+ bazelTarget = "//runsc:runsc";
48+
49+ # gvisor uses the Starlark implementation of rules_cc, not the built-in one,
50+ # so we shouldn't delete it from our dependencies.
51+ removeRulesCC = false;
52+
53+ fetchAttrs = {
54+ inherit preBuild;
55+
56+ preInstall = ''
57+ # Remove the go_sdk (it's just a copy of the go derivation) and all
58+ # references to it from the marker files. Bazel does not need to download
59+ # this sdk because we have patched the WORKSPACE file to point to the one
60+ # currently present in PATH. Without removing the go_sdk from the marker
61+ # file, the hash of it will change anytime the Go derivation changes and
62+ # that would lead to impurities in the marker files which would result in
63+ # a different sha256 for the fetch phase.
64+ rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker}
65+
66+ # Remove the gazelle tools, they contain go binaries that are built
67+ # non-deterministically. As long as the gazelle version matches the tools
68+ # should be equivalent.
69+ rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker}
70+
71+ # Remove the gazelle repository cache
72+ chmod -R +w $bazelOut/external/bazel_gazelle_go_repository_cache
73+ rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,\@bazel_gazelle_go_repository_cache.marker}
74+
75+ # Remove log file(s)
76+ rm -f "$bazelOut"/java.log "$bazelOut"/java.log.*
77+ '';
78+
79+ sha256 = "122qk6iv8hd7g2a84y9aqqhij4r0m47vpxzbqhhh6k5livc73qd6";
80+ };
81+
82+ buildAttrs = {
83+ inherit preBuild;
84+
85+ installPhase = ''
86+ install -Dm755 bazel-bin/runsc/*_pure_stripped/runsc $out/bin/runsc
87+
88+ # Needed for the 'runsc do' subcomand
89+ wrapProgram $out/bin/runsc \
90+ --prefix PATH : ${stdenv.lib.makeBinPath [ iproute iptables procps ]}
91+ '';
92+ };
93+
94+ meta = with stdenv.lib; {
95+ description = "Container Runtime Sandbox";
96+ homepage = https://github.com/google/gvisor;
97+ license = licenses.asl20;
98+ maintainers = with maintainers; [ andrew-d ];
99+ platforms = [ "x86_64-linux" ];
100+ };
101+}
pkgs/top-level/all-packages.nix+4
@@ -19207,6 +19207,10 @@ in
1920719207
1920819208 gv = callPackage ../applications/misc/gv { };
1920919209
19210+ gvisor = callPackage ../applications/virtualization/gvisor { };
19211+
19212+ gvisor-containerd-shim = callPackage ../applications/virtualization/gvisor/containerd-shim.nix { };
19213+
1921019214 guvcview = callPackage ../os-specific/linux/guvcview { };
1921119215
1921219216 gxmessage = callPackage ../applications/misc/gxmessage { };