1 { config, lib, pkgs, ... }:
4 cfg = config.services.autossh;
16 sessions = lib.mkOption {
17 type = lib.types.listOf (lib.types.submodule {
21 example = "socks-peer";
22 description = "Name of the local AutoSSH session";
27 description = "Name of the user the AutoSSH session should run as";
29 monitoringPort = lib.mkOption {
34 Port to be used by AutoSSH for peer monitoring. Note, that
35 AutoSSH also uses mport+1. Value of 0 disables the keep-alive
39 extraArguments = lib.mkOption {
40 type = lib.types.separatedString " ";
41 example = "-N -D4343 bill@socks.example.net";
43 Arguments to be passed to AutoSSH and retransmitted to SSH
44 process. Some meaningful options include -N (don't run remote
45 command), -D (open SOCKS proxy on local port), -R (forward
46 remote port), -L (forward local port), -v (Enable debug). Check
47 ssh manual for the complete list.
55 List of AutoSSH sessions to start as systemd services. Each service is
56 named 'autossh-{session.name}'.
63 monitoringPort = 20000;
64 extraArguments="-N -D4343 billremote@socks.host.net";
75 config = lib.mkIf (cfg.sessions != []) {
79 lib.foldr ( s : acc : acc //
83 mport = if s ? monitoringPort then s.monitoringPort else 0;
86 description = "AutoSSH session (" + s.name + ")";
88 after = [ "network.target" ];
89 wantedBy = [ "multi-user.target" ];
91 # To be able to start the service with no network connection
92 environment.AUTOSSH_GATETIME="0";
94 # How often AutoSSH checks the network, in seconds
95 environment.AUTOSSH_POLL="30";
99 # AutoSSH may exit with 0 code if the SSH session was
100 # gracefully terminated by either local or remote side.
101 Restart = "on-success";
102 ExecStart = "${pkgs.autossh}/bin/autossh -M ${toString mport} ${s.extraArguments}";
107 environment.systemPackages = [ pkgs.autossh ];