patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 7aff6ed7cb5ca25cc178a705be0dfb94cf517719 1498 bytes (raw)
name: vm-lib/make-vm.nix 	 # note: path name is non-authoritative(*)

 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
 
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>

{ pkgs ? import <nixpkgs> {}

# Paths that are present in the base image that will start this VM's
# run script, and don't so need to be duplicated in the extension
# partition's store.
, basePaths ? builtins.toFile "null" ""
}:

pkgs.pkgsStatic.callPackage (

{ lib, runCommand, writeReferencesToFile, e2fsprogs, tar2ext4 }:

{ run, run-as-user, providers ? {} }:

let
  inherit (lib)
    any attrValues concatLists concatStrings hasInfix mapAttrsToList;
in

assert !(any (hasInfix "\n") (concatLists (attrValues providers)));

runCommand "spectrum-vm" {
  nativeBuildInputs = [ e2fsprogs tar2ext4 ];

  providerDirs = concatStrings (concatLists
    (mapAttrsToList (kind: map (vm: "${kind}/${vm}\n")) providers));
  passAsFile = [ "providerDirs" ];
} ''
  mkdir -p "$out"/{blk,providers}

  mkdir root
  cd root
  ln -s ${run} run
  ln -s ${run-as-user} run-as-user
  comm -23 <(sort ${writeReferencesToFile run} ${writeReferencesToFile run-as-user}) \
      <(sort ${writeReferencesToFile basePaths}) |
      tar -cf ../run.tar --verbatim-files-from -T - run run-as-user
  tar2ext4 -i ../run.tar -o "$out/blk/run.img"
  e2label "$out/blk/run.img" ext

  pushd "$out/providers"
  xargs -rd '\n' dirname -- < "$providerDirsPath" | xargs -rd '\n' mkdir -p --
  xargs -rd '\n' touch -- < "$providerDirsPath"
  popd

  ln -s /usr/img/appvm/blk/root.img "$out/blk"
  ln -s /usr/img/appvm/vmlinux "$out"
''
) {}

debug log:

solving 7aff6ed ...
found 7aff6ed in https://inbox.spectrum-os.org/spectrum-devel/20221204224506.1801177-2-vadim.likholetov@unikie.com/
found 2c50ca5 in https://inbox.spectrum-os.org/spectrum-devel/20221010232909.1953738-30-hi@alyssa.is/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20221009114036.463071-7-hi@alyssa.is/

applying [1/2] https://inbox.spectrum-os.org/spectrum-devel/20221010232909.1953738-30-hi@alyssa.is/
diff --git a/vm-lib/make-vm.nix b/vm-lib/make-vm.nix
new file mode 100644
index 0000000..2c50ca5

Checking patch vm-lib/make-vm.nix...
Applied patch vm-lib/make-vm.nix cleanly.

skipping https://inbox.spectrum-os.org/spectrum-devel/20221009114036.463071-7-hi@alyssa.is/ for 2c50ca5
index at:
100644 2c50ca572735ceb0697454643b22296f37c6754c	vm-lib/make-vm.nix

applying [2/2] https://inbox.spectrum-os.org/spectrum-devel/20221204224506.1801177-2-vadim.likholetov@unikie.com/
diff --git a/vm-lib/make-vm.nix b/vm-lib/make-vm.nix
index 2c50ca5..7aff6ed 100644

Checking patch vm-lib/make-vm.nix...
Applied patch vm-lib/make-vm.nix cleanly.

index at:
100644 7aff6ed7cb5ca25cc178a705be0dfb94cf517719	vm-lib/make-vm.nix

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).