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.
This commit is contained in:
James Davidson 2026-03-15 12:56:59 -07:00 committed by Bruno BELANYI
parent ecf019baf4
commit f72ed9c97d
4 changed files with 37 additions and 3 deletions

View file

@ -0,0 +1,9 @@
{ config, pkgs, ... }:
{
time = "2026-03-15T20:42:27+00:00";
condition = true;
message = ''
programs.smug.projects.<name>.session is a new optional setting that
can be used to specify a different session name from the project name.
'';
}

View file

@ -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)
);

View file

@ -0,0 +1,5 @@
root: ~/project
session: project-${worktree}
windows:
- layout: tiled
name: src

View file

@ -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}
'';
}