Feature 57 (config and provisioning): modules declare config and provisions, their files rendered from templates; synced with main (issues of feature 57, 874)

This commit is contained in:
2026-10-16 07:37:43 +00:00
parent 1a2c917abf
commit 9652b2d5ce
771 changed files with 52063 additions and 1774 deletions
@@ -0,0 +1,64 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"testing"
)
// The module's directory, where its manifest and its files/ are.
const moduleDir = "../.."
// templateText is the text a file resource places on the machine: its template's, in the module's files/
// (novox/hq ADR 0349 §2). A resource that names no template, or a template that is not there, fails the test.
func templateText(t *testing.T, r map[string]any) string {
t.Helper()
name, _ := r["template"].(string)
if name == "" {
t.Fatalf("resource %v names no template", r["id"])
}
raw, err := os.ReadFile(filepath.Join(moduleDir, filepath.FromSlash(name)))
if err != nil {
t.Fatalf("resource %v names %s: %v", r["id"], name, err)
}
return string(raw)
}
// No file resource carries its text inline: each names its template in files/, and the build packs files/
// into the one archive the controller reads the templates back from (novox/hq ADR 0349 §2).
func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
raw, err := os.ReadFile(filepath.Join(moduleDir, "module.json"))
if err != nil {
t.Fatal(err)
}
var m struct {
Resources []map[string]any `json:"resources"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
for _, r := range m.Resources {
if _, inline := r["content"]; inline {
t.Errorf("resource %v keeps its text inline: keep it in files/ and name it as the template", r["id"])
}
if r["type"] == "file" {
templateText(t, r)
}
}
packs := 0
for _, a := range m.Build.Artifacts {
if a["kind"] == "archive" && a["from"] == "files" {
packs++
if a["name"] != "files" {
t.Errorf("the templates archive is named %v, not files", a["name"])
}
}
}
if packs != 1 {
t.Errorf("the build packs files/ into %d archives, not one", packs)
}
}
+8
View File
@@ -0,0 +1,8 @@
# Written by the mesh (module triggerhappy, novox/hq ADR 0212). Replaced on every push.
#
# The daemon opens the input devices as root, then drops to the operator's account with its groups,
# so every trigger runs as the account: it reaches the account's session bus and display, with no su
# and no hard-coded user. Only the mesh's trigger file is read.
[Service]
ExecStart=
ExecStart=/usr/bin/thd --triggers /etc/triggerhappy/triggers.d/mesh.conf --socket /run/thd.socket --user ${machine:account} --deviceglob /dev/input/event*
+4
View File
@@ -0,0 +1,4 @@
# The machine's hotkeys, written by the mesh (module triggerhappy, novox/hq ADR 0212). Replaced on
# every push: a key is added by the module it belongs to, as a contribution to node-hotkeys.
# A line is: the key, its state (1 pressed, 2 held, 0 released), the command.
${contribution:node-hotkeys:trigger}
+8 -2
View File
@@ -1,6 +1,7 @@
{
"module": "triggerhappy",
"version": "1",
"moved": true,
"capabilities": [
"service-manager"
],
@@ -28,7 +29,7 @@
"type": "file",
"path": "/etc/systemd/system/triggerhappy.service.d/mesh.conf",
"mode": "0644",
"content": "# Written by the mesh (module triggerhappy, novox/hq ADR 0212). Replaced on every push.\n#\n# The daemon opens the input devices as root, then drops to the operator's account with its groups,\n# so every trigger runs as the account: it reaches the account's session bus and display, with no su\n# and no hard-coded user. Only the mesh's trigger file is read.\n[Service]\nExecStart=\nExecStart=/usr/bin/thd --triggers /etc/triggerhappy/triggers.d/mesh.conf --socket /run/thd.socket --user ${machine:account} --deviceglob /dev/input/event*\n"
"template": "files/service.conf"
},
{
"id": "triggers-dir",
@@ -41,7 +42,7 @@
"type": "file",
"path": "/etc/triggerhappy/triggers.d/mesh.conf",
"mode": "0644",
"content": "# The machine's hotkeys, written by the mesh (module triggerhappy, novox/hq ADR 0212). Replaced on\n# every push: a key is added by the module it belongs to, as a contribution to node-hotkeys.\n# A line is: the key, its state (1 pressed, 2 held, 0 released), the command.\n${contribution:node-hotkeys:trigger}"
"template": "files/triggers.conf"
},
{
"id": "service",
@@ -67,6 +68,11 @@
"loads": [
"triggerhappy-tools"
]
},
{
"name": "files",
"kind": "archive",
"from": "files"
}
]
}