aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-14 06:37:24 +0900
committerOphestra <cat@gensokyo.uk>2025-10-14 06:39:00 +0900
commit4c647add0db06cc7a28571aee7502737f0d66b27 (patch)
tree7446453d4380ed21c3ad3c3f8026c708fc53e729 /cmd
parenta3414669428d4de37b68aff3f2db14e5768e1f59 (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')
-rw-r--r--cmd/hakurei/command.go7
-rw-r--r--cmd/hakurei/print.go20
-rw-r--r--cmd/hakurei/print_test.go60
-rw-r--r--cmd/hpkg/app.go35
-rw-r--r--cmd/hpkg/with.go32
5 files changed, 91 insertions, 63 deletions
diff --git a/cmd/hakurei/command.go b/cmd/hakurei/command.go
index 187ed5d3..0cf0ef1b 100644
--- a/cmd/hakurei/command.go
+++ b/cmd/hakurei/command.go
@@ -147,11 +147,6 @@ func buildCommand(ctx context.Context, msg message.Msg, early *earlyHardeningErr
Enablements: hst.NewEnablements(et),
Container: &hst.ContainerConfig{
- Userns: true,
- HostNet: true,
- Tty: true,
- HostAbstract: true,
-
Filesystem: []hst.FilesystemConfigJSON{
// autoroot, includes the home directory
{FilesystemConfig: &hst.FSBind{
@@ -167,6 +162,8 @@ func buildCommand(ctx context.Context, msg message.Msg, early *earlyHardeningErr
Path: progPath,
Args: args,
+
+ Flags: hst.FUserns | hst.FHostNet | hst.FHostAbstract | hst.FTty,
},
}
diff --git a/cmd/hakurei/print.go b/cmd/hakurei/print.go
index e013909d..db183d71 100644
--- a/cmd/hakurei/print.go
+++ b/cmd/hakurei/print.go
@@ -87,19 +87,19 @@ func printShowInstance(
t.Printf(" Hostname:\t%s\n", params.Hostname)
}
flags := make([]string, 0, 7)
- writeFlag := func(name string, value bool) {
- if value {
+ writeFlag := func(name string, flag uintptr, force bool) {
+ if params.Flags&flag != 0 || force {
flags = append(flags, name)
}
}
- writeFlag("userns", params.Userns)
- writeFlag("devel", params.Devel)
- writeFlag("net", params.HostNet)
- writeFlag("abstract", params.HostAbstract)
- writeFlag("device", params.Device)
- writeFlag("tty", params.Tty)
- writeFlag("mapuid", params.MapRealUID)
- writeFlag("directwl", config.DirectWayland)
+ writeFlag("userns", hst.FUserns, false)
+ writeFlag("devel", hst.FDevel, false)
+ writeFlag("net", hst.FHostNet, false)
+ writeFlag("abstract", hst.FHostAbstract, false)
+ writeFlag("device", hst.FDevice, false)
+ writeFlag("tty", hst.FTty, false)
+ writeFlag("mapuid", hst.FMapRealUID, false)
+ writeFlag("directwl", 0, config.DirectWayland)
if len(flags) == 0 {
flags = append(flags, "none")
}
diff --git a/cmd/hakurei/print_test.go b/cmd/hakurei/print_test.go
index a0bb198c..7679c67b 100644
--- a/cmd/hakurei/print_test.go
+++ b/cmd/hakurei/print_test.go
@@ -252,20 +252,11 @@ App
"container": {
"hostname": "localhost",
"wait_delay": -1,
- "seccomp_compat": true,
- "devel": true,
- "userns": true,
- "host_net": true,
- "host_abstract": true,
- "tty": true,
- "multiarch": true,
"env": {
"GOOGLE_API_KEY": "AIzaSyBHDrl33hwRp4rMQY0ziRbj8K9LPA6vUCY",
"GOOGLE_DEFAULT_CLIENT_ID": "77185425430.apps.googleusercontent.com",
"GOOGLE_DEFAULT_CLIENT_SECRET": "OTJgUOQcT7lO7GsGZq2G4IlT"
},
- "map_real_uid": true,
- "device": true,
"filesystem": [
{
"type": "bind",
@@ -331,7 +322,16 @@ App
"--disable-smooth-scrolling",
"--enable-features=UseOzonePlatform",
"--ozone-platform=wayland"
- ]
+ ],
+ "seccomp_compat": true,
+ "devel": true,
+ "userns": true,
+ "host_net": true,
+ "host_abstract": true,
+ "tty": true,
+ "multiarch": true,
+ "map_real_uid": true,
+ "device": true
}
},
"time": "1970-01-01T00:00:00.000000009Z"
@@ -402,20 +402,11 @@ App
"container": {
"hostname": "localhost",
"wait_delay": -1,
- "seccomp_compat": true,
- "devel": true,
- "userns": true,
- "host_net": true,
- "host_abstract": true,
- "tty": true,
- "multiarch": true,
"env": {
"GOOGLE_API_KEY": "AIzaSyBHDrl33hwRp4rMQY0ziRbj8K9LPA6vUCY",
"GOOGLE_DEFAULT_CLIENT_ID": "77185425430.apps.googleusercontent.com",
"GOOGLE_DEFAULT_CLIENT_SECRET": "OTJgUOQcT7lO7GsGZq2G4IlT"
},
- "map_real_uid": true,
- "device": true,
"filesystem": [
{
"type": "bind",
@@ -481,7 +472,16 @@ App
"--disable-smooth-scrolling",
"--enable-features=UseOzonePlatform",
"--ozone-platform=wayland"
- ]
+ ],
+ "seccomp_compat": true,
+ "devel": true,
+ "userns": true,
+ "host_net": true,
+ "host_abstract": true,
+ "tty": true,
+ "multiarch": true,
+ "map_real_uid": true,
+ "device": true
}
}
`, true},
@@ -612,20 +612,11 @@ func TestPrintPs(t *testing.T) {
"container": {
"hostname": "localhost",
"wait_delay": -1,
- "seccomp_compat": true,
- "devel": true,
- "userns": true,
- "host_net": true,
- "host_abstract": true,
- "tty": true,
- "multiarch": true,
"env": {
"GOOGLE_API_KEY": "AIzaSyBHDrl33hwRp4rMQY0ziRbj8K9LPA6vUCY",
"GOOGLE_DEFAULT_CLIENT_ID": "77185425430.apps.googleusercontent.com",
"GOOGLE_DEFAULT_CLIENT_SECRET": "OTJgUOQcT7lO7GsGZq2G4IlT"
},
- "map_real_uid": true,
- "device": true,
"filesystem": [
{
"type": "bind",
@@ -691,7 +682,16 @@ func TestPrintPs(t *testing.T) {
"--disable-smooth-scrolling",
"--enable-features=UseOzonePlatform",
"--ozone-platform=wayland"
- ]
+ ],
+ "seccomp_compat": true,
+ "devel": true,
+ "userns": true,
+ "host_net": true,
+ "host_abstract": true,
+ "tty": true,
+ "multiarch": true,
+ "map_real_uid": true,
+ "device": true
}
},
"time": "1970-01-01T00:00:00.000000009Z"
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)
}