Nix flake for Open Terminal (public; anonymous git pulls allowed)
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
grokbot 9f458ff4d7 feat(module): enableSudo option for setuid binaries in the service
sudo/su/ping live in /run/wrappers/bin, which was never on the service
PATH, and NoNewPrivileges=true blocked setuid outright. Non-login shells
(what the API executes) also miss the /etc/bashrc prepend that makes a
login shell work, so bare sudo hit the non-setuid store symlink.

Default off; unit output is unchanged unless opted in.
2026-11-16 23:19:32 +00:00
modules feat(module): enableSudo option for setuid binaries in the service 2026-11-16 23:19:32 +00:00
packages package: drop format under pyproject and fix invalid SRI hash 2026-11-13 17:53:41 +00:00
.gitignore Open Terminal 0.17.7: package + NixOS module (all features) 2026-11-11 01:27:51 +00:00
flake.nix fix: interface-scope firewall option; never fail-closed silently 2026-11-13 23:56:52 +00:00
LICENSE Add MIT LICENSE 2026-11-11 01:05:56 +00:00
README.md feat(module): enableSudo option for setuid binaries in the service 2026-11-16 23:19:32 +00:00

Open Terminal NixOS flake

Packages Open WebUI Open Terminal 0.17.7 for NixOS with every feature enabled by default: terminal multiplexer, file explorer, notebooks, browser tab, and the desktop (VNC/Xfce) tab.

This repo lives on Forgejo (git.hq.randomrepair.ca) under the public org Public, and it is public: any machine can pull it over HTTPS with no credentials, deploy key, or SSH access.

Design principle: consume the host's primary user, create nothing

The module never creates a user or group and hardcodes nothing about any host. It runs the service as the consuming machine's existing primary user and exposes that user's real home as the workspace root:

  • user defaults to the first normal user already declared on the host (derived from users.users), not a fixed name.
  • home defaults to that user's actual home (users.users.<user>.home).
  • the unit's Group is that user's real primary group (users.users.<user>.group).
  • an assertion fails the build with a clear message if the chosen user does not already exist on the host.

So you do not set user/home/group for the common case — just enable the service and it adopts the machine's primary user. (An earlier revision created a service user itself, which produced a phantom account with an empty home that could not see the operator's files. That is gone.)

Repository layout

  • flake.nix exports overlays.default, packages.x86_64-linux.open-terminal, and nixosModules.default.
  • packages/open-terminal.nix builds the Python app from the signed PyPI sdist (0.17.7) and takes all Python deps from nixpkgs.
  • modules/open-terminal.nix is a services.open-terminal NixOS module: a hardened systemd unit plus the runtime PATH that Open Terminal probes with shutil.which for the browser, desktop, notebook, and agent features.

Adding it to another flake

The repo is public, so no credentials are required — point the input at the anonymous HTTPS URL. The module adopts the host's primary user automatically, so the usual config is just enable = true plus the per-deployment bits (origins and LAN ranges) that only the operator knows:

inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  open-terminal.url = "git+https://git.hq.randomrepair.ca/Public/open-terminal-flake.git?ref=main";
  open-terminal.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, nixpkgs, open-terminal, ... }: {
  nixosConfigurations.server = nixpkgs.lib.nixosSystem {
    system = "x86_64-linux";
    modules = [
      open-terminal.nixosModules.default
      {
        # The module adopts the host's existing primary user automatically.
        services.open-terminal = {
          enable = true;
          # user / home / group are DERIVED from the host's primary user — set nothing.
          # Firewall scoping. allowedSourceRanges only derives from IPv4 addresses
          # STATICALLY configured on this host's interfaces. On a DHCP host there
          # is no static IP at eval time, so it derives to nothing and the build
          # FAILS with a clear message instead of silently closing the port.
          # Scope the firewall by INTERFACE name instead (works on DHCP):
          allowedInterfaces = [ "eth0" ];          # your real LAN interface
          # ...or pin explicit CIDRs when the client is off-box (remote/VPN/Tailscale):
          # allowedSourceRanges = [ "100.64.0.0/10" ];
          corsAllowedOrigins = [ "https://your-open-webui.example" ];
        };
      }
    ];
  };
};

