diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-14 06:37:24 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-14 06:39:00 +0900 |
| commit | 4c647add0db06cc7a28571aee7502737f0d66b27 (patch) | |
| tree | 7446453d4380ed21c3ad3c3f8026c708fc53e729 /cmd/hpkg | |
| parent | a3414669428d4de37b68aff3f2db14e5768e1f59 (diff) | |
hst/container: pack boolean options
The memory saving is relatively insignificant, however this increases serialisation efficiency.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd/hpkg')
| -rw-r--r-- | cmd/hpkg/app.go | 35 | ||||
| -rw-r--r-- | cmd/hpkg/with.go | 32 |
2 files changed, 49 insertions, 18 deletions
diff --git a/cmd/hpkg/app.go b/cmd/hpkg/app.go index d03c8b03..87a2c47c 100644 --- a/cmd/hpkg/app.go +++ b/cmd/hpkg/app.go @@ -76,15 +76,7 @@ func (app *appInfo) toHst(pathSet *appPathSet, pathname *check.Absolute, argv [] Groups: app.Groups, Container: &hst.ContainerConfig{ - Hostname: formatHostname(app.Name), - Devel: app.Devel, - Userns: app.Userns, - HostNet: app.HostNet, - HostAbstract: app.HostAbstract, - Device: app.Device, - Tty: app.Tty || flagDropShell, - MapRealUID: app.MapRealUID, - Multiarch: app.Multiarch, + Hostname: formatHostname(app.Name), Filesystem: []hst.FilesystemConfigJSON{ {FilesystemConfig: &hst.FSBind{Target: fhs.AbsEtc, Source: pathSet.cacheDir.Append("etc"), Special: true}}, {FilesystemConfig: &hst.FSBind{Source: pathSet.nixPath.Append("store"), Target: pathNixStore}}, @@ -113,6 +105,31 @@ func (app *appInfo) toHst(pathSet *appPathSet, pathname *check.Absolute, argv [] {Ensure: true, Path: pathSet.baseDir, Read: true, Write: true, Execute: true}, }, } + + if app.Devel { + config.Container.Flags |= hst.FDevel + } + if app.Userns { + config.Container.Flags |= hst.FUserns + } + if app.HostNet { + config.Container.Flags |= hst.FHostNet + } + if app.HostAbstract { + config.Container.Flags |= hst.FHostAbstract + } + if app.Device { + config.Container.Flags |= hst.FDevice + } + if app.Tty || flagDropShell { + config.Container.Flags |= hst.FTty + } + if app.MapRealUID { + config.Container.Flags |= hst.FMapRealUID + } + if app.Multiarch { + config.Container.Flags |= hst.FMultiarch + } return config } diff --git a/cmd/hpkg/with.go b/cmd/hpkg/with.go index 5cb1533e..5d6eb87c 100644 --- a/cmd/hpkg/with.go +++ b/cmd/hpkg/with.go @@ -17,6 +17,14 @@ func withNixDaemon( action string, command []string, net bool, updateConfig func(config *hst.Config) *hst.Config, app *appInfo, pathSet *appPathSet, dropShell bool, beforeFail func(), ) { + flags := hst.FMultiarch | hst.FUserns // nix sandbox requires userns + if net { + flags |= hst.FHostNet + } + if dropShell { + flags |= hst.FTty + } + mustRunAppDropShell(ctx, msg, updateConfig(&hst.Config{ ID: app.ID, @@ -28,11 +36,8 @@ func withNixDaemon( Identity: app.Identity, Container: &hst.ContainerConfig{ - Hostname: formatHostname(app.Name) + "-" + action, - Userns: true, // nix sandbox requires userns - HostNet: net, - Multiarch: true, - Tty: dropShell, + Hostname: formatHostname(app.Name) + "-" + action, + Filesystem: []hst.FilesystemConfigJSON{ {FilesystemConfig: &hst.FSBind{Target: fhs.AbsEtc, Source: pathSet.cacheDir.Append("etc"), Special: true}}, {FilesystemConfig: &hst.FSBind{Source: pathSet.nixPath, Target: pathNix, Write: true}}, @@ -58,6 +63,8 @@ func withNixDaemon( // terminate nix-daemon " && pkill nix-daemon", }, + + Flags: flags, }, }), dropShell, beforeFail) } @@ -66,7 +73,13 @@ func withCacheDir( ctx context.Context, msg message.Msg, action string, command []string, workDir *check.Absolute, - app *appInfo, pathSet *appPathSet, dropShell bool, beforeFail func()) { + app *appInfo, pathSet *appPathSet, dropShell bool, beforeFail func(), +) { + flags := hst.FMultiarch + if dropShell { + flags |= hst.FTty + } + mustRunAppDropShell(ctx, msg, &hst.Config{ ID: app.ID, @@ -79,9 +92,8 @@ func withCacheDir( Identity: app.Identity, Container: &hst.ContainerConfig{ - Hostname: formatHostname(app.Name) + "-" + action, - Multiarch: true, - Tty: dropShell, + Hostname: formatHostname(app.Name) + "-" + action, + Filesystem: []hst.FilesystemConfigJSON{ {FilesystemConfig: &hst.FSBind{Target: fhs.AbsEtc, Source: workDir.Append(fhs.Etc), Special: true}}, {FilesystemConfig: &hst.FSBind{Source: workDir.Append("nix"), Target: pathNix}}, @@ -98,6 +110,8 @@ func withCacheDir( Path: pathShell, Args: []string{bash, "-lc", strings.Join(command, " && ")}, + + Flags: flags, }, }, dropShell, beforeFail) } |
