From f3c1925434c393a5db41ae238aeb6d9a7b33792d Mon Sep 17 00:00:00 2001 From: r0chd Date: Sun, 4 Oct 2026 19:24:36 +0200 Subject: [PATCH] sessiond-hooks: run on_start hook as a shell scrit --- Cargo.toml | 1 - docs/src/clients/client-hooks.md | 4 +- docs/src/installation/nixos.md | 5 +- hyprwire-protocols-sessiond/Cargo.toml | 1 - hyprwire-protocols-sessiond/README.md | 3 - nix/internal/finix-vm.nix | 14 +--- nix/internal/nixos-vm.nix | 5 +- sessiond-hooks/Cargo.toml | 1 - sessiond-hooks/README.md | 98 -------------------------- sessiond-hooks/src/main.rs | 15 ++-- sessiond-uaccess/Cargo.toml | 1 - sessiond-uaccess/README.md | 98 -------------------------- 12 files changed, 10 insertions(+), 236 deletions(-) delete mode 100644 hyprwire-protocols-sessiond/README.md delete mode 100644 sessiond-hooks/README.md delete mode 100644 sessiond-uaccess/README.md diff --git a/Cargo.toml b/Cargo.toml index 0473219..f9566c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,6 @@ edition = "2024" license = "GPL-3.0-only" repository = "https://tangled.org/r0chd.pl/sessiond" description = "session management daemon" -readme = "README.md" [workspace.lints.clippy] all = { level = "warn", priority = -1 } diff --git a/docs/src/clients/client-hooks.md b/docs/src/clients/client-hooks.md index 932e524..0bcc451 100644 --- a/docs/src/clients/client-hooks.md +++ b/docs/src/clients/client-hooks.md @@ -7,9 +7,7 @@ manager such as `dinit --user` or `runsvdir`. ## Configuration ```toml -[on_start] -exec = "/usr/bin/dinit" -args = ["--user", "--services-dir", "~/.config/dinit.d"] +on_start = "/usr/bin/dinit" [restart] on = "Failure" diff --git a/docs/src/installation/nixos.md b/docs/src/installation/nixos.md index 7d37236..5064c0c 100644 --- a/docs/src/installation/nixos.md +++ b/docs/src/installation/nixos.md @@ -148,10 +148,7 @@ supervise it: package = inputs.sessiond.packages.sessiond-hooks; debug = true; hooks.systemd.settings = { - on_start = { - exec = "${pkgs.systemd}/lib/systemd/systemd"; - args = [ "--user" ]; - }; + on_start = "${pkgs.systemd}/lib/systemd/systemd"; restart = { on = "Always"; delay = 5; diff --git a/hyprwire-protocols-sessiond/Cargo.toml b/hyprwire-protocols-sessiond/Cargo.toml index 83b8b8d..6015c49 100644 --- a/hyprwire-protocols-sessiond/Cargo.toml +++ b/hyprwire-protocols-sessiond/Cargo.toml @@ -7,7 +7,6 @@ license = "MIT" repository.workspace = true version = "0.2.0" description = "Common Hyprwire protocols for sessiond" -readme = "README.md" [dependencies] hyprwire = "0.5.1" diff --git a/hyprwire-protocols-sessiond/README.md b/hyprwire-protocols-sessiond/README.md deleted file mode 100644 index dbc6443..0000000 --- a/hyprwire-protocols-sessiond/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# hyprwire-protocols-sessiond - -[Hyprwire](https://crates.io/crates/hyprwire) protocol definitions for sessiond. diff --git a/nix/internal/finix-vm.nix b/nix/internal/finix-vm.nix index 02a327e..e756a6d 100644 --- a/nix/internal/finix-vm.nix +++ b/nix/internal/finix-vm.nix @@ -84,24 +84,14 @@ in debug = true; hooks = { systemd.settings = { - on_start = { - exec = "${pkgs.systemd}/lib/systemd/systemd"; - args = [ "--user" ]; - }; + on_start = "${pkgs.systemd}/lib/systemd/systemd --user"; restart = { on = "Always"; delay = 5; }; }; dinit.settings = { - on_start = { - exec = lib.getExe' pkgs.dinit "dinit"; - args = [ - "--user" - "--services-dir" - "/etc/dinit.d/user" - ]; - }; + on_start = "${lib.getExe' pkgs.dinit "dinit"} --user --services-dir /etc/dinit.d/user"; restart = { on = "Failure"; delay = 5; diff --git a/nix/internal/nixos-vm.nix b/nix/internal/nixos-vm.nix index 7302e36..efbbfb4 100644 --- a/nix/internal/nixos-vm.nix +++ b/nix/internal/nixos-vm.nix @@ -61,10 +61,7 @@ in debug = true; hooks = { systemd.settings = { - on_start = { - exec = "${pkgs.systemd}/lib/systemd/systemd"; - args = [ "--user" ]; - }; + on_start = "${pkgs.systemd}/lib/systemd/systemd --user"; restart = { on = "Always"; delay = 5; diff --git a/sessiond-hooks/Cargo.toml b/sessiond-hooks/Cargo.toml index da6e036..99c4dba 100644 --- a/sessiond-hooks/Cargo.toml +++ b/sessiond-hooks/Cargo.toml @@ -8,7 +8,6 @@ repository = "https://tangled.org/r0chd.pl/sessiond" version = "0.0.0" publish = false description = "Launch and supervise per-user session hooks with sessiond" -readme = "README.md" [dependencies] anyhow = "1.0.103" diff --git a/sessiond-hooks/README.md b/sessiond-hooks/README.md deleted file mode 100644 index 73cd5bb..0000000 --- a/sessiond-hooks/README.md +++ /dev/null @@ -1,98 +0,0 @@ -# sessiond-hooks - -`sessiond-hooks` is a `sessiond` client that launches and supervises a per-user -session hook (`dinit --user`, `runsvdir`, …) started for every unique UID. - -## Installation - -`sessiond-hooks` requires `sessiond` to be installed and enabled first. - -On finix with flakes: - -```nix -{ - inputs.sessiond-hooks.url = "git+https://tangled.org/r0chd.pl/sessiond-hooks"; -} -``` - -```nix -{ inputs, lib, pkgs, ... }: -{ - imports = [ - inputs.sessiond-hooks.finixModules.default - ]; - - services.sessiond-hooks = { - package = inputs.sessiond-hooks.packages.${pkgs.system}.default; - hooks.dinit.settings = { - on_start = { - exec = lib.getExe' pkgs.dinit "dinit"; - args = [ "--user" "--services-dir" "~/.config/dinit.d" ]; - }; - restart = { - on = "Failure"; - delay = 5; - }; - }; - }; -} -``` - -With npins: - -```sh -npins add git --name sessiond-hooks https://tangled.org/r0chd.pl/sessiond-hooks --branch master -``` - -```nix -{ lib, pkgs, ... }: -let - sources = import ./npins; - sessiond-hooks = import sources.sessiond-hooks.outPath { }; -in -{ - imports = [ - sessiond-hooks.finixModules.default - ]; - - services.sessiond-hooks = { - package = sessiond-hooks.packages.sessiond-hooks; - hooks.dinit.settings = { - on_start = { - exec = lib.getExe' pkgs.dinit "dinit"; - args = [ "--user" "--services-dir" "~/.config/dinit.d" ]; - }; - restart = { - on = "Failure"; - delay = 5; - }; - }; - }; -} -``` - -To build it manually: - -```sh -cargo build --release -``` - -The binary is written to `target/release/sessiond-hooks`. - -## Usage - -```sh -sessiond-hooks [--config PATH] [--log-target stderr|syslog] -``` - -Example configuration: - -```toml -[on_start] -exec = "/usr/bin/dinit" -args = ["--user", "--services-dir", "~/.config/dinit.d"] - -[restart] -on = "Failure" -delay = 5 -``` diff --git a/sessiond-hooks/src/main.rs b/sessiond-hooks/src/main.rs index 5aa2583..505ba64 100644 --- a/sessiond-hooks/src/main.rs +++ b/sessiond-hooks/src/main.rs @@ -15,7 +15,6 @@ use std::collections::BTreeMap; use std::io::Write; use std::os::unix::process::CommandExt; use std::{env, fs, io, path, process, time}; -use uzers::os::unix::UserExt; #[derive(Parser)] #[command(version, about = "Launch and supervise a per-user session hook")] @@ -246,21 +245,17 @@ impl hyprwire::Dispatch for }) }; cmd.arg("-c") - .arg( - r#" - [ -r /etc/profile ] && . /etc/profile - exec "$@" - "#, - ) + .arg(format!( + " + [ -r /etc/profile ] && . /etc/profile\n{}", + self.config.on_start + )) .arg("sessiond-hook"); for (key, value) in envs { cmd.env(key, value); } - self.config.on_start.split(' ').for_each(|arg| { - cmd.arg(arg); - }); cmd.stdin(process::Stdio::piped()); let mut child = match cmd.spawn() { diff --git a/sessiond-uaccess/Cargo.toml b/sessiond-uaccess/Cargo.toml index 146d240..3fd314f 100644 --- a/sessiond-uaccess/Cargo.toml +++ b/sessiond-uaccess/Cargo.toml @@ -8,7 +8,6 @@ repository = "https://tangled.org/r0chd.pl/sessiond" version = "0.0.0" publish = false description = "Dynamic device access manager" -readme = "README.md" [dependencies] anyhow = "1.0.103" diff --git a/sessiond-uaccess/README.md b/sessiond-uaccess/README.md deleted file mode 100644 index afaded3..0000000 --- a/sessiond-uaccess/README.md +++ /dev/null @@ -1,98 +0,0 @@ -# sessiond-uaccess - -`sessiond-uaccess` is a `sessiond` client that grants device-node access to -active local sessions by writing POSIX ACL entries. - -## Installation - -`sessiond-uaccess` requires `sessiond` to be installed and enabled first. - -On finix with flakes: - -```nix -{ - inputs.sessiond-uaccess.url = "git+https://tangled.org/r0chd.pl/sessiond-uaccess"; -} -``` - -```nix -{ inputs, pkgs, ... }: -{ - imports = [ - inputs.sessiond-uaccess.finixModules.default - ]; - - services.sessiond-uaccess = { - enable = true; - package = inputs.sessiond-uaccess.packages.${pkgs.system}.default; - }; -} -``` - -With npins: - -```sh -npins add git --name sessiond-uaccess https://tangled.org/r0chd.pl/sessiond-uaccess --branch master -``` - -```nix -{ pkgs, ... }: -let - sources = import ./npins; - sessiond-uaccess = import sources.sessiond-uaccess.outPath { }; -in -{ - imports = [ - sessiond-uaccess.finixModules.default - ]; - - services.sessiond-uaccess = { - enable = true; - package = sessiond-uaccess.packages.sessiond-uaccess; - }; -} -``` - -To build it manually: - -```sh -cargo build --release -``` - -The binary is written to `target/release/sessiond-uaccess`. - -## Usage - -```sh -sessiond-uaccess --rules-dirs PATH [--rules-dirs PATH...] -``` - -`sessiond-uaccess` connects to `/run/sessiond/sessiond.sock`, loads every `*.lua` file -from each existing rules directory, scans existing udev devices, and then keeps -listening for new udev devices and session changes. - -### mdevd - -`sessiond-uaccess` can be used with `mdevd` and `libudev-zero`. Start `mdevd` -with `-O 4` so it rebroadcasts processed uevents to the netlink group used by -the libudev monitor: - -```sh -mdevd -O 4 -``` - -## Rules - -Rules are Lua files that call `device` with an access mode and match function: - -```lua -device { - access = "rw", - match = function(dev) - return dev.subsystem == "sound" - end, -} -``` - -The default rules in `rules/70-uaccess.lua` cover sound devices, cameras, DRI -devices, render and accelerator nodes, AMD KFD, KVM, rfkill, and optical drives. -- 2.51.2