temporarily source udev rules from system config

This commit is contained in:
Mikaël Cluseau
2026-05-12 10:38:21 +02:00
parent b0e84f6aa8
commit 78aa9ba20d
+28 -4
View File
@@ -16,8 +16,10 @@ import (
"slices" "slices"
"strings" "strings"
"github.com/cavaliergopher/cpio"
"github.com/klauspost/compress/zstd" "github.com/klauspost/compress/zstd"
"novit.tech/direktil/pkg/base64"
"novit.tech/direktil/pkg/config" "novit.tech/direktil/pkg/config"
"novit.tech/direktil/pkg/cpiocat" "novit.tech/direktil/pkg/cpiocat"
"novit.tech/direktil/pkg/localconfig" "novit.tech/direktil/pkg/localconfig"
@@ -38,7 +40,7 @@ func renderBootstrapConfig(w http.ResponseWriter, ctx *renderContext) (err error
func buildInitrd(out io.Writer, ctx *renderContext) (err error) { func buildInitrd(out io.Writer, ctx *renderContext) (err error) {
_, cfg, err := ctx.Config() _, cfg, err := ctx.Config()
if err != nil { if err != nil {
return return fmt.Errorf("render config failed: %w", err)
} }
zout, err := zstd.NewWriter(out, zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(12))) zout, err := zstd.NewWriter(out, zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(12)))
@@ -51,10 +53,32 @@ func buildInitrd(out io.Writer, ctx *renderContext) (err error) {
// initrd // initrd
initrdPath, err := distFetch("initrd", ctx.Host.Initrd) initrdPath, err := distFetch("initrd", ctx.Host.Initrd)
if err != nil { if err != nil {
return return fmt.Errorf("fetch initrd failed: %w", err)
} }
cat.AppendArchFile(initrdPath) cat.AppendArchFile(initrdPath)
// copy config's udev rules (FIXME: too much logic for dls)
for _, file := range cfg.Files {
if !strings.HasPrefix(file.Path, "/etc/udev/rules.d/") {
continue
}
content := []byte(file.Content)
if c := file.Content64; c != "" {
content, err = base64.Decode(c)
if err != nil {
return fmt.Errorf("decode %s failed: %w", file.Path, err)
}
}
mode := file.Mode
if mode == 0 {
mode = 0o644
}
cat.AppendBytes(content, file.Path, cpio.FileMode(mode))
}
// embedded layers (modules) // embedded layers (modules)
for _, layer := range cfg.Layers { for _, layer := range cfg.Layers {
switch layer { switch layer {
@@ -65,7 +89,7 @@ func buildInitrd(out io.Writer, ctx *renderContext) (err error) {
} }
modulesPath, err := distFetch("layers", layer, layerVersion) modulesPath, err := distFetch("layers", layer, layerVersion)
if err != nil { if err != nil {
return err return fmt.Errorf("fetch layer %s failed: %w", layer, err)
} }
cat.AppendFile(modulesPath, "modules.sqfs") cat.AppendFile(modulesPath, "modules.sqfs")
@@ -75,7 +99,7 @@ func buildInitrd(out io.Writer, ctx *renderContext) (err error) {
// config // config
cfgBytes, err := ctx.BootstrapConfig() cfgBytes, err := ctx.BootstrapConfig()
if err != nil { if err != nil {
return return fmt.Errorf("render bootstrap config failed: %w", err)
} }
cat.AppendBytes(cfgBytes, "config.yaml", 0o600) cat.AppendBytes(cfgBytes, "config.yaml", 0o600)