internal/rosa/package: migrate hakurei
All checks were successful
Test / Create distribution (push) Successful in 1m4s
Test / Sandbox (push) Successful in 2m47s
Test / ShareFS (push) Successful in 3m42s
Test / Hakurei (push) Successful in 4m0s
Test / Sandbox (race detector) (push) Successful in 5m24s
Test / Hakurei (race detector) (push) Successful in 6m29s
Test / Flake checks (push) Successful in 1m36s

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-05-22 00:07:25 +09:00
parent 2a9aa3b400
commit f3a6f7ddf9
7 changed files with 235 additions and 190 deletions

View File

@@ -1,121 +0,0 @@
package rosa
import "hakurei.app/internal/pkg"
func (t Toolchain) newHakurei(
suffix, build, check, install string,
withHostname bool,
) pkg.Artifact {
hostname := `
echo 'Building test helper (hostname).'
go build -o /bin/hostname /usr/src/hostname/main.go
`
if !withHostname {
hostname = ""
}
name := "hakurei" + suffix
return t.NewPackage(name, hakureiVersion, t.NewPatchedSource(
"hakurei-"+hakureiVersion, hakureiSource, false, hakureiPatches...,
), &PackageAttr{
EnterSource: true,
Writable: true,
Env: []string{
"CGO_ENABLED=1",
"GOCACHE=/tmp/gocache",
"CC=clang -O3 -Werror",
},
Paths: []pkg.ExecPath{pkg.Path(AbsUsrSrc.Append("hostname", "main.go"), false, pkg.NewFile(
"hostname.go",
[]byte(`
package main
import "os"
func main() {
if name, err := os.Hostname(); err != nil {
panic(err)
} else {
os.Stdout.WriteString(name)
}
}
`),
))},
}, &GenericHelper{
InPlace: true,
Build: hostname + `
HAKUREI_VERSION='v` + hakureiVersion + `'
` + build,
Check: check,
Install: install,
},
_go,
H("pkg-config"),
H("libseccomp"),
H("acl"),
H("fuse"),
H("xcb"),
H("wayland"),
H("wayland-protocols"),
_kernelHeaders,
)
}
func init() {
meta := Metadata{
Name: "hakurei",
Description: "low-level userspace tooling for Rosa OS",
Website: "https://hakurei.app",
Version: hakureiVersion,
ID: 388834,
}
native.MustRegister(meta.Name, func(t Toolchain) (*Metadata, pkg.Artifact) {
return &meta, t.newHakurei("", `
mkdir -p /work/system/libexec/hakurei/
echo "Building hakurei for $(go env GOOS)/$(go env GOARCH)."
go generate ./...
go build -trimpath -tags=rosa -o /work/system/libexec/hakurei -ldflags="-s -w
-buildid=
-linkmode external
-extldflags=-static
-X hakurei.app/internal/info.buildVersion=${HAKUREI_VERSION}
-X hakurei.app/internal/info.hakureiPath=/system/bin/hakurei
-X hakurei.app/internal/info.hsuPath=/system/bin/hsu
-X main.hakureiPath=/system/bin/hakurei
" ./...
echo
`, `
echo '##### Testing hakurei.'
go test -ldflags='-buildid= -linkmode external -extldflags=-static' ./...
echo
`, `
mkdir -p /work/system/bin/
(cd /work/system/libexec/hakurei && mv \
hakurei \
sharefs \
../../bin/)
`, true)
})
}
func init() {
meta := Metadata{
Name: "hakurei-dist",
Description: "low-level userspace tooling for Rosa OS (distribution tarball)",
Website: "https://hakurei.app",
Version: hakureiVersion,
}
native.MustRegister(meta.Name, func(t Toolchain) (*Metadata, pkg.Artifact) {
name := "all"
if t.opts&OptSkipCheck != 0 {
name = "make"
}
return &meta, t.newHakurei("-dist", `
export HAKUREI_VERSION
DESTDIR=/work ./`+name+`.sh
`, "", "", true)
})
}

View File

@@ -1,26 +0,0 @@
//go:build current
package rosa
import (
_ "embed"
"hakurei.app/internal/pkg"
)
const hakureiVersion = "1.0-current"
// hakureiSourceTarball is a compressed tarball of the hakurei source code.
//
//go:generate tar -zc -C ../.. --exclude .git --exclude *.tar.gz -f hakurei_current.tar.gz .
//go:embed hakurei_current.tar.gz
var hakureiSourceTarball []byte
// hakureiSource is the source code at the time this package is compiled.
var hakureiSource = pkg.NewTar(pkg.NewFile(
"hakurei-current.tar.gz",
hakureiSourceTarball,
), pkg.TarGzip)
// hakureiPatches are patches applied against the compile-time source tree.
var hakureiPatches []KV

