From a1edac63b845e92f62035cd2d38949eae84709fc Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 20:34:33 +0000 Subject: [PATCH] fix(session): start the session as user units through its own target The tty1 login hook ran systemctl --user start graphical-session.target, which systemd refuses (RefuseManualStart=yes), so none of the NixOS session's services started. The units in infra/systemd were wanted by graphical.target, a system target, although weft-appd's needs the session user's runtime and home directories and the compositor publishes its socket to the user manager; run as system units the shell could never learn the socket. weft-session.target binds graphical-session.target and wants the compositor, shell and weft-appd, in the NixOS configuration and as a user unit in infra/systemd; the login hook starts it. The services are part of the graphical session, the shell no longer hardcodes the compositor's socket, and the compositor's units unset WAYLAND_DISPLAY and DISPLAY so a restarted compositor does not take them for an enclosing session and pick the nested backend. As a user unit, weft-appd drops ProtectSystem= and PrivateTmp=, which a user manager implements with PrivateUsers=yes, under which the setuid mount helper cannot mount verified images. docs/building.md adds the VM's disabled graphics and its mount helper, which the Nix store cannot hold setuid, to what still keeps the image from a working desktop. Rendered from the NixOS configuration, and as installed from infra/systemd, the units pass systemd-analyze --user verify. --- docs/building.md | 5 +++-- infra/nixos/configuration.nix | 26 ++++++++++++++++++++------ infra/systemd/servo-shell.service | 4 ++-- infra/systemd/weft-appd.service | 12 +++++------- infra/systemd/weft-compositor.service | 12 ++++++++---- infra/systemd/weft-session.target | 10 ++++++++++ 6 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 infra/systemd/weft-session.target diff --git a/docs/building.md b/docs/building.md index 9a4a6d6..9791fb4 100644 --- a/docs/building.md +++ b/docs/building.md @@ -141,11 +141,12 @@ bash infra/vm/run.sh See `infra/nixos/weft-packages.nix` for the package derivations. Its `outputHashes` hold one hash per git source in `Cargo.lock` (the Servo and Stylo forks); every package vendors them, so they must match the pinned revisions for any Nix package to build. -The VM's user session starts `weft-compositor`, `weft-servo-shell` with the system UI page its package installs, and `weft-appd` with the runtime, app shell, file portal and mount helper packages. The image is not yet bootable to a working desktop: +Logging in on tty1 starts the user target `weft-session.target`, which binds `graphical-session.target` (that one refuses a manual start) and wants `weft-compositor`, then `weft-servo-shell` with the system UI page its package installs, and `weft-appd` with the runtime, app shell, file portal and mount helper packages. Run as a systemd user service, the compositor publishes its socket as `WAYLAND_DISPLAY` to the user manager before reporting readiness, so the units after it, and the app shells weft-appd starts, connect to it. The units in `infra/systemd/` are the same session for an installation outside Nix, as user units under `weft-session.target`. The image is not yet bootable to a working desktop: - the Servo source hash in `outputHashes` is still a placeholder, so no package builds until a Nix build reports it; - the shell packages do not enable `servo-embed`, so `weft-servo-shell` and `weft-app-shell` exit at startup; -- the shell's service names the compositor's socket `wayland-1`, the first name the compositor tries, rather than learning it. +- the VM runs without graphics (`virtualisation.graphics = false` in `infra/nixos/configuration.nix`, for a serial console), so the session's output is not shown; +- `WEFT_MOUNT_HELPER` names the mount helper's store path, which cannot be setuid, so verified images cannot be mounted; a setuid wrapper would be needed. ## CI diff --git a/infra/nixos/configuration.nix b/infra/nixos/configuration.nix index 17a66c2..271012a 100644 --- a/infra/nixos/configuration.nix +++ b/infra/nixos/configuration.nix @@ -75,15 +75,28 @@ }) ]; + # graphical-session.target refuses a manual start; the login shell starts + # this target, which binds it, as Wayland compositors' session targets do. + systemd.user.targets.weft-session = { + description = "WEFT OS session"; + bindsTo = [ "graphical-session.target" ]; + wants = [ "graphical-session-pre.target" ]; + after = [ "graphical-session-pre.target" ]; + }; + systemd.user.services = { weft-compositor = { description = "WEFT OS Wayland Compositor"; - after = [ "graphical-session.target" ]; + before = [ "graphical-session.target" ]; partOf = [ "graphical-session.target" ]; - wantedBy = [ "graphical-session.target" ]; + wantedBy = [ "weft-session.target" ]; serviceConfig = { Type = "notify"; ExecStart = "${pkgs.weft.weft-compositor}/bin/weft-compositor"; + # The compositor publishes WAYLAND_DISPLAY to the user manager for the + # units after it; a restarted compositor must not inherit it, or an + # X11 DISPLAY, or it would pick the nested backend. + UnsetEnvironment = "WAYLAND_DISPLAY DISPLAY"; Restart = "on-failure"; RestartSec = "1"; }; @@ -93,9 +106,9 @@ description = "WEFT OS System Shell"; requires = [ "weft-compositor.service" ]; after = [ "weft-compositor.service" ]; - wantedBy = [ "graphical-session.target" ]; + partOf = [ "graphical-session.target" ]; + wantedBy = [ "weft-session.target" ]; environment = { - WAYLAND_DISPLAY = "wayland-1"; WEFT_SYSTEM_UI_HTML = "${pkgs.weft.weft-servo-shell}/share/weft/shell/system-ui.html"; }; serviceConfig = { @@ -110,7 +123,8 @@ description = "WEFT Application Daemon"; requires = [ "weft-compositor.service" ]; after = [ "weft-compositor.service" "weft-servo-shell.service" ]; - wantedBy = [ "graphical-session.target" ]; + partOf = [ "graphical-session.target" ]; + wantedBy = [ "weft-session.target" ]; serviceConfig = { Type = "notify"; ExecStart = "${pkgs.weft.weft-appd}/bin/weft-appd"; @@ -128,7 +142,7 @@ programs.bash.loginShellInit = '' if [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && [ "$(tty)" = "/dev/tty1" ]; then - systemctl --user start graphical-session.target + systemctl --user start weft-session.target fi ''; diff --git a/infra/systemd/servo-shell.service b/infra/systemd/servo-shell.service index e87141e..e6ef1cb 100644 --- a/infra/systemd/servo-shell.service +++ b/infra/systemd/servo-shell.service @@ -3,10 +3,10 @@ Description=WEFT OS Servo Shell Documentation=https://github.com/weft-os/weft Requires=weft-compositor.service After=weft-compositor.service +PartOf=graphical-session.target [Service] Type=simple -PassEnvironment=WAYLAND_DISPLAY XDG_RUNTIME_DIR DISPLAY Environment=WEFT_APPD_WS_PORT=7410 # The page is the package's share/weft/shell/system-ui.html; set # WEFT_SYSTEM_UI_HTML to use another. @@ -15,4 +15,4 @@ Restart=on-failure RestartSec=2 [Install] -WantedBy=graphical.target +WantedBy=weft-session.target diff --git a/infra/systemd/weft-appd.service b/infra/systemd/weft-appd.service index 45fd526..105acdf 100644 --- a/infra/systemd/weft-appd.service +++ b/infra/systemd/weft-appd.service @@ -3,6 +3,7 @@ Description=WEFT Application Daemon Documentation=https://github.com/weft-os/weft Requires=weft-compositor.service After=weft-compositor.service servo-shell.service +PartOf=graphical-session.target [Service] Type=notify @@ -10,15 +11,12 @@ Environment=WEFT_RUNTIME_BIN=/packages/system/weft-runtime/active/bin/weft-runti Environment=WEFT_APP_SHELL_BIN=/packages/system/weft-app-shell/active/bin/weft-app-shell Environment=WEFT_FILE_PORTAL_BIN=/packages/system/weft-file-portal/active/bin/weft-file-portal Environment=WEFT_MOUNT_HELPER=/packages/system/weft-mount-helper/active/bin/weft-mount-helper -PassEnvironment=WAYLAND_DISPLAY XDG_RUNTIME_DIR DISPLAY ExecStart=/packages/system/weft-appd/active/bin/weft-appd Restart=on-failure RestartSec=1s -ProtectSystem=strict -PrivateTmp=true -# App data and the user package store, where earlier versions kept app data. -# %h is the home of the user the unit runs as; run it as the session user. -ReadWritePaths=%t -%h/.local/share/weft +# No ProtectSystem= or PrivateTmp=: in the user manager they imply +# PrivateUsers=yes, under which the setuid weft-mount-helper cannot mount +# verified images. Each session's runtime runs in its own systemd scope. [Install] -WantedBy=graphical.target +WantedBy=weft-session.target diff --git a/infra/systemd/weft-compositor.service b/infra/systemd/weft-compositor.service index ad7ac7e..52489b0 100644 --- a/infra/systemd/weft-compositor.service +++ b/infra/systemd/weft-compositor.service @@ -1,15 +1,19 @@ [Unit] Description=WEFT OS Wayland Compositor Documentation=https://github.com/weft-os/weft -After=systemd-logind.service +Before=graphical-session.target +PartOf=graphical-session.target [Service] Type=notify ExecStart=/packages/system/weft-compositor/active/bin/weft-compositor Restart=on-failure RestartSec=1 -# The socket path is posted to the environment by the compositor itself. -# Downstream services (servo-shell.service) should declare After=weft-compositor.service. +# A user unit: the compositor publishes its socket as WAYLAND_DISPLAY in the +# user manager before reporting readiness, for the services ordered +# After=weft-compositor.service. It must not inherit that value, or an X11 +# DISPLAY, on restart, or it would pick the nested backend. +UnsetEnvironment=WAYLAND_DISPLAY DISPLAY [Install] -WantedBy=graphical.target +WantedBy=weft-session.target diff --git a/infra/systemd/weft-session.target b/infra/systemd/weft-session.target new file mode 100644 index 0000000..382c3d0 --- /dev/null +++ b/infra/systemd/weft-session.target @@ -0,0 +1,10 @@ +[Unit] +Description=WEFT OS session +Documentation=https://github.com/weft-os/weft +# These are user units: install them in the user manager +# (systemctl --user enable weft-compositor servo-shell weft-appd) and start +# the session with systemctl --user start weft-session.target, as the NixOS +# image's login shell does. graphical-session.target refuses a manual start. +BindsTo=graphical-session.target +Wants=graphical-session-pre.target +After=graphical-session-pre.target