Skip to content

Conversation

@lovesegfault
Copy link
Contributor

@lovesegfault lovesegfault commented Dec 6, 2025

Description

When both system-level (e.g., NixOS programs.tmux) and home-manager
tmux configs set newSession = true, tmux would create two sessions
on startup since both /etc/tmux.conf and ~/.config/tmux/tmux.conf
contain the new-session command.

Change new-session to new-session -A -s 0, which attaches to session
"0" if it exists, otherwise creates it. This makes the command
idempotent so multiple configs can safely enable newSession.

c.f. NixOS/nixpkgs#468337

Checklist

  • Change is backwards compatible.

  • Code formatted with nix fmt or
    nix-shell -p treefmt nixfmt deadnix keep-sorted --run treefmt.

  • Code tested through nix run .#tests -- test-all or
    nix-shell --pure tests -A run.all.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.
    • Generate a news entry. See News
    • Basic tests added. See Tests
  • If this PR adds an exciting new feature or contains a breaking change.

    • Generate a news entry. See News

When both system-level (e.g., NixOS programs.tmux) and home-manager
tmux configs set newSession = true, tmux would create two sessions
on startup since both /etc/tmux.conf and ~/.config/tmux/tmux.conf
contain the new-session command.

Change new-session to new-session -A -s 0, which attaches to session
"0" if it exists, otherwise creates it. This makes the command
idempotent so multiple configs can safely enable newSession.
@lovesegfault
Copy link
Contributor Author

cc. @teto for review maybe?

@khaneliman
Copy link
Collaborator

Change seems to make sense to me, just not a tmux user anymore and not familiar enough with how this might affect existing workflows.

@teto
Copy link
Collaborator

teto commented Dec 8, 2025

I just occasionnaly use tmux. Is there a good reason to enable both the system and user modules ? having 2 differents sessions or a single one, I can see reasons for both behaviors.
In doubt, I would refrain from changing it.

Would be nice to have the feedback of a more experienced tmux user. Either way do you want to set yourself as the maintainer for this module ?

NB: Unrelated but the config chains up optionalString which tend to create empty lines that trigger my OCD in the generated config. The way to go IMO is https://github.com/NixOS/nixpkgs/blob/864b51ebb4d1143e83d05594ab8d7669f058d5d3/nixos/modules/services/networking/ssh/sshd.nix#L814

@lovesegfault
Copy link
Contributor Author

Is there a good reason to enable both the system and user modules ?

It's not really about that, you may be using home-manager on a host with new-session on the /etc/tmux.conf which you cannot control. This change makes it work under any condition.

The NixOS change is just a nice-to-have for correctness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants