git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #52352 from hyperfekt/init_crosvm

crosvm: init at 77.0.3865.105

commite726201cc8027551134134fb0e844b9ed1527256 authorMichael Raskin <7c6f434c@mail.ru> dateTue 17 Dec 2019, 15:22 (7 years ago) parent352f03059a5ba4
6 files changed+207−4
pkgs/applications/virtualization/crosvm/default-seccomp-policy-dir.patch+15 pkgs/applications/virtualization/crosvm/default.nix+83 pkgs/applications/virtualization/crosvm/update.py+85 pkgs/applications/virtualization/crosvm/upstream-info.json+19 pkgs/tools/system/minijail/default.nix+3−4 pkgs/top-level/all-packages.nix+2
pkgs/applications/virtualization/crosvm/default-seccomp-policy-dir.patchnew file+15
@@ -0,0 +1,15 @@
1+diff --git a/src/main.rs b/src/main.rs
2+index 81f20a7..481ebd7 100644
3+--- a/src/main.rs
4++++ b/src/main.rs
5+@@ -158,7 +158,9 @@ impl Default for Config {
6+ wayland_dmabuf: false,
7+ shared_dirs: Vec::new(),
8+ sandbox: !cfg!(feature = "default-no-sandbox"),
9+- seccomp_policy_dir: PathBuf::from(SECCOMP_POLICY_DIR),
10++ seccomp_policy_dir: PathBuf::from(
11++ option_env!("DEFAULT_SECCOMP_POLICY_DIR").unwrap_or(SECCOMP_POLICY_DIR),
12++ ),
13+ seccomp_log_failures: false,
14+ cras_audio: false,
15+ cras_capture: false,
pkgs/applications/virtualization/crosvm/default.nixnew file+83
@@ -0,0 +1,83 @@
1+{ stdenv, rustPlatform, fetchgit, runCommand, symlinkJoin
2+, pkgconfig, minijail, dtc, libusb1, libcap
3+}:
4+
5+let
6+
7+ upstreamInfo = with builtins; fromJSON (readFile ./upstream-info.json);
8+
9+ arch = with stdenv.hostPlatform;
10+ if isAarch64 then "arm"
11+ else if isx86_64 then "x86_64"
12+ else throw "no seccomp policy files available for host platform";
13+
14+ # used to turn symlinks into real files because write permissions are necessary for the vendoring process
15+ delink = src: runCommand "${src.name}-delinked" {
16+ preferLocalBuild = true;
17+ allowSubstitutes = false;
18+ } ''
19+ cp -prL --reflink=auto ${src} $out
20+ '';
21+
22+ # used to place subtrees into the location they have in the Chromium monorepo
23+ move = src: target: runCommand "moved-${src.name}" {
24+ preferLocalBuild = true;
25+ allowSubstitutes = false;
26+ } ''
27+ mkdir -p $(dirname $out/${target})
28+ ln -s ${src} $out/${target}
29+ '';
30+
31+ # used to check out subtrees from the Chromium monorepo
32+ chromiumSource = name: subtrees: delink (symlinkJoin {
33+ inherit name;
34+ paths = stdenv.lib.mapAttrsToList (
35+ location: { url, rev, sha256, fetchSubmodules, ... }:
36+ move (fetchgit {
37+ inherit url rev sha256 fetchSubmodules;
38+ }) location) subtrees;
39+ });
40+
41+in
42+
43+ rustPlatform.buildRustPackage rec {
44+ pname = "crosvm";
45+ inherit (upstreamInfo) version;
46+
47+ src = chromiumSource "${pname}-sources" upstreamInfo.components;
48+
49+ sourceRoot = "${src.name}/chromiumos/platform/crosvm";
50+
51+ patches = [
52+ ./default-seccomp-policy-dir.patch
53+ ];
54+
55+ cargoSha256 = "16cfp79c13ng5jjcrvz00h3cg7cc9ywhjiq02vsm757knn9jgr1v";
56+
57+ nativeBuildInputs = [ pkgconfig ];
58+
59+ buildInputs = [ dtc libcap libusb1 minijail ];
60+
61+ postPatch = ''
62+ sed -i "s|/usr/share/policy/crosvm/|$out/share/policy/|g" \
63+ seccomp/*/*.policy
64+ '';
65+
66+ preBuild = ''
67+ export DEFAULT_SECCOMP_POLICY_DIR=$out/share/policy
68+ '';
69+
70+ postInstall = ''
71+ mkdir -p $out/share/policy/
72+ cp seccomp/${arch}/* $out/share/policy/
73+ '';
74+
75+ passthru.updateScript = ./update.py;
76+
77+ meta = with stdenv.lib; {
78+ description = "A secure virtual machine monitor for KVM";
79+ homepage = "https://chromium.googlesource.com/chromiumos/platform/crosvm/";
80+ license = licenses.bsd3;
81+ platforms = [ "aarch64-linux" "x86_64-linux" ];
82+ };
83+ }
pkgs/applications/virtualization/crosvm/update.pynew file+85
@@ -0,0 +1,85 @@
1+#! /usr/bin/env nix-shell
2+#! nix-shell -p python3 -p nix-prefetch-git -i python
3+
4+import base64
5+import csv
6+import json
7+import re
8+import subprocess
9+import xml.etree.ElementTree as ElementTree
10+from codecs import iterdecode
11+from operator import itemgetter
12+from os.path import dirname, splitext
13+from urllib.request import urlopen
14+
15+# ChromiumOS components required to build crosvm.
16+components = ['chromiumos/platform/crosvm', 'chromiumos/third_party/adhd']
17+
18+git_root = 'https://chromium.googlesource.com/'
19+manifest_versions = f'{git_root}chromiumos/manifest-versions'
20+buildspecs_url = f'{manifest_versions}/+/refs/heads/master/paladin/buildspecs/'
21+
22+# CrOS version numbers look like this:
23+# [<chrome-major-version>.]<tip-build>.<branch-build>.<branch-branch-build>
24+#
25+# As far as I can tell, branches are where internal Google
26+# modifications are added to turn Chromium OS into Chrome OS, and
27+# branch branches are used for fixes for specific devices. So for
28+# Chromium OS they will always be 0. This is a best guess, and is not
29+# documented.
30+with urlopen('https://cros-omahaproxy.appspot.com/all') as resp:
31+ versions = csv.DictReader(iterdecode(resp, 'utf-8'))
32+ stables = filter(lambda v: v['track'] == 'stable-channel', versions)
33+ stable = sorted(stables, key=itemgetter('chrome_version'), reverse=True)[0]
34+
35+chrome_major_version = re.match(r'\d+', stable['chrome_version'])[0]
36+chromeos_tip_build = re.match(r'\d+', stable['chromeos_version'])[0]
37+
38+# Find the most recent buildspec for the stable Chrome version and
39+# Chromium OS build number. Its branch build and branch branch build
40+# numbers will (almost?) certainly be 0. It will then end with an rc
41+# number -- presumably these are release candidates, one of which
42+# becomes the final release. Presumably the one with the highest rc
43+# number.
44+with urlopen(f'{buildspecs_url}{chrome_major_version}/?format=TEXT') as resp:
45+ listing = base64.decodebytes(resp.read()).decode('utf-8')
46+ buildspecs = [(line.split('\t', 1)[1]) for line in listing.splitlines()]
47+ buildspecs = [s for s in buildspecs if s.startswith(chromeos_tip_build)]
48+ buildspecs.sort(reverse=True)
49+ buildspec = splitext(buildspecs[0])[0]
50+
51+revisions = {}
52+
53+# Read the buildspec, and extract the git revisions for each component.
54+with urlopen(f'{buildspecs_url}{chrome_major_version}/{buildspec}.xml?format=TEXT') as resp:
55+ xml = base64.decodebytes(resp.read()).decode('utf-8')
56+ root = ElementTree.fromstring(xml)
57+ for project in root.findall('project'):
58+ revisions[project.get('name')] = project.get('revision')
59+
60+# Initialize the data that will be output from this script. Leave the
61+# rc number in buildspec so nobody else is subject to the same level
62+# of confusion I have been.
63+data = {'version': f'{chrome_major_version}.{buildspec}', 'components': {}}
64+
65+# Fill in the 'components' dictionary with the output from
66+# nix-prefetch-git, which can be passed straight to fetchGit when
67+# imported by Nix.
68+for component in components:
69+ argv = ['nix-prefetch-git',
70+ '--url', git_root + component,
71+ '--rev', revisions[component]]
72+
73+ output = subprocess.check_output(argv)
74+ data['components'][component] = json.loads(output.decode('utf-8'))
75+
76+# Find the path to crosvm's default.nix, so the srcs data can be
77+# written into the same directory.
78+argv = ['nix-instantiate', '--eval', '--json', '-A', 'crosvm.meta.position']
79+position = json.loads(subprocess.check_output(argv).decode('utf-8'))
80+filename = re.match(r'[^:]*', position)[0]
81+
82+# Finally, write the output.
83+with open(dirname(filename) + '/upstream-info.json', 'w') as out:
84+ json.dump(data, out, indent=2)
85+ out.write('\n')
pkgs/applications/virtualization/crosvm/upstream-info.jsonnew file+19
@@ -0,0 +1,19 @@
1+{
2+ "version": "77.12371.0.0-rc1",
3+ "components": {
4+ "chromiumos/platform/crosvm": {
5+ "url": "https://chromium.googlesource.com/chromiumos/platform/crosvm",
6+ "rev": "f5285c647acacb4f25ef8cf9334254b976e71686",
7+ "date": "2019-07-25T22:15:48+00:00",
8+ "sha256": "1ccjd540xmpad082w9ri13q78wkg95xxmq38b8ybcrj4f7lsxm6w",
9+ "fetchSubmodules": false
10+ },
11+ "chromiumos/third_party/adhd": {
12+ "url": "https://chromium.googlesource.com/chromiumos/third_party/adhd",
13+ "rev": "a1c0d93d991daffb042b979ac807bbe9c1f9a3ee",
14+ "date": "2019-07-25T20:38:50-07:00",
15+ "sha256": "11bijqd876adarq96syywn6znfbiflqssgb2j4w032iw2vfnnsyy",
16+ "fetchSubmodules": false
17+ }
18+ }
19+}
pkgs/tools/system/minijail/default.nix+3−4
@@ -1,14 +1,13 @@
11{ stdenv, fetchgit, libcap }:
22
33stdenv.mkDerivation rec {
4− shortname = "minijail";
5− name = "${shortname}-${version}";
6− version = "android-9.0.0_r3";
4+ pname = "minijail";
5+ version = "android-10.0.0_r9";
76
87 src = fetchgit {
98 url = "https://android.googlesource.com/platform/external/minijail";
109 rev = version;
11− sha256 = "1g1g52s3q61amcnx8cv1332sbixpck1bmjzgsrjiw5ix7chrzkp2";
10+ sha256 = "0gcfsyim1krrddcklydqfxl8mamaxgail2xl5qp9yclq60km8f22";
1211 };
1312
1413 buildInputs = [ libcap ];
pkgs/top-level/all-packages.nix+2
@@ -1493,6 +1493,8 @@ in
14931493
14941494 crip = callPackage ../applications/audio/crip { };
14951495
1496+ crosvm = callPackage ../applications/virtualization/crosvm { };
1497+
14961498 crunch = callPackage ../tools/security/crunch { };
14971499
14981500 crudini = callPackage ../tools/misc/crudini { };