WEFT_OS/infra/nixos/configuration.nix
Marco Allegretti a1edac63b8
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.
2026-10-09 20:35:58 +00:00

153 lines
4.2 KiB
Nix

{ pkgs, lib, self, modulesPath, rustOverlay, ... }:
{
imports = [
"${modulesPath}/profiles/qemu-guest.nix"
"${modulesPath}/virtualisation/qemu-vm.nix"
];
system.stateVersion = "25.05";
boot.loader.grub = {
enable = true;
device = "/dev/vda";
};
fileSystems."/" = {
device = "/dev/vda1";
fsType = "ext4";
};
virtualisation = {
graphics = false;
memorySize = 4096;
cores = 4;
diskSize = 20480;
};
hardware.graphics = {
enable = true;
extraPackages = with pkgs; [ mesa.drivers virglrenderer ];
};
networking = {
hostName = "weft-vm";
firewall.enable = false;
};
time.timeZone = "UTC";
users.users.weft = {
isNormalUser = true;
description = "WEFT OS session user";
extraGroups = [ "video" "render" "seat" "input" "audio" ];
password = "";
autoSubUidGidRange = false;
};
services.getty.autologinUser = "weft";
security.polkit.enable = true;
services.dbus.enable = true;
services.udev.packages = [ pkgs.libinput ];
environment.systemPackages = with pkgs; [
mesa
wayland-utils
libinput
bash
coreutils
curl
htop
pkgs.weft.weft-servo-shell
pkgs.weft.weft-app-shell
pkgs.weft.weft-pack
];
nixpkgs.overlays = [
rustOverlay
(final: prev: {
rust193 = final.rust-bin.stable."1.93.0".default;
weft = final.callPackage ./weft-packages.nix {
rust193 = final.rust193;
};
})
];
# 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";
before = [ "graphical-session.target" ];
partOf = [ "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";
};
};
weft-servo-shell = {
description = "WEFT OS System Shell";
requires = [ "weft-compositor.service" ];
after = [ "weft-compositor.service" ];
partOf = [ "graphical-session.target" ];
wantedBy = [ "weft-session.target" ];
environment = {
WEFT_SYSTEM_UI_HTML = "${pkgs.weft.weft-servo-shell}/share/weft/shell/system-ui.html";
};
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.weft.weft-servo-shell}/bin/weft-servo-shell";
Restart = "on-failure";
RestartSec = "2";
};
};
weft-appd = {
description = "WEFT Application Daemon";
requires = [ "weft-compositor.service" ];
after = [ "weft-compositor.service" "weft-servo-shell.service" ];
partOf = [ "graphical-session.target" ];
wantedBy = [ "weft-session.target" ];
serviceConfig = {
Type = "notify";
ExecStart = "${pkgs.weft.weft-appd}/bin/weft-appd";
Restart = "on-failure";
RestartSec = "1s";
Environment = [
"WEFT_RUNTIME_BIN=${pkgs.weft.weft-runtime}/bin/weft-runtime"
"WEFT_APP_SHELL_BIN=${pkgs.weft.weft-app-shell}/bin/weft-app-shell"
"WEFT_FILE_PORTAL_BIN=${pkgs.weft.weft-file-portal}/bin/weft-file-portal"
"WEFT_MOUNT_HELPER=${pkgs.weft.weft-mount-helper}/bin/weft-mount-helper"
];
};
};
};
programs.bash.loginShellInit = ''
if [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && [ "$(tty)" = "/dev/tty1" ]; then
systemctl --user start weft-session.target
fi
'';
nix.settings = {
experimental-features = [ "nix-command" "flakes" ];
trusted-users = [ "root" "weft" ];
};
}