From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-4.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 Received: by atuin.qyliss.net (Postfix, from userid 496) id 54F226299; Sun, 11 Apr 2021 12:01:26 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 7D86B5EB4; Sun, 11 Apr 2021 11:58:47 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id 8C0C85EA5; Sun, 11 Apr 2021 11:58:46 +0000 (UTC) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by atuin.qyliss.net (Postfix) with ESMTPS id 886B55B92 for ; Sun, 11 Apr 2021 11:57:58 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id F37FE5C00D9 for ; Sun, 11 Apr 2021 07:57:57 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sun, 11 Apr 2021 07:57:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h= from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=pWiJ/4bt1Qf6a HAGwKKFi8XZRkstLv/1y7otNVaVfI8=; b=HV3qOQSMhyer3VMmNcG94VRAioA2A fYKyoo+NGV2sucZr0XvSJJdMWtXq0gUwTrkyGArS5gPwuAqwIPtNhjC6NT74Y9uF oZhhJz+evtvHbimZHVAAH0U8iXg3ik53RBZan7Pfs+mFnpXkWs8h+0TMU7127tE5 +DeqhFzuKqkODMdSc5ylXr43Qmd1mOuV6F7U8CUnC89le9ss8Nrcjx2N2HjuHgoJ mHYcgURPY9ghs+fCATk/K5oLtKL9rK09vuQjf/rrMWBcOpIFi3d1AZvvF9BwYr/4 sT6GwzQ1mqIus0wAzsO9f2KIJISlD0JPHmKkxVfv0t60KhGizKMHLqv4g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=pWiJ/4bt1Qf6aHAGwKKFi8XZRkstLv/1y7otNVaVfI8=; b=s1i0BgO6 98gGHJh2+qs6RBxeoW2CwcLmvHJwPRLhdm4MT/HT3VqXJQsc3g1f3Cg3b5ZTmTjU B2Y91pYqFv/8WG7/vXsisxq2PWOPtbzyBjVOgiwx/xYB65n86YxiQgomb5+6+G6i uLMvW2Y40fFbXIEM7h2biyh1TbqceZIk5xZzL3owjMlptOsWHaXT5cTKadfBvyn2 Ht5lSa0hWWG540IVh1US6S8v6DU4yqiD/kCGtOKanSaznS+B+55bBnb1gAHQad2p XGOmSY2w5CDdwMMNA5LCtrikLzGPLYYgYh/X9FoUbO+P3bbnBVhJU1hCJixTRHAu f4nFZEmE1OiBuw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudekgedgudejhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpeetlhihshhsrgcutfhoshhsuceohhhisegrlhihshhsrgdr ihhsqeenucggtffrrghtthgvrhhnpeelheekjefhieduteejffegteduhfegfeelvefgle duhefgvedugeeiffdvudelffenucffohhmrghinheprhgtshgvrhhvihgtvghsrdhnvght pdhgvghtthihrdhruhhnpdhshihsqdhvmhhsrdgrphhpnecukfhppeejledrvdefhedrud duledruddtjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhr ohhmpehqhihlihhsshesgidvvddtrdhqhihlihhsshdrnhgvth X-ME-Proxy: Received: from x220.qyliss.net (p4feb776b.dip0.t-ipconnect.de [79.235.119.107]) by mail.messagingengine.com (Postfix) with ESMTPA id C9170240054 for ; Sun, 11 Apr 2021 07:57:57 -0400 (EDT) Received: by x220.qyliss.net (Postfix, from userid 1000) id 664DC192F; Sun, 11 Apr 2021 11:57:56 +0000 (UTC) From: Alyssa Ross To: devel@spectrum-os.org Subject: [PATCH nixpkgs 15/16] spectrumPackages.sys-vms.app: init Date: Sun, 11 Apr 2021 11:57:39 +0000 Message-Id: <20210411115740.29615-16-hi@alyssa.is> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210411115740.29615-1-hi@alyssa.is> References: <20210411115740.29615-1-hi@alyssa.is> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: HAFGKKGK3VEASJ7QADDHRDEIJTGLAKGH X-Message-ID-Hash: HAFGKKGK3VEASJ7QADDHRDEIJTGLAKGH X-MailFrom: qyliss@x220.qyliss.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.3.1 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: This is a very barebones VM. It's purpose is just to be a demonstration that other VMs can connect to the router and have their packets reach the network. So all it does is infer its IPv4 address, and the IPv4 address of the router, from the MAC address of its virtual ethernet device, and configure the network interfaces and routes appropriately. vmID is an integer seed we can use to derive things for the VM like IP and VSOCK addresses. I don't foresee this sitting around, because I think it would make more sense for this to be assigned at runtime, since starting arbitrary VMs at runtime is a goal. But we'll need some way to ensure unique addresses. --- .../linux/spectrum/vm/app/default.nix | 63 +++++++++++++++++++ .../os-specific/linux/spectrum/vm/default.nix | 2 + 2 files changed, 65 insertions(+) create mode 100644 pkgs/os-specific/linux/spectrum/vm/app/default.nix diff --git a/pkgs/os-specific/linux/spectrum/vm/app/default.nix b/pkgs/os-specific/linux/spectrum/vm/app/default.nix new file mode 100644 index 00000000000..65dbb51f5e1 --- /dev/null +++ b/pkgs/os-specific/linux/spectrum/vm/app/default.nix @@ -0,0 +1,63 @@ +{ runCommand, writeScript, writeText, makeRootfs +, busybox, execline, linux_vm, jq, iproute +}: + +runCommand "vm-app" rec { + linux = linux_vm; + + login = writeScript "login" '' + #! ${execline}/bin/execlineb -s0 + unexport ! + ${busybox}/bin/login -p -f root $@ + ''; + + rootfs = makeRootfs { + rcServices.ok-all = { + type = writeText "ok-all-type" '' + bundle + ''; + contents = writeText "ok-all-contents" '' + net + ''; + }; + + rcServices.net = { + type = writeText "net-type" '' + oneshot + ''; + up = writeText "net-up" '' + backtick -i LOCAL_IP { + pipeline { ip -j link show eth0 } + pipeline { jq -r ".[0].address | split(\":\") | .[3:6] | \"0x\" + .[]" } + xargs printf "100.%d.%d.%d" + } + importas -iu LOCAL_IP LOCAL_IP + + backtick -i REMOTE_IP { + jq -jn --arg localip $LOCAL_IP + "$localip | split(\".\") | .[3] |= tonumber - 1 | join(\".\")" + } + importas -iu REMOTE_IP REMOTE_IP + + if { ip address add ''${LOCAL_IP}/31 dev eth0 } + if { ip link set eth0 up } + ip route add default via $REMOTE_IP + ''; + }; + + services.getty.run = writeScript "getty-run" '' + #! ${execline}/bin/execlineb -P + ${busybox}/bin/getty -i -n -l ${login} 38400 ttyS0 + ''; + + path = [ iproute jq ]; + }; + + inherit (rootfs) squashfs; + vmID = 0; +} '' + mkdir $out + echo "$vmID" > $out/vm-id + ln -s $linux/bzImage $out/kernel + ln -s $squashfs $out/squashfs +'' diff --git a/pkgs/os-specific/linux/spectrum/vm/default.nix b/pkgs/os-specific/linux/spectrum/vm/default.nix index c4ff729cb8a..f5d591a960a 100644 --- a/pkgs/os-specific/linux/spectrum/vm/default.nix +++ b/pkgs/os-specific/linux/spectrum/vm/default.nix @@ -1,6 +1,8 @@ { callPackage }: { + app = callPackage ./app { }; + comp = callPackage ./comp { }; net = callPackage ./net { }; -- 2.30.0