diff mbox series

[bug#35895] linux-container: Remove networking service whennetwork is shared with host.

Message ID cu7zhmqebur.fsf@systemreboot.net
State Accepted
Headers show
Series [bug#35895] linux-container: Remove networking service whennetwork is shared with host. | expand

Checks

Context Check Description
cbaines/applying patch fail Apply failed

Commit Message

Arun Isaac June 9, 2019, 8:35 p.m. UTC
Thank you both for the review. I have made the suggested changes. Please
find attached an updated patch.

In the future, please address me in the Cc or To fields so that I take
note sooner. I found your mails only a couple of days ago while going
through all my unread mails. :-(

Comments

Ludovic Courtès June 13, 2019, 9:02 p.m. UTC | #1
Hello,

Arun Isaac <arunisaac@systemreboot.net> skribis:

> From a7b795d9af3347330b48470d3988d43b8038c2c1 Mon Sep 17 00:00:00 2001
> From: Arun Isaac <arunisaac@systemreboot.net>
> Date: Sat, 25 May 2019 11:49:42 +0530
> Subject: [PATCH] linux-container: Remove networking service when network is
>  shared with host.
>
> * gnu/system/linux-container.scm (dummy-networking-shepherd-service): New
> procedure.
> (dummy-networking-service-type): New variable.
> (containerized-operating-system): If network is shared with host, replace
> static-networking-service-type with dummy-networking-service-type.

[...]

> +(define dummy-networking-shepherd-service
> +  (shepherd-service
> +   (documentation "Provide loopback and networking without actually doing
> +anything.")
> +   (provision '(loopback networking))
> +   (start #~(const #t))))
> +
> +(define dummy-networking-service-type
> +  (service-type
> +   (name 'dummy-networking)
> +   (extensions
> +    (list (service-extension
> +           shepherd-root-service-type
> +           (const (list dummy-networking-shepherd-service)))))
> +   (default-value #f)))

You can use ‘shepherd-service-type’ as a shorthand for these two
definitions.

> +    (services (append
> +               (remove (lambda (service)
> +                         (memq (service-kind service)
> +                               useless-services))
> +                       (operating-system-user-services os))
> +               ;; Many Guix services depend on a 'networking' shepherd
> +               ;; service, so make sure to provide a dummy 'networking'
> +               ;; service when we are sure that networking is already set up
> +               ;; in the host and can be used.  That prevents double setup.
> +               (if shared-network?
> +                   (list (service dummy-networking-service-type))
> +                   (list))))

I’m really nitpicking here, but I like to have the first argument to
‘append’ on the same line, and I also visually recognize '() more easily
than (list).

Anyway, LGTM!

Thanks,
Ludo’.
diff mbox series

Patch

From a7b795d9af3347330b48470d3988d43b8038c2c1 Mon Sep 17 00:00:00 2001
From: Arun Isaac <arunisaac@systemreboot.net>
Date: Sat, 25 May 2019 11:49:42 +0530
Subject: [PATCH] linux-container: Remove networking service when network is
 shared with host.

* gnu/system/linux-container.scm (dummy-networking-shepherd-service): New
procedure.
(dummy-networking-service-type): New variable.
(containerized-operating-system): If network is shared with host, replace
static-networking-service-type with dummy-networking-service-type.
---
 gnu/system/linux-container.scm | 36 +++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/gnu/system/linux-container.scm b/gnu/system/linux-container.scm
index c1e963d047..95b56b6f4f 100644
--- a/gnu/system/linux-container.scm
+++ b/gnu/system/linux-container.scm
@@ -30,6 +30,7 @@ 
   #:use-module (gnu build linux-container)
   #:use-module (gnu services)
   #:use-module (gnu services base)
+  #:use-module (gnu services shepherd)
   #:use-module (gnu system)
   #:use-module (gnu system file-systems)
   #:export (system-container
@@ -65,6 +66,22 @@  from OS that are needed on the bare metal and not in a container."
                          files)))
             base)))
 
+(define dummy-networking-shepherd-service
+  (shepherd-service
+   (documentation "Provide loopback and networking without actually doing
+anything.")
+   (provision '(loopback networking))
+   (start #~(const #t))))
+
+(define dummy-networking-service-type
+  (service-type
+   (name 'dummy-networking)
+   (extensions
+    (list (service-extension
+           shepherd-root-service-type
+           (const (list dummy-networking-shepherd-service)))))
+   (default-value #f)))
+
 (define* (containerized-operating-system os mappings
                                          #:key
                                          shared-network?
@@ -96,7 +113,8 @@  containerized OS.  EXTRA-FILE-SYSTEMS is a list of file systems to add to OS."
                   agetty-service-type)
             ;; Remove nscd service if network is shared with the host.
             (if shared-network?
-                (list nscd-service-type)
+                (list nscd-service-type
+                      static-networking-service-type)
                 (list))))
 
   (operating-system
@@ -105,10 +123,18 @@  containerized OS.  EXTRA-FILE-SYSTEMS is a list of file systems to add to OS."
     (essential-services (container-essential-services
                          this-operating-system
                          #:shared-network? shared-network?))
-    (services (remove (lambda (service)
-                        (memq (service-kind service)
-                              useless-services))
-                      (operating-system-user-services os)))
+    (services (append
+               (remove (lambda (service)
+                         (memq (service-kind service)
+                               useless-services))
+                       (operating-system-user-services os))
+               ;; Many Guix services depend on a 'networking' shepherd
+               ;; service, so make sure to provide a dummy 'networking'
+               ;; service when we are sure that networking is already set up
+               ;; in the host and can be used.  That prevents double setup.
+               (if shared-network?
+                   (list (service dummy-networking-service-type))
+                   (list))))
     (file-systems (append (map mapping->fs
                                (if shared-network?
                                    (append %network-file-mappings mappings)
-- 
2.21.0