View File

@@ -1,18 +0,0 @@
//go:build !current
package rosa
import "hakurei.app/internal/pkg"
const hakureiVersion = "0.4.2"
// hakureiSource is the source code of a hakurei release.
var hakureiSource = newTar(
"https://git.gensokyo.uk/rosa/hakurei/archive/"+
"v"+hakureiVersion+".tar.gz",
"jadgaOrxv5ABGvzQ_Rk0aPGz7U8K-427TbMhQNQ32scSizEnlR44Pu7NoWYWVZWq",
pkg.TarGzip,
)
// hakureiPatches are patches applied against a hakurei release.
var hakureiPatches []KV

View File

@@ -5,30 +5,6 @@ import (
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
) )
var _earlyInit = H("earlyinit")
func init() {
meta := Metadata{
Name: "earlyinit",
Description: "Rosa OS initramfs init program",
Version: Unversioned,
}
native.MustRegister(meta.Name, func(t Toolchain) (*Metadata, pkg.Artifact) {
return &meta, t.newHakurei("-early-init", `
mkdir -p /work/system/libexec/hakurei/
echo '# Building earlyinit.'
go build -trimpath -v -o /work/system/libexec/hakurei -ldflags="-s -w
-buildid=
-linkmode external
-extldflags=-static
-X hakurei.app/internal/info.buildVersion=${HAKUREI_VERSION}
" ./cmd/earlyinit
echo
`, "", "", false)
})
}
func init() { func init() {
meta := Metadata{ meta := Metadata{
Name: "system-image", Name: "system-image",
@@ -61,7 +37,7 @@ func init() {
native.MustRegister(meta.Name, func(t Toolchain) (*Metadata, pkg.Artifact) { native.MustRegister(meta.Name, func(t Toolchain) (*Metadata, pkg.Artifact) {
return &meta, t.New("initramfs", TNoToolchain, t.Append(nil, return &meta, t.New("initramfs", TNoToolchain, t.Append(nil,
_zstd, _zstd,
_earlyInit, H("earlyinit"),
H("gen_init_cpio"), H("gen_init_cpio"),
), nil, nil, ` ), nil, nil, `
gen_init_cpio -t 4294967295 -c /usr/src/initramfs | zstd > /work/initramfs.zst gen_init_cpio -t 4294967295 -c /usr/src/initramfs | zstd > /work/initramfs.zst

View File

@@ -0,0 +1,61 @@
From 2a9aa3b4007a73a6c9d4608cb9a8822247881fd6 Mon Sep 17 00:00:00 2001
From: Ophestra <cat@gensokyo.uk>
Date: Thu, 21 May 2026 23:34:50 +0900
Subject: [PATCH] cmd/dist: include version in release
This makes HAKUREI_VERSION optional during build.
Signed-off-by: Ophestra <cat@gensokyo.uk>
---
cmd/dist/VERSION | 1 +
cmd/dist/main.go | 7 ++++++-
flake.nix | 1 -
3 files changed, 7 insertions(+), 2 deletions(-)
create mode 100644 cmd/dist/VERSION
diff --git a/cmd/dist/VERSION b/cmd/dist/VERSION
new file mode 100644
index 00000000..0eec13e4
--- /dev/null
+++ b/cmd/dist/VERSION
@@ -0,0 +1 @@
+v0.4.2
diff --git a/cmd/dist/main.go b/cmd/dist/main.go
index 9ed7f2f8..d876cf83 100644
--- a/cmd/dist/main.go
+++ b/cmd/dist/main.go
@@ -18,8 +18,13 @@ import (
"os/signal"
"path/filepath"
"runtime"
+ "strings"
)
+//go:generate sh -c "git describe --tags > VERSION"
+//go:embed VERSION
+var version string
+
// getenv looks up an environment variable, and returns fallback if it is unset.
func getenv(key, fallback string) string {
if v, ok := os.LookupEnv(key); ok {
@@ -47,7 +52,7 @@ func main() {
verbose := os.Getenv("VERBOSE") != ""
runTests := os.Getenv("HAKUREI_DIST_MAKE") == ""
- version := getenv("HAKUREI_VERSION", "untagged")
+ version = getenv("HAKUREI_VERSION", strings.TrimSpace(version))
prefix := getenv("PREFIX", "/usr")
destdir := getenv("DESTDIR", "dist")
diff --git a/flake.nix b/flake.nix
index 4de35204..09520be2 100644
--- a/flake.nix
+++ b/flake.nix
@@ -139,7 +139,6 @@
GOCACHE="$(mktemp -d)" \
PATH="${pkgs.pkgsStatic.musl.bin}/bin:$PATH" \
DESTDIR="$out" \
- HAKUREI_VERSION="v${hakurei.version}" \
./all.sh
'';
}

View File

@@ -0,0 +1,11 @@
package main
import "os"
func main() {
if name, err := os.Hostname(); err != nil {
panic(err)
} else {
os.Stdout.WriteString(name)
}
}

View File

@@ -0,0 +1,162 @@
package hakurei-source {
description = "hakurei source tree";
exclude = true;
version* = "0.4.2";
output = remoteTar {
url = "https://git.gensokyo.uk/rosa/hakurei/archive/"+
"v"+version+".tar.gz";
checksum = "jadgaOrxv5ABGvzQ_Rk0aPGz7U8K-427TbMhQNQ32scSizEnlR44Pu7NoWYWVZWq";
compress = gzip;
};
}
package hakurei {
description = "low-level userspace tooling for Rosa OS";
website = "https://hakurei.app";
anitya = 388834;
source = hakurei-source;
patches = [ "2a9aa3b4007a73a6c9d4608cb9a8822247881fd6.patch" ];
enterSource = true;
writable = true;
chmod = true;
env = [
"CGO_ENABLED=1",
"GOCACHE=/tmp/gocache",
"CC=clang -O3 -Werror",
];
files = {
"hostname/main.go": "hostname";
};
exec = generic {
inPlace = true;
build = `
echo 'Building test helper (hostname).'
go build -o /bin/hostname /usr/src/hostname/main.go
mkdir -p /work/system/libexec/hakurei/
echo "Building hakurei for $(go env GOOS)/$(go env GOARCH)."
go generate ./...
go build -trimpath -tags=rosa -o /work/system/libexec/hakurei -ldflags="-s -w
-buildid=
-linkmode external
-extldflags=-static
-X hakurei.app/internal/info.buildVersion=$(cat cmd/dist/VERSION)
-X hakurei.app/internal/info.hakureiPath=/system/bin/hakurei
-X hakurei.app/internal/info.hsuPath=/system/bin/hsu
-X main.hakureiPath=/system/bin/hakurei
" ./...
echo`;
check = `
echo '##### Testing hakurei.'
go test -ldflags='-buildid= -linkmode external -extldflags=-static' ./...
echo`;
install = `
mkdir -p /work/system/bin/
(cd /work/system/libexec/hakurei && mv \
hakurei \
sharefs \
../../bin/)
`;
};
inputs = [
go,
pkg-config,
libseccomp,
acl,
fuse,
xcb,
wayland,
wayland-protocols,
kernel-headers,
];
}
package hakurei-dist {
description = "low-level userspace tooling for Rosa OS (distribution tarball)";
website = "https://hakurei.app";
source = hakurei-source;
patches = [ "2a9aa3b4007a73a6c9d4608cb9a8822247881fd6.patch" ];
enterSource = true;
writable = true;
chmod = true;
env = [
"CGO_ENABLED=1",
"GOCACHE=/tmp/gocache",
"CC=clang -O3 -Werror",
];
files = {
"hostname/main.go": "hostname";
};
exec = generic {
inPlace = true;
build = `
echo 'Building test helper (hostname).'
go build -o /bin/hostname /usr/src/hostname/main.go
NAME=make`;
check = `
NAME=all`;
install = `
DESTDIR=/work "./${NAME}.sh"
`;
};
inputs = [
go,
pkg-config,
libseccomp,
acl,
fuse,
xcb,
wayland,
wayland-protocols,
kernel-headers,
];
}
package earlyinit {
description = "Rosa OS initramfs init program";
exclude = true;
source = hakurei-source;
patches = [ "2a9aa3b4007a73a6c9d4608cb9a8822247881fd6.patch" ];
enterSource = true;
writable = true;
chmod = true;
env = [
"CGO_ENABLED=1",
"GOCACHE=/tmp/gocache",
"CC=clang -O3 -Werror",
];
exec = generic {
inPlace = true;
build = `
mkdir -p /work/system/libexec/hakurei/
echo '# Building earlyinit.'
go build -trimpath -v -o /work/system/libexec/hakurei -ldflags="-s -w
-buildid=
-linkmode external
-extldflags=-static
-X hakurei.app/internal/info.buildVersion=$(cat cmd/dist/VERSION)
" ./cmd/earlyinit
echo`;
};
inputs = [ go ];
}