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:
@@ -41,7 +41,6 @@ The X display server as a module (novox/hq ADR 0208, research 026, to-be 42 phas
|
||||
|---|---|---|
|
||||
| `first` | `gnome-keyring` | `SSH_AUTH_SOCK` |
|
||||
| `normal` | `adwaita` | its GSettings keys |
|
||||
| `normal` | `clipmenu` | `clipmenud &` |
|
||||
| `normal` | `feh` | the wallpaper |
|
||||
| `normal` | `i3status-rust` | the bar watchdog |
|
||||
| `normal` | `screen-lock` | the timeouts and the `xss-lock` loop |
|
||||
|
||||
@@ -119,7 +119,7 @@ func TestItInstallsTheServerItsStartAndTheToolsItsVerbsRun(t *testing.T) {
|
||||
|
||||
func TestTheResourcesFileHoldsTheDefaultsAndTheThreeSlots(t *testing.T) {
|
||||
r := readManifest(t).resource(t, "xresources")
|
||||
c := r["content"].(string)
|
||||
c := templateText(t, r)
|
||||
if r["path"] != "${machine:account-home}/.config/xorg/xresources" || r["into"] != nil {
|
||||
t.Fatalf("an owned file: %v", r)
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func TestTheSessionStartIsABlockAtTheStartInTheOrderTheDecisionGives(t *testing.
|
||||
if r["path"] != "${machine:account-home}/.xinitrc" || r["into"] != "block" || r["at"] != "start" {
|
||||
t.Fatalf("%v", r)
|
||||
}
|
||||
c := r["content"].(string)
|
||||
c := templateText(t, r)
|
||||
order := []string{
|
||||
". \"${machine:account-home}/.config/mesh/environment.sh\"",
|
||||
"dbus-update-activation-environment --systemd $mesh_words",
|
||||
@@ -205,7 +205,7 @@ func TestTheBlockRunsTheEnvironmentTheImportTheResourcesTheSlotsAndEndsInTheSess
|
||||
for _, prog := range []string{"dbus-update-activation-environment", "xrdb", "autorandr", "the-session"} {
|
||||
os.WriteFile(filepath.Join(bin, prog), []byte("#!/bin/sh\necho \""+prog+" $*\" >> \""+log+"\"\n"), 0o755)
|
||||
}
|
||||
block := render(readManifest(t).resource(t, "xinitrc")["content"].(string), home, map[string]string{
|
||||
block := render(templateText(t, readManifest(t).resource(t, "xinitrc")), home, map[string]string{
|
||||
"normal": "echo normal >> \"" + log + "\"",
|
||||
"last": "exec the-session",
|
||||
})
|
||||
@@ -237,7 +237,8 @@ func TestTheBlockRunsTheEnvironmentTheImportTheResourcesTheSlotsAndEndsInTheSess
|
||||
|
||||
func TestTheBundleIsGoBuiltForArch(t *testing.T) {
|
||||
a := readManifest(t).Build.Artifacts
|
||||
if len(a) != 1 || a[0]["language"] != "go" || a[0]["system"] != "arch" || a[0]["from"] != "cmd/xorg" || a[0]["binary"] != "xorg" {
|
||||
// The bundle, and beside it the archive the build packs the templates in files/ into (novox/hq ADR 0349 §2).
|
||||
if len(a) != 2 || a[1]["name"] != "files" || a[0]["language"] != "go" || a[0]["system"] != "arch" || a[0]["from"] != "cmd/xorg" || a[0]["binary"] != "xorg" {
|
||||
t.Fatalf("%v", a)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
# The mesh's block (module xorg, novox/hq ADR 0208 §5): the graphical session's start, replaced at
|
||||
# every push. It ends by starting the session, so no line below it in this file runs any more. A line
|
||||
# of your own that must run at every session start goes in ~/.xinitrc.local, which this block sources
|
||||
# just before the session starts (the module's README lists where each of today's lines went).
|
||||
|
||||
# 1. The account's environment (ADR 0203): the file every shell sources, written by node-environment.
|
||||
if [ -r "${machine:account-home}/.config/mesh/environment.sh" ]; then
|
||||
. "${machine:account-home}/.config/mesh/environment.sh"
|
||||
fi
|
||||
|
||||
# The session bus is the user manager's. pam_systemd normally hands it over; when it did not, take
|
||||
# the canonical socket rather than starting a second bus, which runs every D-Bus-activated service
|
||||
# twice (two notifiers, two portals) and hides one copy from the other.
|
||||
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && [ -S "/run/user/$(id -u)/bus" ]; then
|
||||
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
|
||||
export DBUS_SESSION_BUS_ADDRESS
|
||||
fi
|
||||
|
||||
# 2. The session's own words into the user manager and D-Bus activation, so the portal, the notifier
|
||||
# and every user service see the display and the desktop's identity. An explicit list and never
|
||||
# --all: a session's environment may hold things no user service should be able to read back.
|
||||
mesh_words=
|
||||
for mesh_word in DISPLAY XAUTHORITY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP \
|
||||
XDG_CONFIG_HOME XDG_DATA_DIRS GTK_THEME GTK2_RC_FILES QT_QPA_PLATFORMTHEME QT_STYLE_OVERRIDE \
|
||||
QT_SELECT XCURSOR_THEME XCURSOR_SIZE TERMINAL; do
|
||||
if printenv "$mesh_word" >/dev/null 2>&1; then
|
||||
mesh_words="$mesh_words $mesh_word"
|
||||
fi
|
||||
done
|
||||
dbus-update-activation-environment --systemd $mesh_words
|
||||
unset mesh_word mesh_words
|
||||
|
||||
# 3. X resources: the mesh's, then yours in ~/.Xresources, which win. The mesh's file is merged
|
||||
# without the C preprocessor, so no compiler is needed for it.
|
||||
xrdb -nocpp -merge "${machine:account-home}/.config/xorg/xresources"
|
||||
if [ -r "$HOME/.Xresources" ]; then
|
||||
xrdb -merge "$HOME/.Xresources"
|
||||
fi
|
||||
|
||||
# 4. The monitors: the saved layout profile that matches the monitors connected, if one does.
|
||||
if command -v autorandr >/dev/null 2>&1; then
|
||||
autorandr --change >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
# 5. Other modules' session lines (ADR 0208 §4), then yours.
|
||||
${shell:xinitrc:first}${shell:xinitrc:normal}if [ -r "$HOME/.xinitrc.local" ]; then
|
||||
. "$HOME/.xinitrc.local"
|
||||
fi
|
||||
|
||||
# 6. The session itself: the holder of node-display-session starts it from the last slot.
|
||||
${shell:xinitrc:last}
|
||||
@@ -0,0 +1,13 @@
|
||||
! The mesh's X resources (module xorg, novox/hq ADR 0208 §4), replaced at every push. The session's
|
||||
! start merges them with xrdb -nocpp before ~/.Xresources, so your own resources there win. Without
|
||||
! the preprocessor there is no #include or #define here, and a line starting with # is skipped,
|
||||
! which is what the line naming each contributing module is.
|
||||
!
|
||||
! Font rendering, as both workstations had it. 96 DPI becomes a setting with issue 168; xorg_dpi
|
||||
! changes it for the running session.
|
||||
Xft.dpi: 96
|
||||
Xft.antialias: 1
|
||||
Xft.hinting: 1
|
||||
Xft.hintstyle: hintslight
|
||||
Xft.rgba: rgb
|
||||
${shell:xresources:first}${shell:xresources:normal}${shell:xresources:last}
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"module": "xorg",
|
||||
"version": "1",
|
||||
"moved": true,
|
||||
"capabilities": [
|
||||
"package-manager",
|
||||
"seat"
|
||||
@@ -96,7 +97,7 @@
|
||||
"path": "${machine:account-home}/.config/xorg/xresources",
|
||||
"owner": "${machine:account}",
|
||||
"mode": "0644",
|
||||
"content": "! The mesh's X resources (module xorg, novox/hq ADR 0208 §4), replaced at every push. The session's\n! start merges them with xrdb -nocpp before ~/.Xresources, so your own resources there win. Without\n! the preprocessor there is no #include or #define here, and a line starting with # is skipped,\n! which is what the line naming each contributing module is.\n!\n! Font rendering, as both workstations had it. 96 DPI becomes a setting with issue 168; xorg_dpi\n! changes it for the running session.\nXft.dpi: 96\nXft.antialias: 1\nXft.hinting: 1\nXft.hintstyle: hintslight\nXft.rgba: rgb\n${shell:xresources:first}${shell:xresources:normal}${shell:xresources:last}\n"
|
||||
"template": "files/xresources"
|
||||
},
|
||||
{
|
||||
"id": "xinitrc",
|
||||
@@ -106,7 +107,7 @@
|
||||
"mode": "0755",
|
||||
"into": "block",
|
||||
"at": "start",
|
||||
"content": "# The mesh's block (module xorg, novox/hq ADR 0208 §5): the graphical session's start, replaced at\n# every push. It ends by starting the session, so no line below it in this file runs any more. A line\n# of your own that must run at every session start goes in ~/.xinitrc.local, which this block sources\n# just before the session starts (the module's README lists where each of today's lines went).\n\n# 1. The account's environment (ADR 0203): the file every shell sources, written by node-environment.\nif [ -r \"${machine:account-home}/.config/mesh/environment.sh\" ]; then\n . \"${machine:account-home}/.config/mesh/environment.sh\"\nfi\n\n# The session bus is the user manager's. pam_systemd normally hands it over; when it did not, take\n# the canonical socket rather than starting a second bus, which runs every D-Bus-activated service\n# twice (two notifiers, two portals) and hides one copy from the other.\nif [ -z \"$DBUS_SESSION_BUS_ADDRESS\" ] && [ -S \"/run/user/$(id -u)/bus\" ]; then\n DBUS_SESSION_BUS_ADDRESS=\"unix:path=/run/user/$(id -u)/bus\"\n export DBUS_SESSION_BUS_ADDRESS\nfi\n\n# 2. The session's own words into the user manager and D-Bus activation, so the portal, the notifier\n# and every user service see the display and the desktop's identity. An explicit list and never\n# --all: a session's environment may hold things no user service should be able to read back.\nmesh_words=\nfor mesh_word in DISPLAY XAUTHORITY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP \\\n XDG_CONFIG_HOME XDG_DATA_DIRS GTK_THEME GTK2_RC_FILES QT_QPA_PLATFORMTHEME QT_STYLE_OVERRIDE \\\n QT_SELECT XCURSOR_THEME XCURSOR_SIZE TERMINAL; do\n if printenv \"$mesh_word\" >/dev/null 2>&1; then\n mesh_words=\"$mesh_words $mesh_word\"\n fi\ndone\ndbus-update-activation-environment --systemd $mesh_words\nunset mesh_word mesh_words\n\n# 3. X resources: the mesh's, then yours in ~/.Xresources, which win. The mesh's file is merged\n# without the C preprocessor, so no compiler is needed for it.\nxrdb -nocpp -merge \"${machine:account-home}/.config/xorg/xresources\"\nif [ -r \"$HOME/.Xresources\" ]; then\n xrdb -merge \"$HOME/.Xresources\"\nfi\n\n# 4. The monitors: the saved layout profile that matches the monitors connected, if one does.\nif command -v autorandr >/dev/null 2>&1; then\n autorandr --change >/dev/null 2>&1 || true\nfi\n\n# 5. Other modules' session lines (ADR 0208 §4), then yours.\n${shell:xinitrc:first}${shell:xinitrc:normal}if [ -r \"$HOME/.xinitrc.local\" ]; then\n . \"$HOME/.xinitrc.local\"\nfi\n\n# 6. The session itself: the holder of node-display-session starts it from the last slot.\n${shell:xinitrc:last}\n"
|
||||
"template": "files/xinitrc"
|
||||
}
|
||||
],
|
||||
"build": {
|
||||
@@ -121,6 +122,11 @@
|
||||
"loads": [
|
||||
"xorg"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "files",
|
||||
"kind": "archive",
|
||||
"from": "files"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user