From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id MJ9WL5X1BF98dgAA0tVLHw (envelope-from ) for ; Tue, 07 Jul 2020 22:22:13 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id eNE6K5X1BF84VwAAB5/wlQ (envelope-from ) for ; Tue, 07 Jul 2020 22:22:13 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E5E9D940DA4 for ; Tue, 7 Jul 2020 22:22:10 +0000 (UTC) Received: from localhost ([::1]:35998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jsvya-00010L-Gr for larch@yhetil.org; Tue, 07 Jul 2020 18:22:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jsvyU-00010D-Hu for bug-guix@gnu.org; Tue, 07 Jul 2020 18:22:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53587) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jsvyU-0002pj-8b for bug-guix@gnu.org; Tue, 07 Jul 2020 18:22:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jsvyU-0002A6-4W for bug-guix@gnu.org; Tue, 07 Jul 2020 18:22:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#42252: Not possible to reliably port forward with "guix system vm" anymore Resent-From: Christopher Lemmer Webber Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Tue, 07 Jul 2020 22:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42252 X-GNU-PR-Package: guix X-GNU-PR-Keywords: X-Debbugs-Original-Cc: 42252@debbugs.gnu.org, bug-guix@gnu.org Received: via spool by 42252-submit@debbugs.gnu.org id=B42252.15941604818256 (code B ref 42252); Tue, 07 Jul 2020 22:22:02 +0000 Received: (at 42252) by debbugs.gnu.org; 7 Jul 2020 22:21:21 +0000 Received: from localhost ([127.0.0.1]:36900 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jsvxp-000295-9U for submit@debbugs.gnu.org; Tue, 07 Jul 2020 18:21:21 -0400 Received: from dustycloud.org ([50.116.34.160]:33550) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jsvxl-00028w-Pn for 42252@debbugs.gnu.org; Tue, 07 Jul 2020 18:21:19 -0400 Received: from twig (localhost [127.0.0.1]) by dustycloud.org (Postfix) with ESMTPS id 091EF26617; Tue, 7 Jul 2020 18:21:16 -0400 (EDT) References: <87r1tnf496.fsf@dustycloud.org> <87o8orf3cd.fsf@dustycloud.org> User-agent: mu4e 1.4.9; emacs 26.3 From: Christopher Lemmer Webber In-reply-to: <87o8orf3cd.fsf@dustycloud.org> Date: Tue, 07 Jul 2020 18:21:16 -0400 Message-ID: <87lfjvezkz.fsf@dustycloud.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 1.2 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: 0.2 (/) X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 42252@debbugs.gnu.org Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Spam-Score: 0.99 X-TUID: N+mbbEPYQ14Q --=-=-= Content-Type: text/plain Christopher Lemmer Webber writes: > Christopher Lemmer Webber writes: > >> guix system vm config.scm --hostfwd=tcp::10022-:22 --hostfwd=tcp::8888-:80 >> >> kind of ugly, but it could work. WDYT? > > Kind of uglier, but more versatile: > > guix system vm config.scm --nic=user,model=virtio-net-pci,hostfwd=tcp::10022-:22,hostfwd=tcp::8888-:80 Here's a patch that implements just that. Seems to work fine here! --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-guix-system-Add-nic-option-for-vm-subcommand.patch >From b008aad5d00fb6a87eb5a03d1849d6f52fb2307d Mon Sep 17 00:00:00 2001 From: Christopher Lemmer Webber Date: Tue, 7 Jul 2020 18:13:29 -0400 Subject: [PATCH] guix system: Add --nic option for 'vm' subcommand. This allows passing in explicit options for the qemu -nic keyword argument for use in port forwarding, etc. * (show-help, %options, process-action): Add and use command line argument of --nic for `guix system vm' and pass along appropriately. guix/scripts/system.scm (system-derivation-for-action): (perform-action): Define and use #:nic-options keyword. * gnu/system/vm.scm (common-qemu-options) (system-qemu-image/shared-store-script): Likewise. (default-nic-options): New variable. * doc/guix.texi (Running Guix in a VM): Use --nic argument in system vm port forwarding example. --- doc/guix.texi | 2 +- gnu/system/vm.scm | 16 ++++++++++++---- guix/scripts/system.scm | 18 ++++++++++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 992bc303bb..4e76eb832a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -28315,7 +28315,7 @@ To enable SSH inside a VM you need to add an SSH server like 22 by default, to the host. You can do this with @example -`guix system vm config.scm` -nic user,model=virtio-net-pci,hostfwd=tcp::10022-:22 +`guix system vm config.scm --nic=user,model=virtio-net-pci,hostfwd=tcp::10022-:22` @end example To connect to the VM you can run diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index f2b6b71b4d..78f89f6568 100644 --- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -803,7 +803,11 @@ bootloader refers to: OS kernel, initrd, bootloader data, etc." #:register-closures? #f #:copy-inputs? full-boot?)) -(define* (common-qemu-options image shared-fs) +(define default-nic-options + "user,model=virtio-net-pci") + +(define* (common-qemu-options image shared-fs + #:key nic-options) "Return the a string-value gexp with the common QEMU options to boot IMAGE, with '-virtfs' options for the host file systems listed in SHARED-FS." @@ -819,7 +823,9 @@ with '-virtfs' options for the host file systems listed in SHARED-FS." '()) "-no-reboot" - "-nic" "user,model=virtio-net-pci" + + ;; Construct -nic while forwarding all --hostfwd=... options + "-nic" #$(or nic-options default-nic-options) "-object" "rng-random,filename=/dev/urandom,id=guixsd-vm-rng" "-device" "virtio-rng-pci,rng=guixsd-vm-rng" @@ -840,7 +846,8 @@ with '-virtfs' options for the host file systems listed in SHARED-FS." (disk-image-size (* (if full-boot? 500 70) (expt 2 20))) - (options '())) + (options '()) + (nic-options #f)) "Return a derivation that builds a script to run a virtual machine image of OS that shares its store with the host. The virtual machine runs with MEMORY-SIZE MiB of memory. @@ -874,7 +881,8 @@ it is mostly useful when FULL-BOOT? is true." (string-join #$kernel-arguments " ")))) #$@(common-qemu-options image (map file-system-mapping-source - (cons %store-mapping mappings))) + (cons %store-mapping mappings)) + #:nic-options nic-options) "-m " (number->string #$memory-size) #$@options)) diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 61eeec622b..32cea9b184 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -684,7 +684,7 @@ checking this by themselves in their 'check' procedure." (define* (system-derivation-for-action os base-image action #:key image-size file-system-type full-boot? container-shared-network? - mappings) + mappings nic-options) "Return as a monadic value the derivation for OS according to ACTION." (case action ((build init reconfigure) @@ -703,7 +703,8 @@ checking this by themselves in their 'check' procedure." (if full-boot? image-size (* 70 (expt 2 20))) - #:mappings mappings)) + #:mappings mappings + #:nic-options nic-options)) ((disk-image) (lower-object (system-image @@ -764,6 +765,7 @@ and TARGET arguments." use-substitutes? bootloader-target target image-size file-system-type full-boot? container-shared-network? + nic-options (mappings '()) (gc-root #f)) "Perform ACTION for OS. INSTALL-BOOTLOADER? specifies whether to install @@ -819,7 +821,8 @@ static checks." #:image-size image-size #:full-boot? full-boot? #:container-shared-network? container-shared-network? - #:mappings mappings)) + #:mappings mappings + #:nic-options nic-options)) ;; For 'init' and 'reconfigure', always build BOOTCFG, even if ;; --no-bootloader is passed, because we then use it as a GC root. @@ -965,6 +968,8 @@ Some ACTIONS support additional ARGS.\n")) --share=SPEC for 'vm', share host file system according to SPEC")) (display (G_ " --expose=SPEC for 'vm', expose host file system according to SPEC")) + (display (G_ " + --nic=NIC-OPTIONS for 'fm', set the value passed to qemu's -nic option")) (display (G_ " -N, --network for 'container', allow containers to access the network")) (display (G_ " @@ -1014,6 +1019,10 @@ Some ACTIONS support additional ARGS.\n")) (lambda (opt name arg result) (alist-cons 'image-size (size->number arg) result))) + (option '("nic") #t #f + (lambda (opt name arg result) + (alist-cons 'nic-options arg + result))) (option '(#\N "network") #f #f (lambda (opt name arg result) (alist-cons 'container-shared-network? #t result))) @@ -1172,7 +1181,8 @@ resulting from command-line parsing." #:install-bootloader? bootloader? #:target target-file #:bootloader-target bootloader-target - #:gc-root (assoc-ref opts 'gc-root))))) + #:gc-root (assoc-ref opts 'gc-root) + #:nic-options (assoc-ref opts 'nic-options))))) #:target target #:system system))) (warn-about-disk-space))) -- 2.26.2 --=-=-=--