9 cfg = config.services.autossh;
21 sessions = lib.mkOption {
22 type = lib.types.listOf (
27 example = "socks-peer";
28 description = "Name of the local AutoSSH session";
33 description = "Name of the user the AutoSSH session should run as";
35 monitoringPort = lib.mkOption {
40 Port to be used by AutoSSH for peer monitoring. Note, that
41 AutoSSH also uses mport+1. Value of 0 disables the keep-alive
45 extraArguments = lib.mkOption {
46 type = lib.types.separatedString " ";
47 example = "-N -D4343 bill@socks.example.net";
49 Arguments to be passed to AutoSSH and retransmitted to SSH
50 process. Some meaningful options include -N (don't run remote
51 command), -D (open SOCKS proxy on local port), -R (forward
52 remote port), -L (forward local port), -v (Enable debug). Check
53 ssh manual for the complete list.
62 List of AutoSSH sessions to start as systemd services. Each service is
63 named 'autossh-{session.name}'.
70 monitoringPort = 20000;
71 extraArguments = "-N -D4343 billremote@socks.host.net";
82 config = lib.mkIf (cfg.sessions != [ ]) {
92 mport = if s ? monitoringPort then s.monitoringPort else 0;
95 description = "AutoSSH session (" + s.name + ")";
97 after = [ "network.target" ];
98 wantedBy = [ "multi-user.target" ];
100 # To be able to start the service with no network connection
101 environment.AUTOSSH_GATETIME = "0";
103 # How often AutoSSH checks the network, in seconds
104 environment.AUTOSSH_POLL = "30";
108 # AutoSSH may exit with 0 code if the SSH session was
109 # gracefully terminated by either local or remote side.
110 Restart = "on-success";
111 ExecStart = "${pkgs.autossh}/bin/autossh -M ${toString mport} ${s.extraArguments}";
117 environment.systemPackages = [ pkgs.autossh ];