From c6be82bcf91fc4b6e61d9df40213e80367addbd8 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 3 Aug 2025 20:46:41 +0900 Subject: container/path: fhs path constants This increases readability since this can help disambiguate absolute paths from similarly named path segments. Signed-off-by: Ophestra --- cmd/hakurei/command.go | 3 ++- cmd/hakurei/print_test.go | 20 ++++++++++---------- cmd/hpkg/app.go | 19 ++++++++++--------- cmd/hpkg/main.go | 13 +++++++------ cmd/hpkg/paths.go | 3 ++- cmd/hpkg/with.go | 15 ++++++++------- 6 files changed, 39 insertions(+), 34 deletions(-) (limited to 'cmd') diff --git a/cmd/hakurei/command.go b/cmd/hakurei/command.go index bbe679fa..83749755 100644 --- a/cmd/hakurei/command.go +++ b/cmd/hakurei/command.go @@ -14,6 +14,7 @@ import ( "time" "hakurei.app/command" + "hakurei.app/container" "hakurei.app/hst" "hakurei.app/internal" "hakurei.app/internal/app" @@ -94,7 +95,7 @@ func buildCommand(out io.Writer) command.Command { Gid: us, Username: "chronos", Name: "Hakurei Permissive Default", - HomeDir: "/var/empty", + HomeDir: container.FHSVarEmpty, } } else { passwd = u diff --git a/cmd/hakurei/print_test.go b/cmd/hakurei/print_test.go index 0a4e91ba..4a79ba6b 100644 --- a/cmd/hakurei/print_test.go +++ b/cmd/hakurei/print_test.go @@ -43,12 +43,12 @@ func Test_printShowInstance(t *testing.T) { Hostname: localhost Flags: userns devel net device tty mapuid autoetc Root: /var/lib/hakurei/base/org.debian (2) - Etc: /etc + Etc: /etc/ Path: /run/current-system/sw/bin/chromium Arguments: chromium --ignore-gpu-blocklist --disable-smooth-scrolling --enable-features=UseOzonePlatform --ozone-platform=wayland Filesystem - w+tmpfs:/tmp + w+tmpfs:/tmp/ +/nix/store +/run/current-system +/run/opengl-driver @@ -123,12 +123,12 @@ App Hostname: localhost Flags: userns devel net device tty mapuid autoetc Root: /var/lib/hakurei/base/org.debian (2) - Etc: /etc + Etc: /etc/ Path: /run/current-system/sw/bin/chromium Arguments: chromium --ignore-gpu-blocklist --disable-smooth-scrolling --enable-features=UseOzonePlatform --ozone-platform=wayland Filesystem - w+tmpfs:/tmp + w+tmpfs:/tmp/ +/nix/store +/run/current-system +/run/opengl-driver @@ -276,7 +276,7 @@ App "device": true, "filesystem": [ { - "dst": "/tmp", + "dst": "/tmp/", "src": "tmpfs", "write": true }, @@ -311,7 +311,7 @@ App ], "auto_root": "/var/lib/hakurei/base/org.debian", "root_flags": 2, - "etc": "/etc", + "etc": "/etc/", "auto_etc": true } }, @@ -408,7 +408,7 @@ App "device": true, "filesystem": [ { - "dst": "/tmp", + "dst": "/tmp/", "src": "tmpfs", "write": true }, @@ -443,7 +443,7 @@ App ], "auto_root": "/var/lib/hakurei/base/org.debian", "root_flags": 2, - "etc": "/etc", + "etc": "/etc/", "auto_etc": true } } @@ -594,7 +594,7 @@ func Test_printPs(t *testing.T) { "device": true, "filesystem": [ { - "dst": "/tmp", + "dst": "/tmp/", "src": "tmpfs", "write": true }, @@ -629,7 +629,7 @@ func Test_printPs(t *testing.T) { ], "auto_root": "/var/lib/hakurei/base/org.debian", "root_flags": 2, - "etc": "/etc", + "etc": "/etc/", "auto_etc": true } }, diff --git a/cmd/hpkg/app.go b/cmd/hpkg/app.go index 082bc28e..fb784d73 100644 --- a/cmd/hpkg/app.go +++ b/cmd/hpkg/app.go @@ -6,6 +6,7 @@ import ( "os" "path" + "hakurei.app/container" "hakurei.app/container/seccomp" "hakurei.app/hst" "hakurei.app/system" @@ -94,17 +95,17 @@ func (app *appInfo) toFst(pathSet *appPathSet, argv []string, flagDropShell bool Filesystem: []*hst.FilesystemConfig{ {Src: path.Join(pathSet.nixPath, "store"), Dst: "/nix/store", Must: true}, {Src: pathSet.metaPath, Dst: path.Join(hst.Tmp, "app"), Must: true}, - {Src: "/etc/resolv.conf"}, - {Src: "/sys/block"}, - {Src: "/sys/bus"}, - {Src: "/sys/class"}, - {Src: "/sys/dev"}, - {Src: "/sys/devices"}, + {Src: container.FHSEtc + "resolv.conf"}, + {Src: container.FHSSys + "block"}, + {Src: container.FHSSys + "bus"}, + {Src: container.FHSSys + "class"}, + {Src: container.FHSSys + "dev"}, + {Src: container.FHSSys + "devices"}, }, Link: [][2]string{ - {app.CurrentSystem, "/run/current-system"}, - {"/run/current-system/sw/bin", "/bin"}, - {"/run/current-system/sw/bin", "/usr/bin"}, + {app.CurrentSystem, container.FHSRun + "current-system"}, + {container.FHSRun + "current-system/sw/bin", "/bin"}, + {container.FHSRun + "current-system/sw/bin", container.FHSUsrBin}, }, Etc: path.Join(pathSet.cacheDir, "etc"), AutoEtc: true, diff --git a/cmd/hpkg/main.go b/cmd/hpkg/main.go index d808aa01..728ee14e 100644 --- a/cmd/hpkg/main.go +++ b/cmd/hpkg/main.go @@ -11,6 +11,7 @@ import ( "syscall" "hakurei.app/command" + "hakurei.app/container" "hakurei.app/hst" "hakurei.app/internal" "hakurei.app/internal/hlog" @@ -275,12 +276,12 @@ func main() { "path:" + a.NixGL + "#nixVulkanNvidia", }, true, func(config *hst.Config) *hst.Config { config.Container.Filesystem = append(config.Container.Filesystem, []*hst.FilesystemConfig{ - {Src: "/etc/resolv.conf"}, - {Src: "/sys/block"}, - {Src: "/sys/bus"}, - {Src: "/sys/class"}, - {Src: "/sys/dev"}, - {Src: "/sys/devices"}, + {Src: container.FHSEtc + "resolv.conf"}, + {Src: container.FHSSys + "block"}, + {Src: container.FHSSys + "bus"}, + {Src: container.FHSSys + "class"}, + {Src: container.FHSSys + "dev"}, + {Src: container.FHSSys + "devices"}, }...) appendGPUFilesystem(config) return config diff --git a/cmd/hpkg/paths.go b/cmd/hpkg/paths.go index 11715fb2..b7cc926a 100644 --- a/cmd/hpkg/paths.go +++ b/cmd/hpkg/paths.go @@ -8,6 +8,7 @@ import ( "strconv" "sync/atomic" + "hakurei.app/container" "hakurei.app/hst" "hakurei.app/internal/hlog" ) @@ -21,7 +22,7 @@ func init() { if p, ok := os.LookupEnv("HAKUREI_DATA_HOME"); ok { dataHome = p } else { - dataHome = "/var/lib/hakurei/" + strconv.Itoa(os.Getuid()) + dataHome = container.FHSVarLib + "hakurei/" + strconv.Itoa(os.Getuid()) } } diff --git a/cmd/hpkg/with.go b/cmd/hpkg/with.go index 7d9fc7b8..444b4e7e 100644 --- a/cmd/hpkg/with.go +++ b/cmd/hpkg/with.go @@ -5,6 +5,7 @@ import ( "path" "strings" + "hakurei.app/container" "hakurei.app/container/seccomp" "hakurei.app/hst" "hakurei.app/internal" @@ -52,9 +53,9 @@ func withNixDaemon( {Src: pathSet.nixPath, Dst: "/nix", Write: true, Must: true}, }, Link: [][2]string{ - {app.CurrentSystem, "/run/current-system"}, - {"/run/current-system/sw/bin", "/bin"}, - {"/run/current-system/sw/bin", "/usr/bin"}, + {app.CurrentSystem, container.FHSRun + "current-system"}, + {container.FHSRun + "current-system/sw/bin", "/bin"}, + {container.FHSRun + "current-system/sw/bin", container.FHSUsrBin}, }, Etc: path.Join(pathSet.cacheDir, "etc"), AutoEtc: true, @@ -93,11 +94,11 @@ func withCacheDir( {Src: workDir, Dst: path.Join(hst.Tmp, "bundle"), Must: true}, }, Link: [][2]string{ - {app.CurrentSystem, "/run/current-system"}, - {"/run/current-system/sw/bin", "/bin"}, - {"/run/current-system/sw/bin", "/usr/bin"}, + {app.CurrentSystem, container.FHSRun + "current-system"}, + {container.FHSRun + "current-system/sw/bin", "/bin"}, + {container.FHSRun + "current-system/sw/bin", container.FHSUsrBin}, }, - Etc: path.Join(workDir, "etc"), + Etc: path.Join(workDir, container.FHSEtc), AutoEtc: true, }, }, dropShell, beforeFail) -- cgit v1.3.1