aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-23 23:25:46 +0900
committerOphestra <cat@gensokyo.uk>2025-10-24 00:42:16 +0900
commit2442eda8d960681d53e5f463a974a7f44ffe312e (patch)
treea30501452180df8f2966200a70a0599e767d631c
parent05488bfb8f43f12bc0306e03b675d4f415fc6328 (diff)
hst/instance: embed config struct
This makes the resulting json easier to parse since it can now be deserialised into the config struct. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--cmd/hakurei/print_test.go552
-rw-r--r--cmd/hpkg/test/test.py10
-rw-r--r--hst/instance.go2
-rw-r--r--test/test.py14
4 files changed, 285 insertions, 293 deletions
diff --git a/cmd/hakurei/print_test.go b/cmd/hakurei/print_test.go
index cbf23d14..41ce5543 100644
--- a/cmd/hakurei/print_test.go
+++ b/cmd/hakurei/print_test.go
@@ -189,154 +189,152 @@ App
"instance": "8e2c76b066dabe574cf073bdb46eb5c1",
"pid": 3405691582,
"shim_pid": 3735928559,
- "config": {
- "id": "org.chromium.Chromium",
- "enablements": {
- "wayland": true,
- "dbus": true,
- "pulse": true
+ "id": "org.chromium.Chromium",
+ "enablements": {
+ "wayland": true,
+ "dbus": true,
+ "pulse": true
+ },
+ "session_bus": {
+ "see": null,
+ "talk": [
+ "org.freedesktop.Notifications",
+ "org.freedesktop.FileManager1",
+ "org.freedesktop.ScreenSaver",
+ "org.freedesktop.secrets",
+ "org.kde.kwalletd5",
+ "org.kde.kwalletd6",
+ "org.gnome.SessionManager"
+ ],
+ "own": [
+ "org.chromium.Chromium.*",
+ "org.mpris.MediaPlayer2.org.chromium.Chromium.*",
+ "org.mpris.MediaPlayer2.chromium.*"
+ ],
+ "call": {
+ "org.freedesktop.portal.*": "*"
},
- "session_bus": {
- "see": null,
- "talk": [
- "org.freedesktop.Notifications",
- "org.freedesktop.FileManager1",
- "org.freedesktop.ScreenSaver",
- "org.freedesktop.secrets",
- "org.kde.kwalletd5",
- "org.kde.kwalletd6",
- "org.gnome.SessionManager"
- ],
- "own": [
- "org.chromium.Chromium.*",
- "org.mpris.MediaPlayer2.org.chromium.Chromium.*",
- "org.mpris.MediaPlayer2.chromium.*"
- ],
- "call": {
- "org.freedesktop.portal.*": "*"
- },
- "broadcast": {
- "org.freedesktop.portal.*": "@/org/freedesktop/portal/*"
- },
- "filter": true
+ "broadcast": {
+ "org.freedesktop.portal.*": "@/org/freedesktop/portal/*"
},
- "system_bus": {
- "see": null,
- "talk": [
- "org.bluez",
- "org.freedesktop.Avahi",
- "org.freedesktop.UPower"
- ],
- "own": null,
- "call": null,
- "broadcast": null,
- "filter": true
+ "filter": true
+ },
+ "system_bus": {
+ "see": null,
+ "talk": [
+ "org.bluez",
+ "org.freedesktop.Avahi",
+ "org.freedesktop.UPower"
+ ],
+ "own": null,
+ "call": null,
+ "broadcast": null,
+ "filter": true
+ },
+ "extra_perms": [
+ {
+ "ensure": true,
+ "path": "/var/lib/hakurei/u0",
+ "x": true
},
- "extra_perms": [
+ {
+ "path": "/var/lib/hakurei/u0/org.chromium.Chromium",
+ "r": true,
+ "w": true,
+ "x": true
+ }
+ ],
+ "identity": 9,
+ "groups": [
+ "video",
+ "dialout",
+ "plugdev"
+ ],
+ "container": {
+ "hostname": "localhost",
+ "wait_delay": -1,
+ "env": {
+ "GOOGLE_API_KEY": "AIzaSyBHDrl33hwRp4rMQY0ziRbj8K9LPA6vUCY",
+ "GOOGLE_DEFAULT_CLIENT_ID": "77185425430.apps.googleusercontent.com",
+ "GOOGLE_DEFAULT_CLIENT_SECRET": "OTJgUOQcT7lO7GsGZq2G4IlT"
+ },
+ "filesystem": [
{
- "ensure": true,
- "path": "/var/lib/hakurei/u0",
- "x": true
+ "type": "bind",
+ "dst": "/",
+ "src": "/var/lib/hakurei/base/org.debian",
+ "write": true,
+ "special": true
},
{
- "path": "/var/lib/hakurei/u0/org.chromium.Chromium",
- "r": true,
- "w": true,
- "x": true
+ "type": "bind",
+ "dst": "/etc/",
+ "src": "/etc/",
+ "special": true
+ },
+ {
+ "type": "ephemeral",
+ "dst": "/tmp/",
+ "write": true,
+ "perm": 493
+ },
+ {
+ "type": "overlay",
+ "dst": "/nix/store",
+ "lower": [
+ "/var/lib/hakurei/base/org.nixos/ro-store"
+ ],
+ "upper": "/var/lib/hakurei/nix/u0/org.chromium.Chromium/rw-store/upper",
+ "work": "/var/lib/hakurei/nix/u0/org.chromium.Chromium/rw-store/work"
+ },
+ {
+ "type": "link",
+ "dst": "/run/current-system",
+ "linkname": "/run/current-system",
+ "dereference": true
+ },
+ {
+ "type": "link",
+ "dst": "/run/opengl-driver",
+ "linkname": "/run/opengl-driver",
+ "dereference": true
+ },
+ {
+ "type": "bind",
+ "dst": "/data/data/org.chromium.Chromium",
+ "src": "/var/lib/hakurei/u0/org.chromium.Chromium",
+ "write": true,
+ "ensure": true
+ },
+ {
+ "type": "bind",
+ "src": "/dev/dri",
+ "dev": true,
+ "optional": true
}
],
- "identity": 9,
- "groups": [
- "video",
- "dialout",
- "plugdev"
+ "username": "chronos",
+ "shell": "/run/current-system/sw/bin/zsh",
+ "home": "/data/data/org.chromium.Chromium",
+ "path": "/run/current-system/sw/bin/chromium",
+ "args": [
+ "chromium",
+ "--ignore-gpu-blocklist",
+ "--disable-smooth-scrolling",
+ "--enable-features=UseOzonePlatform",
+ "--ozone-platform=wayland"
],
- "container": {
- "hostname": "localhost",
- "wait_delay": -1,
- "env": {
- "GOOGLE_API_KEY": "AIzaSyBHDrl33hwRp4rMQY0ziRbj8K9LPA6vUCY",
- "GOOGLE_DEFAULT_CLIENT_ID": "77185425430.apps.googleusercontent.com",
- "GOOGLE_DEFAULT_CLIENT_SECRET": "OTJgUOQcT7lO7GsGZq2G4IlT"
- },
- "filesystem": [
- {
- "type": "bind",
- "dst": "/",
- "src": "/var/lib/hakurei/base/org.debian",
- "write": true,
- "special": true
- },
- {
- "type": "bind",
- "dst": "/etc/",
- "src": "/etc/",
- "special": true
- },
- {
- "type": "ephemeral",
- "dst": "/tmp/",
- "write": true,
- "perm": 493
- },
- {
- "type": "overlay",
- "dst": "/nix/store",
- "lower": [
- "/var/lib/hakurei/base/org.nixos/ro-store"
- ],
- "upper": "/var/lib/hakurei/nix/u0/org.chromium.Chromium/rw-store/upper",
- "work": "/var/lib/hakurei/nix/u0/org.chromium.Chromium/rw-store/work"
- },
- {
- "type": "link",
- "dst": "/run/current-system",
- "linkname": "/run/current-system",
- "dereference": true
- },
- {
- "type": "link",
- "dst": "/run/opengl-driver",
- "linkname": "/run/opengl-driver",
- "dereference": true
- },
- {
- "type": "bind",
- "dst": "/data/data/org.chromium.Chromium",
- "src": "/var/lib/hakurei/u0/org.chromium.Chromium",
- "write": true,
- "ensure": true
- },
- {
- "type": "bind",
- "src": "/dev/dri",
- "dev": true,
- "optional": true
- }
- ],
- "username": "chronos",
- "shell": "/run/current-system/sw/bin/zsh",
- "home": "/data/data/org.chromium.Chromium",
- "path": "/run/current-system/sw/bin/chromium",
- "args": [
- "chromium",
- "--ignore-gpu-blocklist",
- "--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,
- "share_runtime": true,
- "share_tmpdir": true
- }
+ "seccomp_compat": true,
+ "devel": true,
+ "userns": true,
+ "host_net": true,
+ "host_abstract": true,
+ "tty": true,
+ "multiarch": true,
+ "map_real_uid": true,
+ "device": true,
+ "share_runtime": true,
+ "share_tmpdir": true
},
"time": "1970-01-01T00:00:00.000000009Z"
}
@@ -537,154 +535,152 @@ func TestPrintPs(t *testing.T) {
"instance": "8e2c76b066dabe574cf073bdb46eb5c1",
"pid": 3405691582,
"shim_pid": 3735928559,
- "config": {
- "id": "org.chromium.Chromium",
- "enablements": {
- "wayland": true,
- "dbus": true,
- "pulse": true
+ "id": "org.chromium.Chromium",
+ "enablements": {
+ "wayland": true,
+ "dbus": true,
+ "pulse": true
+ },
+ "session_bus": {
+ "see": null,
+ "talk": [
+ "org.freedesktop.Notifications",
+ "org.freedesktop.FileManager1",
+ "org.freedesktop.ScreenSaver",
+ "org.freedesktop.secrets",
+ "org.kde.kwalletd5",
+ "org.kde.kwalletd6",
+ "org.gnome.SessionManager"
+ ],
+ "own": [
+ "org.chromium.Chromium.*",
+ "org.mpris.MediaPlayer2.org.chromium.Chromium.*",
+ "org.mpris.MediaPlayer2.chromium.*"
+ ],
+ "call": {
+ "org.freedesktop.portal.*": "*"
},
- "session_bus": {
- "see": null,
- "talk": [
- "org.freedesktop.Notifications",
- "org.freedesktop.FileManager1",
- "org.freedesktop.ScreenSaver",
- "org.freedesktop.secrets",
- "org.kde.kwalletd5",
- "org.kde.kwalletd6",
- "org.gnome.SessionManager"
- ],
- "own": [
- "org.chromium.Chromium.*",
- "org.mpris.MediaPlayer2.org.chromium.Chromium.*",
- "org.mpris.MediaPlayer2.chromium.*"
- ],
- "call": {
- "org.freedesktop.portal.*": "*"
- },
- "broadcast": {
- "org.freedesktop.portal.*": "@/org/freedesktop/portal/*"
- },
- "filter": true
+ "broadcast": {
+ "org.freedesktop.portal.*": "@/org/freedesktop/portal/*"
},
- "system_bus": {
- "see": null,
- "talk": [
- "org.bluez",
- "org.freedesktop.Avahi",
- "org.freedesktop.UPower"
- ],
- "own": null,
- "call": null,
- "broadcast": null,
- "filter": true
+ "filter": true
+ },
+ "system_bus": {
+ "see": null,
+ "talk": [
+ "org.bluez",
+ "org.freedesktop.Avahi",
+ "org.freedesktop.UPower"
+ ],
+ "own": null,
+ "call": null,
+ "broadcast": null,
+ "filter": true
+ },
+ "extra_perms": [
+ {
+ "ensure": true,
+ "path": "/var/lib/hakurei/u0",
+ "x": true
},
- "extra_perms": [
+ {
+ "path": "/var/lib/hakurei/u0/org.chromium.Chromium",
+ "r": true,
+ "w": true,
+ "x": true
+ }
+ ],
+ "identity": 9,
+ "groups": [
+ "video",
+ "dialout",
+ "plugdev"
+ ],
+ "container": {
+ "hostname": "localhost",
+ "wait_delay": -1,
+ "env": {
+ "GOOGLE_API_KEY": "AIzaSyBHDrl33hwRp4rMQY0ziRbj8K9LPA6vUCY",
+ "GOOGLE_DEFAULT_CLIENT_ID": "77185425430.apps.googleusercontent.com",
+ "GOOGLE_DEFAULT_CLIENT_SECRET": "OTJgUOQcT7lO7GsGZq2G4IlT"
+ },
+ "filesystem": [
+ {
+ "type": "bind",
+ "dst": "/",
+ "src": "/var/lib/hakurei/base/org.debian",
+ "write": true,
+ "special": true
+ },
+ {
+ "type": "bind",
+ "dst": "/etc/",
+ "src": "/etc/",
+ "special": true
+ },
{
- "ensure": true,
- "path": "/var/lib/hakurei/u0",
- "x": true
+ "type": "ephemeral",
+ "dst": "/tmp/",
+ "write": true,
+ "perm": 493
},
{
- "path": "/var/lib/hakurei/u0/org.chromium.Chromium",
- "r": true,
- "w": true,
- "x": true
+ "type": "overlay",
+ "dst": "/nix/store",
+ "lower": [
+ "/var/lib/hakurei/base/org.nixos/ro-store"
+ ],
+ "upper": "/var/lib/hakurei/nix/u0/org.chromium.Chromium/rw-store/upper",
+ "work": "/var/lib/hakurei/nix/u0/org.chromium.Chromium/rw-store/work"
+ },
+ {
+ "type": "link",
+ "dst": "/run/current-system",
+ "linkname": "/run/current-system",
+ "dereference": true
+ },
+ {
+ "type": "link",
+ "dst": "/run/opengl-driver",
+ "linkname": "/run/opengl-driver",
+ "dereference": true
+ },
+ {
+ "type": "bind",
+ "dst": "/data/data/org.chromium.Chromium",
+ "src": "/var/lib/hakurei/u0/org.chromium.Chromium",
+ "write": true,
+ "ensure": true
+ },
+ {
+ "type": "bind",
+ "src": "/dev/dri",
+ "dev": true,
+ "optional": true
}
],
- "identity": 9,
- "groups": [
- "video",
- "dialout",
- "plugdev"
+ "username": "chronos",
+ "shell": "/run/current-system/sw/bin/zsh",
+ "home": "/data/data/org.chromium.Chromium",
+ "path": "/run/current-system/sw/bin/chromium",
+ "args": [
+ "chromium",
+ "--ignore-gpu-blocklist",
+ "--disable-smooth-scrolling",
+ "--enable-features=UseOzonePlatform",
+ "--ozone-platform=wayland"
],
- "container": {
- "hostname": "localhost",
- "wait_delay": -1,
- "env": {
- "GOOGLE_API_KEY": "AIzaSyBHDrl33hwRp4rMQY0ziRbj8K9LPA6vUCY",
- "GOOGLE_DEFAULT_CLIENT_ID": "77185425430.apps.googleusercontent.com",
- "GOOGLE_DEFAULT_CLIENT_SECRET": "OTJgUOQcT7lO7GsGZq2G4IlT"
- },
- "filesystem": [
- {
- "type": "bind",
- "dst": "/",
- "src": "/var/lib/hakurei/base/org.debian",
- "write": true,
- "special": true
- },
- {
- "type": "bind",
- "dst": "/etc/",
- "src": "/etc/",
- "special": true
- },
- {
- "type": "ephemeral",
- "dst": "/tmp/",
- "write": true,
- "perm": 493
- },
- {
- "type": "overlay",
- "dst": "/nix/store",
- "lower": [
- "/var/lib/hakurei/base/org.nixos/ro-store"
- ],
- "upper": "/var/lib/hakurei/nix/u0/org.chromium.Chromium/rw-store/upper",
- "work": "/var/lib/hakurei/nix/u0/org.chromium.Chromium/rw-store/work"
- },
- {
- "type": "link",
- "dst": "/run/current-system",
- "linkname": "/run/current-system",
- "dereference": true
- },
- {
- "type": "link",
- "dst": "/run/opengl-driver",
- "linkname": "/run/opengl-driver",
- "dereference": true
- },
- {
- "type": "bind",
- "dst": "/data/data/org.chromium.Chromium",
- "src": "/var/lib/hakurei/u0/org.chromium.Chromium",
- "write": true,
- "ensure": true
- },
- {
- "type": "bind",
- "src": "/dev/dri",
- "dev": true,
- "optional": true
- }
- ],
- "username": "chronos",
- "shell": "/run/current-system/sw/bin/zsh",
- "home": "/data/data/org.chromium.Chromium",
- "path": "/run/current-system/sw/bin/chromium",
- "args": [
- "chromium",
- "--ignore-gpu-blocklist",
- "--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,
- "share_runtime": true,
- "share_tmpdir": true
- }
+ "seccomp_compat": true,
+ "devel": true,
+ "userns": true,
+ "host_net": true,
+ "host_abstract": true,
+ "tty": true,
+ "multiarch": true,
+ "map_real_uid": true,
+ "device": true,
+ "share_runtime": true,
+ "share_tmpdir": true
},
"time": "1970-01-01T00:00:00.000000009Z"
}
diff --git a/cmd/hpkg/test/test.py b/cmd/hpkg/test/test.py
index e2a002d6..6f16729d 100644
--- a/cmd/hpkg/test/test.py
+++ b/cmd/hpkg/test/test.py
@@ -60,13 +60,11 @@ def check_state(name, enablements):
raise Exception(f"unexpected state length {len(instances)}")
instance = next(iter(instances.values()))
- config = instance['config']
+ if len(instance['container']['args']) != 1 or not (instance['container']['args'][0].startswith("/nix/store/")) or f"hakurei-{name}-" not in (instance['container']['args'][0]):
+ raise Exception(f"unexpected args {instance['container']['args']}")
- if len(config['container']['args']) != 1 or not (config['container']['args'][0].startswith("/nix/store/")) or f"hakurei-{name}-" not in (config['container']['args'][0]):
- raise Exception(f"unexpected args {config['container']['args']}")
-
- if config['enablements'] != enablements:
- raise Exception(f"unexpected enablements {config['enablements']}")
+ if instance['enablements'] != enablements:
+ raise Exception(f"unexpected enablements {instance['enablements']}")
start_all()
diff --git a/hst/instance.go b/hst/instance.go
index e2ad5a57..b59a7684 100644
--- a/hst/instance.go
+++ b/hst/instance.go
@@ -80,7 +80,7 @@ type State struct {
ShimPID int `json:"shim_pid"`
// Configuration used to start the container.
- Config *Config `json:"config"`
+ *Config
// Point in time the shim process was created.
Time time.Time `json:"time"`
diff --git a/test/test.py b/test/test.py
index 3c36c61e..cfc2f843 100644
--- a/test/test.py
+++ b/test/test.py
@@ -58,17 +58,15 @@ def check_state(name, enablements):
raise Exception(f"unexpected state length {len(instances)}")
instance = next(iter(instances.values()))
- config = instance['config']
-
command = f"{name}-start"
- if not (config['container']['path'].startswith("/nix/store/")) or not (config['container']['path'].endswith(command)):
- raise Exception(f"unexpected path {config['path']}")
+ if not (instance['container']['path'].startswith("/nix/store/")) or not (instance['container']['path'].endswith(command)):
+ raise Exception(f"unexpected path {instance['path']}")
- if len(config['container']['args']) != 1 or config['container']['args'][0] != command:
- raise Exception(f"unexpected args {config['args']}")
+ if len(instance['container']['args']) != 1 or instance['container']['args'][0] != command:
+ raise Exception(f"unexpected args {instance['args']}")
- if config['enablements'] != enablements:
- raise Exception(f"unexpected enablements {config['enablements']['enablements']}")
+ if instance['enablements'] != enablements:
+ raise Exception(f"unexpected enablements {instance['enablements']['enablements']}")
def hakurei(command):