Skip to content

Commit c4787b9

Browse files
committed
feat: add wsl2-ssh-agent integration
1 parent c7832dd commit c4787b9

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

modules/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
./docker-desktop.nix
55
./interop.nix
66
./recovery.nix
7+
./ssh-agent.nix
78
./systemd
89
./usbip.nix
910
./version.nix

modules/ssh-agent.nix

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{ config
2+
, lib
3+
, pkgs
4+
, ...
5+
}:
6+
7+
let
8+
cfg = config.wsl.ssh-agent;
9+
in
10+
{
11+
options.wsl.ssh-agent = {
12+
enable = lib.mkEnableOption "ssh-agent passthrough to Windows";
13+
14+
package = lib.mkPackageOption pkgs "wsl2-ssh-agent" { };
15+
16+
users = lib.mkOption {
17+
type =
18+
let
19+
inherit (lib.types) either enum listOf;
20+
userNames = lib.attrNames config.users.users;
21+
in
22+
either
23+
(enum [
24+
"!@system"
25+
"@system"
26+
])
27+
(listOf (enum userNames));
28+
default = "!@system";
29+
description = ''
30+
Users to activate the service for. Defaults to all non-system users.
31+
'';
32+
};
33+
};
34+
35+
config = lib.mkIf (config.wsl.enable && cfg.enable) {
36+
systemd.user.services.wsl2-ssh-agent = {
37+
description = "WSL2 SSH Agent Bridge";
38+
after = [ "network.target" ];
39+
wantedBy = [ "default.target" ];
40+
unitConfig = {
41+
ConditionUser = lib.join "|" (lib.toList cfg.users);
42+
};
43+
serviceConfig = {
44+
ExecStart = "${cfg.package}/bin/wsl2-ssh-agent --verbose --foreground --socket=%t/wsl2-ssh-agent.sock";
45+
Restart = "on-failure";
46+
};
47+
};
48+
49+
environment.variables.SSH_AUTH_SOCK = "$XDG_RUNTIME_DIR/wsl2-ssh-agent.sock";
50+
};
51+
}

0 commit comments

Comments
 (0)