From 288e0008cb1e6db55982971d7a42f1f0ddc4501c Mon Sep 17 00:00:00 2001 From: mirkobrombin Date: Sun, 19 May 2024 16:52:55 +0200 Subject: [PATCH] fix: there is no destinction between prompts with distrobox 1.7, the hostname is now in sync with the host. This commit explicitly sets the hostname to the subsystem name. Also allows to set a custom one using the Hostname key in the Subsystem struct. --- cmd/subsyStems.go | 2 +- core/dbox.go | 8 +++++++- core/subSystem.go | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/subsyStems.go b/cmd/subsyStems.go index b226a979..3a5290d6 100644 --- a/cmd/subsyStems.go +++ b/cmd/subsyStems.go @@ -242,7 +242,7 @@ func newSubSystem(cmd *cobra.Command, args []string) error { return err } - subSystem, err := core.NewSubSystem(subSystemName, stack, home, isInit, false, false, false, true) + subSystem, err := core.NewSubSystem(subSystemName, stack, home, isInit, false, false, false, true, "") if err != nil { return err } diff --git a/core/dbox.go b/core/dbox.go index 93956dff..a2c0dcc0 100644 --- a/core/dbox.go +++ b/core/dbox.go @@ -238,7 +238,7 @@ func (d *dbox) ContainerDelete(name string, rootFull bool) error { return err } -func (d *dbox) CreateContainer(name string, image string, additionalPackages []string, home string, labels map[string]string, withInit bool, rootFull bool, unshared bool, withNvidiaIntegration bool) error { +func (d *dbox) CreateContainer(name string, image string, additionalPackages []string, home string, labels map[string]string, withInit bool, rootFull bool, unshared bool, withNvidiaIntegration bool, hostname string) error { args := []string{ "--image", image, "--name", name, @@ -263,6 +263,12 @@ func (d *dbox) CreateContainer(name string, image string, additionalPackages []s args = append(args, "--unshare-all") } + if hostname != "" { + args = append(args, "--hostname", hostname) + } else { + args = append(args, "--hostname", name) + } + if len(additionalPackages) > 0 { args = append(args, "--additional-packages") args = append(args, strings.Join(additionalPackages, " ")) diff --git a/core/subSystem.go b/core/subSystem.go index b4cf4c16..6f43c7a6 100644 --- a/core/subSystem.go +++ b/core/subSystem.go @@ -32,9 +32,10 @@ type SubSystem struct { IsRootfull bool IsUnshared bool HasNvidiaIntegration bool + Hostname string } -func NewSubSystem(name string, stack *Stack, home string, hasInit bool, isManaged bool, isRootfull bool, isUnshared bool, hasNvidiaIntegration bool) (*SubSystem, error) { +func NewSubSystem(name string, stack *Stack, home string, hasInit bool, isManaged bool, isRootfull bool, isUnshared bool, hasNvidiaIntegration bool, hostname string) (*SubSystem, error) { internalName := genInternalName(name) return &SubSystem{ InternalName: internalName, @@ -46,6 +47,7 @@ func NewSubSystem(name string, stack *Stack, home string, hasInit bool, isManage IsRootfull: isRootfull, IsUnshared: isUnshared, HasNvidiaIntegration: hasNvidiaIntegration, + Hostname: hostname, }, nil } @@ -150,6 +152,7 @@ func (s *SubSystem) Create() error { s.IsRootfull, s.IsUnshared, s.HasNvidiaIntegration, + s.Hostname, ) if err != nil { return err