From f72ed9c97d434daab5d359d469c43a5d5c7a4dec Mon Sep 17 00:00:00 2001 From: James Davidson Date: Sun, 15 Mar 2026 12:56:59 -0700 Subject: [PATCH] smug: add project session setting Add an optional session setting so that session names can be different than the smug project name. This also enables using template variables when naming sessions. --- modules/misc/news/2026/03/2026-03-15_13-42-27.nix | 9 +++++++++ modules/programs/smug.nix | 14 +++++++++++--- tests/modules/programs/smug/project.yml | 5 +++++ tests/modules/programs/smug/settings.nix | 12 ++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 modules/misc/news/2026/03/2026-03-15_13-42-27.nix create mode 100644 tests/modules/programs/smug/project.yml diff --git a/modules/misc/news/2026/03/2026-03-15_13-42-27.nix b/modules/misc/news/2026/03/2026-03-15_13-42-27.nix new file mode 100644 index 00000000..79adbb80 --- /dev/null +++ b/modules/misc/news/2026/03/2026-03-15_13-42-27.nix @@ -0,0 +1,9 @@ +{ config, pkgs, ... }: +{ + time = "2026-03-15T20:42:27+00:00"; + condition = true; + message = '' + programs.smug.projects..session is a new optional setting that + can be used to specify a different session name from the project name. + ''; +} diff --git a/modules/programs/smug.nix b/modules/programs/smug.nix index 2a92b7c0..50a91d79 100644 --- a/modules/programs/smug.nix +++ b/modules/programs/smug.nix @@ -37,9 +37,17 @@ in projects = lib.mkOption { type = lib.types.attrsOf ( - lib.types.submodule [ + lib.types.submodule ( + { name, ... }: { options = { + session = lib.mkOption { + type = lib.types.str; + default = name; + description = "Session name for the smug project."; + example = lib.literalExpression ''{ session = "project-\''${worktree}"; }''; + }; + root = mkOptionRoot '' Root path in filesystem of the smug project. This is where tmux changes its directory to. @@ -139,7 +147,7 @@ in stop = mkOptionCommands "Commands to execute after the tmux-session is destroyed."; }; } - ] + ) ); default = { }; description = "Attribute set with project configurations."; @@ -161,7 +169,7 @@ in (lib.attrsets.nameValuePair (if name == "beforeStart" then "before_start" else name) value) ) v // { - session = k; + session = v.session; windows = lib.lists.forEach v.windows ( winprop: (lib.filterAttrsRecursive (name: value: value != null) winprop) ); diff --git a/tests/modules/programs/smug/project.yml b/tests/modules/programs/smug/project.yml new file mode 100644 index 00000000..d0f34bd9 --- /dev/null +++ b/tests/modules/programs/smug/project.yml @@ -0,0 +1,5 @@ +root: ~/project +session: project-${worktree} +windows: +- layout: tiled + name: src diff --git a/tests/modules/programs/smug/settings.nix b/tests/modules/programs/smug/settings.nix index aa958c6a..081cf32b 100644 --- a/tests/modules/programs/smug/settings.nix +++ b/tests/modules/programs/smug/settings.nix @@ -53,11 +53,23 @@ ]; }; + project = { + root = "~/project"; + session = "project-\${worktree}"; + windows = [ + { + name = "src"; + layout = "tiled"; + } + ]; + }; + }; }; }; nmt.script = '' assertFileContent home-files/.config/smug/blogdemo.yml ${./blogdemo.yml} + assertFileContent home-files/.config/smug/project.yml ${./project.yml} ''; }