Skip to content

Conversation

@bmrips
Copy link
Contributor

@bmrips bmrips commented Nov 19, 2025

Description

This PR is a follow-up on #8099.

  • Since ssh-agent: add shell integrations #8099, the module sets $SSH_AUTH_SOCK through shells' options for interactive shell initialization instead of home.sessionVariablesExtra. The replacement was not faithful, however, since home.sessionVariablesExtra is sourced also in non-interactive shells. With this PR, the shells' profile options (where home.sessionVariablesExtra is sourced) are used to set $SSH_AUTH_SOCK.

  • ssh-agent: add shell integrations #8099 introduced shell integration options that guard the code for setting $SSH_AUTH_SOCK. To my understanding it is crucial for the ssh-agent that this env var is set, hence I do not see a reason to have these options. Consequently, this PR removes them.

    Note that this change is not backwards-compatible!

Fixes #8129.

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

@bmrips
Copy link
Contributor Author

bmrips commented Nov 19, 2025

@rhododendrox, @meenzen, @slotThe would you mind testing whether this PR fixes your issues? That would be appreciated because I do not have any issues myself!

@rhododendrox
Copy link

rhododendrox commented Nov 20, 2025

Just tested this, it works and kinda fixes my problem, but that's fine since I discovered the issues I had where partially caused by my config.

Nevertheless I think this is a good change since it makes much more sense to export SSH_AUTH_SOCK in .profile instead of .bashrc

PS: I only tested bash and zsh because those are the shells I use.
If someone here uses the other two shells and can test this changes it'd be really helpful.

@slotThe
Copy link
Contributor

slotThe commented Nov 24, 2025

[…] @slotThe would you mind testing whether this PR fixes your issues? That would be appreciated because I do not have any issues myself!

Tested it with fish, and everything seems to work as before after I shuffled some bits: I start X11 from .profile, and by default the export of SSH_AUTH_SOCK was inserted after the call to xinit. Inserting a lib.mkAfter in my own config fixed this, but this should probably be documented as a possible problem when upgrading.

Thanks!

@bmrips
Copy link
Contributor Author

bmrips commented Nov 24, 2025

Tested it with fish, and everything seems to work as before after I shuffled some bits: I start X11 from .profile, and by default the export of SSH_AUTH_SOCK was inserted after the call to xinit. Inserting a lib.mkAfter in my own config fixed this, but this should probably be documented as a possible problem when upgrading.

That's a good point! I added an lib.mkBefore to put the initialization code before other code such that these kind of issues should be fixed.

@jokesper jokesper mentioned this pull request Nov 27, 2025
9 tasks
@jokesper
Copy link

Since I just also noticed the Problem, I have tried your fix (on fish).
Seems to work just fine for me too.

@bmrips bmrips marked this pull request as ready for review December 1, 2025 10:45
@bmrips bmrips requested a review from lheckemann December 1, 2025 10:45
Comment on lines 39 to 46

enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; };

enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { inherit config; };

enableFishIntegration = lib.hm.shell.mkFishIntegrationOption { inherit config; };

enableNushellIntegration = lib.hm.shell.mkNushellIntegrationOption { inherit config; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, IMO the options can stay, I can imagine that someone might want to disable it for some reason.

At the very least, this should make use of mkRemoveOptionModule if you do remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. With the newest change, I left them intact.

in
{
bash.initExtra = lib.mkIf cfg.enableBashIntegration bashIntegration;
bash.profileExtra = lib.mkBefore bashIntegration;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mkBefore?


Ah:

Tested it with fish, and everything seems to work as before after I shuffled some bits: I start X11 from .profile, and by default the export of SSH_AUTH_SOCK was inserted after the call to xinit. Inserting a lib.mkAfter in my own config fixed this, but this should probably be documented as a possible problem when upgrading.

That's a good point! I added an lib.mkBefore to put the initialization code before other code such that these kind of issues should be fixed.

More of a downstream user issue than module issue IMO, though it is a simple change.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't say this is a downstream user issue, if the behaviour of defined options differ due to an upstream change. There is also no other option for code you want to always run. An alternative to mkBefore would be a new option which is like profileExtra + mkBefore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mkBefore?

To preserve the behavior of the module as it was before. I also just changed the priority from 500 to 900 such that lib.mkBefore on the user side gets priority as you would expect.

Since PR nix-community#8099, the module sets `$SSH_AUTH_SOCK` through shells' options
for interactive shell initialization instead of
`home.sessionVariablesExtra`. The replacement was not faithful, however,
since `home.sessionVariablesExtra` is sourced also in non-interactive
shells. With this commit, the shells' profile options (where
`home.sessionVariablesExtra` is sourced) are used to set
`$SSH_AUTH_SOCK`.

Fixes nix-community#8129.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: SSH_AUTH_SOCK is not set when starting emacs as a service

5 participants