To target a specific existing user instead of the derived first normal user, set services.open-terminal.user to that user's name (it must already be declared; the module will not create it).

API key

The service authenticates callers with a bearer token. By default the module creates it for you on first start, so you never have to provision it:

  • services.open-terminal.generateApiKey = true (default) runs an idempotent ExecStartPre that writes a 64-hex-char key (mode 0600) into the service StateDirectory, /var/lib/open-terminal/api.key, only if it does not already exist. It is generated on the host at runtime, never baked into the Nix store, so it stays out of the system closure and build logs. The key survives rebuilds and reboots (it is not regenerated once present).

Retrieve it on the host, then paste it into Open WebUI (Settings -> Admin Settings -> Integrations -> Open Terminal):

sudo cat /var/lib/open-terminal/api.key

To manage the key yourself instead, set generateApiKey = false and provide the file named by apiKeyFile (default /var/lib/open-terminal/api.key, override to any path, e.g. /etc/open-terminal/api.key):

sudo mkdir -p /etc/open-terminal
openssl rand -hex 32 | sudo tee /etc/open-terminal/api.key
sudo chmod 600 /etc/open-terminal/api.key

Options

Option Default Purpose
user host's first normal user (derived) Existing user to run as; never created by this module
home users.users.<user>.home (derived) Workspace root exposed to Open WebUI (the user's real home)
port / host 8771 / 0.0.0.0 Listen address for the Open Terminal API
corsAllowedOrigins [ ] Origins allowed to call the API (set per deployment)
apiKeyFile /var/lib/open-terminal/api.key File holding the bearer key when generateApiKey = false
generateApiKey true Auto-create the bearer key on first start (0600); when false, use apiKeyFile
inheritUserPath true Put the host user's and the system's profile bins on the service PATH, so the Open Terminal terminal sees the same packages an interactive login shell does. Set false for a minimal, fixed feature toolchain (more reproducible/hardened)
extraPackages [ ] Extra binaries to add to the service PATH for agent/document features (use this for things not in the user/system profiles, or when inheritUserPath = false)
enableSudo false Clear NoNewPrivileges and prepend /run/wrappers/bin to the service PATH so the service user can run setuid-root binaries (sudo, su, ping). With a passwordless sudoers this hands root to anyone who can reach the API as that user; it does not itself make sudo passwordless.
openFirewall true Open the API port in the firewall, scoped by the rules below.
allowedSourceRanges host static subnets (hostSubnets) Accept traffic from these CIDRs. Defaults to subnets derived from IPv4 addresses STATICALLY configured on the host's interfaces; derives to nothing on a DHCP host (no build-time IP exists).
allowedInterfaces [ ] Accept traffic arriving on these interface names (iifname / -i). Recommended on DHCP hosts: interface names exist at build time and survive lease changes. If the firewall is on and BOTH lists are empty, the module fails the build instead of silently closing the port.
package packaged 0.17.7 The derivation to run

allowedInterfaces and allowedSourceRanges are independent alternatives (an OR): setting either one on its own is enough to scope the port and reachability, and neither requires the other. The generated firewall rules accept traffic matching EITHER a source range OR an inbound interface; only the catch-all DROP applies to traffic matching neither. If the firewall is enabled and BOTH are empty, the build fails with a clear message instead of silently closing the port.

All features

Every OPEN_TERMINAL_ENABLE_* flag defaults to true, so terminal, notebooks, browser, and desktop are on with no config. The browser and desktop features additionally require runtime binaries on the service PATH; the module provides them:

  • browser tab: chromium
  • desktop tab: tigervnc (Xtigervnc), dbus (dbus-run-session), xfce (startxfce4), xorg.xauth, xorg.xrandr, xdotool, scrot, xclip, pulseaudio, ffmpeg
  • notebooks: bundled in the package (nbclient, ipykernel)
  • search and shell: ripgrep, git, bash

Your existing chromium is still fine: the module puts a chromium on the service PATH regardless, because Open Terminal discovers the browser via shutil.which on the unit environment, not your desktop session.

Checks

nix flake check
nix build .#open-terminal