From c73a698857dc0f783997585c33d96fa45d7dfd7a Mon Sep 17 00:00:00 2001 From: oqyude Date: Sun, 4 Oct 2026 22:27:55 +0300 Subject: [PATCH] opencode fix linger --- home/modules/opencode.nix | 13 ++++++++++++- modules/users.nix | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/home/modules/opencode.nix b/home/modules/opencode.nix index 5c8fba3..8bef228 100644 --- a/home/modules/opencode.nix +++ b/home/modules/opencode.nix @@ -336,7 +336,18 @@ in # Refs: # https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html # https://www.freedesktop.org/software/systemd/man/systemd.exec.html#OOMScoreAdjust= - systemd.user.services.opencode-web.serviceConfig = { + # Override the [Service] section emitted by `programs.opencode.web`. + # Upstream writes its own [Service] keys (ExecStart, EnvironmentFile, + # Restart, RestartSec); merging on the same `Service` attrset unions both + # sides into the same systemd section, so cgroup limits land where systemd + # actually reads them. + # + # NOTE: do NOT use `serviceConfig = { ... }` here — it is rendered as a + # literal `[serviceConfig]` section header by home-manager, which systemd + # silently ignores (verified on sapphira, journal: "Unknown section + # 'serviceConfig'. Ignoring."). The previous version of this block was + # exactly that, so the OOM/cgroup protection above never took effect. + systemd.user.services.opencode-web.Service = { MemoryHigh = "1G"; MemoryMax = "2G"; OOMScoreAdjust = -900; diff --git a/modules/users.nix b/modules/users.nix index c60fab9..2c9b8f4 100644 --- a/modules/users.nix +++ b/modules/users.nix @@ -68,6 +68,11 @@ in hashedPasswordFile = config.sops.secrets.hashed_password.path; # hashed_password homeMode = "700"; home = "/home/${user}"; + # Linger keeps `user@.service` (the systemd user manager) alive + # across logouts, so user services like opencode-web survive when no + # SSH/login session is active. Without this the service is torn down + # together with the user manager on the last session close. + linger = true; extraGroups = [ "audio" "disk"