2017-05-09 05:30:37 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.ssh;
|
|
|
|
|
2019-08-20 13:20:39 +02:00
|
|
|
isPath = x: builtins.substring 0 1 (toString x) == "/";
|
|
|
|
|
|
|
|
addressPort = entry:
|
|
|
|
if isPath entry.address
|
|
|
|
then " ${entry.address}"
|
|
|
|
else " [${entry.address}]:${toString entry.port}";
|
|
|
|
|
2018-11-24 23:40:25 +01:00
|
|
|
unwords = builtins.concatStringsSep " ";
|
|
|
|
|
2023-05-11 14:22:40 +02:00
|
|
|
mkSetEnvStr = envStr: unwords
|
|
|
|
(mapAttrsToList
|
|
|
|
(name: value: ''${name}="${escape [ "\"" "\\" ] (toString value)}"'')
|
|
|
|
envStr
|
|
|
|
);
|
|
|
|
|
2019-08-20 13:20:39 +02:00
|
|
|
bindOptions = {
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
|
|
|
example = "example.org";
|
|
|
|
description = "The address where to bind the port.";
|
|
|
|
};
|
2019-08-02 19:37:45 +02:00
|
|
|
|
2019-08-20 13:20:39 +02:00
|
|
|
port = mkOption {
|
2021-04-27 23:16:33 +02:00
|
|
|
type = types.nullOr types.port;
|
|
|
|
default = null;
|
2019-08-20 13:20:39 +02:00
|
|
|
example = 8080;
|
|
|
|
description = "Specifies port number to bind on bind address.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
dynamicForwardModule = types.submodule {
|
|
|
|
options = bindOptions;
|
|
|
|
};
|
|
|
|
|
|
|
|
forwardModule = types.submodule {
|
|
|
|
options = {
|
|
|
|
bind = bindOptions;
|
2019-08-02 19:37:45 +02:00
|
|
|
|
|
|
|
host = {
|
|
|
|
address = mkOption {
|
2021-04-27 23:16:33 +02:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2019-08-02 19:37:45 +02:00
|
|
|
example = "example.org";
|
|
|
|
description = "The address where to forward the traffic to.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-04-27 23:16:33 +02:00
|
|
|
type = types.nullOr types.port;
|
|
|
|
default = null;
|
2019-08-02 19:37:45 +02:00
|
|
|
example = 80;
|
|
|
|
description = "Specifies port number to forward the traffic to.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2019-08-20 13:20:39 +02:00
|
|
|
};
|
2019-08-02 19:37:45 +02:00
|
|
|
|
2020-04-13 22:02:08 +02:00
|
|
|
matchBlockModule = types.submodule ({ dagName, ... }: {
|
2017-05-09 05:30:37 +02:00
|
|
|
options = {
|
|
|
|
host = mkOption {
|
2022-11-27 16:15:32 +01:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2017-05-09 05:30:37 +02:00
|
|
|
example = "*.example.org";
|
|
|
|
description = ''
|
2022-11-27 16:15:32 +01:00
|
|
|
<literal>Host</literal> pattern used by this conditional block.
|
|
|
|
See
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>ssh_config</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum>
|
|
|
|
</citerefentry>
|
|
|
|
for <literal>Host</literal> block details.
|
|
|
|
This option is ignored if
|
2023-05-18 22:37:19 +02:00
|
|
|
<option>ssh.matchBlocks.*.match</option>
|
2022-11-27 16:15:32 +01:00
|
|
|
if defined.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
match = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "host <hostname> canonical\nhost <hostname> exec \"ping -c1 -q 192.168.17.1\"";
|
|
|
|
description = ''
|
|
|
|
<literal>Match</literal> block conditions used by this block. See
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>ssh_config</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum>
|
|
|
|
</citerefentry>
|
|
|
|
for <literal>Match</literal> block details.
|
|
|
|
This option takes precedence over
|
|
|
|
<option>ssh.matchBlocks.*.host</option>
|
|
|
|
if defined.
|
2017-05-09 05:30:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2019-08-19 20:37:48 +02:00
|
|
|
type = types.nullOr types.port;
|
2017-05-09 05:30:37 +02:00
|
|
|
default = null;
|
|
|
|
description = "Specifies port number to connect on remote host.";
|
|
|
|
};
|
|
|
|
|
2018-11-24 23:40:25 +01:00
|
|
|
forwardAgent = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether the connection to the authentication agent (if any)
|
|
|
|
will be forwarded to the remote machine.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-05-09 05:30:37 +02:00
|
|
|
forwardX11 = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Specifies whether X11 connections will be automatically redirected
|
|
|
|
over the secure channel and <envar>DISPLAY</envar> set.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
forwardX11Trusted = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Specifies whether remote X11 clients will have full access to the
|
|
|
|
original X11 display.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
identitiesOnly = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Specifies that ssh should only use the authentication
|
|
|
|
identity explicitly configured in the
|
|
|
|
<filename>~/.ssh/config</filename> files or passed on the
|
|
|
|
ssh command-line, even if <command>ssh-agent</command>
|
|
|
|
offers more identities.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
identityFile = mkOption {
|
2019-03-19 22:35:13 +01:00
|
|
|
type = with types; either (listOf str) (nullOr str);
|
|
|
|
default = [];
|
|
|
|
apply = p:
|
|
|
|
if p == null then []
|
|
|
|
else if isString p then [p]
|
|
|
|
else p;
|
2017-05-09 05:30:37 +02:00
|
|
|
description = ''
|
2019-03-19 22:35:13 +01:00
|
|
|
Specifies files from which the user identity is read.
|
|
|
|
Identities will be tried in the given order.
|
2017-05-09 05:30:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
2017-05-13 12:23:59 +02:00
|
|
|
type = types.nullOr types.str;
|
2017-05-09 05:30:37 +02:00
|
|
|
default = null;
|
|
|
|
description = "Specifies the user to log in as.";
|
|
|
|
};
|
|
|
|
|
|
|
|
hostname = mkOption {
|
2017-05-13 12:23:59 +02:00
|
|
|
type = types.nullOr types.str;
|
2017-05-09 05:30:37 +02:00
|
|
|
default = null;
|
|
|
|
description = "Specifies the real host name to log into.";
|
|
|
|
};
|
|
|
|
|
|
|
|
serverAliveInterval = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
description =
|
|
|
|
"Set timeout in seconds after which response will be requested.";
|
|
|
|
};
|
|
|
|
|
2020-06-01 16:50:34 +02:00
|
|
|
serverAliveCountMax = mkOption {
|
|
|
|
type = types.ints.positive;
|
|
|
|
default = 3;
|
|
|
|
description = ''
|
|
|
|
Sets the number of server alive messages which may be sent
|
|
|
|
without SSH receiving any messages back from the server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-11-24 23:40:25 +01:00
|
|
|
sendEnv = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Environment variables to send from the local host to the
|
|
|
|
server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-05-11 14:22:40 +02:00
|
|
|
setEnv = mkOption {
|
|
|
|
type = with types; attrsOf (oneOf [ str path int float ]);
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Environment variables and their value to send to the server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-01-06 01:41:44 +01:00
|
|
|
compression = mkOption {
|
2018-01-14 22:06:32 +01:00
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Specifies whether to use compression. Omitted from the host
|
|
|
|
block when <literal>null</literal>.
|
|
|
|
'';
|
2018-01-06 01:41:44 +01:00
|
|
|
};
|
|
|
|
|
2017-05-09 05:30:37 +02:00
|
|
|
checkHostIP = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Check the host IP address in the
|
|
|
|
<filename>known_hosts</filename> file.
|
|
|
|
'';
|
|
|
|
};
|
2017-05-13 12:08:09 +02:00
|
|
|
|
|
|
|
proxyCommand = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "The command to use to connect to the server.";
|
|
|
|
};
|
2018-01-10 16:40:07 +01:00
|
|
|
|
2019-01-15 22:09:16 +01:00
|
|
|
proxyJump = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "The proxy host to use to connect to the server.";
|
|
|
|
};
|
|
|
|
|
2018-12-05 00:14:15 +01:00
|
|
|
certificateFile = mkOption {
|
2020-01-19 23:33:54 +01:00
|
|
|
type = with types; either (listOf str) (nullOr str);
|
|
|
|
default = [];
|
|
|
|
apply = p:
|
|
|
|
if p == null then []
|
|
|
|
else if isString p then [p]
|
|
|
|
else p;
|
2018-12-05 00:14:15 +01:00
|
|
|
description = ''
|
2020-01-19 23:33:54 +01:00
|
|
|
Specifies files from which the user certificate is read.
|
2018-12-05 00:14:15 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-12-04 05:05:58 +01:00
|
|
|
addressFamily = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr (types.enum ["any" "inet" "inet6"]);
|
|
|
|
description = ''
|
|
|
|
Specifies which address family to use when connecting.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-08-02 19:37:45 +02:00
|
|
|
localForwards = mkOption {
|
2019-08-20 13:20:39 +02:00
|
|
|
type = types.listOf forwardModule;
|
2019-08-02 19:37:45 +02:00
|
|
|
default = [];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2019-08-02 19:37:45 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
bind.port = 8080;
|
|
|
|
host.address = "10.0.0.13";
|
|
|
|
host.port = 80;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Specify local port forwardings. See
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>ssh_config</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum>
|
2019-08-20 13:20:39 +02:00
|
|
|
</citerefentry> for <literal>LocalForward</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
remoteForwards = mkOption {
|
|
|
|
type = types.listOf forwardModule;
|
|
|
|
default = [];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2019-08-20 13:20:39 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
bind.port = 8080;
|
|
|
|
host.address = "10.0.0.13";
|
|
|
|
host.port = 80;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Specify remote port forwardings. See
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>ssh_config</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum>
|
|
|
|
</citerefentry> for <literal>RemoteForward</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dynamicForwards = mkOption {
|
|
|
|
type = types.listOf dynamicForwardModule;
|
|
|
|
default = [];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2019-08-20 13:20:39 +02:00
|
|
|
[ { port = 8080; } ];
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Specify dynamic port forwardings. See
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>ssh_config</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum>
|
|
|
|
</citerefentry> for <literal>DynamicForward</literal>.
|
2019-08-02 19:37:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-01-10 16:40:07 +01:00
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
description = "Extra configuration options for the host.";
|
|
|
|
};
|
2017-05-09 05:30:37 +02:00
|
|
|
};
|
2017-09-10 13:59:59 +02:00
|
|
|
|
2022-11-27 16:15:32 +01:00
|
|
|
# config.host = mkDefault dagName;
|
2017-09-10 13:59:59 +02:00
|
|
|
});
|
2017-05-09 05:30:37 +02:00
|
|
|
|
2022-11-27 16:15:32 +01:00
|
|
|
matchBlockStr = key: cf: concatStringsSep "\n" (
|
|
|
|
let
|
|
|
|
hostOrDagName = if cf.host != null then cf.host else key;
|
|
|
|
matchHead = if cf.match != null
|
|
|
|
then "Match ${cf.match}"
|
|
|
|
else "Host ${hostOrDagName}";
|
|
|
|
in [ "${matchHead}" ]
|
2018-12-05 00:14:15 +01:00
|
|
|
++ optional (cf.port != null) " Port ${toString cf.port}"
|
2022-04-08 06:36:13 +02:00
|
|
|
++ optional (cf.forwardAgent != null) " ForwardAgent ${lib.hm.booleans.yesNo cf.forwardAgent}"
|
2018-12-05 00:14:15 +01:00
|
|
|
++ optional cf.forwardX11 " ForwardX11 yes"
|
|
|
|
++ optional cf.forwardX11Trusted " ForwardX11Trusted yes"
|
|
|
|
++ optional cf.identitiesOnly " IdentitiesOnly yes"
|
|
|
|
++ optional (cf.user != null) " User ${cf.user}"
|
|
|
|
++ optional (cf.hostname != null) " HostName ${cf.hostname}"
|
2018-12-04 05:05:58 +01:00
|
|
|
++ optional (cf.addressFamily != null) " AddressFamily ${cf.addressFamily}"
|
2018-12-05 00:14:15 +01:00
|
|
|
++ optional (cf.sendEnv != []) " SendEnv ${unwords cf.sendEnv}"
|
2023-05-11 14:22:40 +02:00
|
|
|
++ optional (cf.setEnv != {}) " SetEnv ${mkSetEnvStr cf.setEnv}"
|
2017-05-09 05:30:37 +02:00
|
|
|
++ optional (cf.serverAliveInterval != 0)
|
2020-06-01 16:50:34 +02:00
|
|
|
" ServerAliveInterval ${toString cf.serverAliveInterval}"
|
|
|
|
++ optional (cf.serverAliveCountMax != 3)
|
|
|
|
" ServerAliveCountMax ${toString cf.serverAliveCountMax}"
|
2022-04-08 06:36:13 +02:00
|
|
|
++ optional (cf.compression != null) " Compression ${lib.hm.booleans.yesNo cf.compression}"
|
2018-12-05 00:14:15 +01:00
|
|
|
++ optional (!cf.checkHostIP) " CheckHostIP no"
|
|
|
|
++ optional (cf.proxyCommand != null) " ProxyCommand ${cf.proxyCommand}"
|
2019-01-15 22:09:16 +01:00
|
|
|
++ optional (cf.proxyJump != null) " ProxyJump ${cf.proxyJump}"
|
2019-03-19 22:35:13 +01:00
|
|
|
++ map (file: " IdentityFile ${file}") cf.identityFile
|
2020-01-19 23:33:54 +01:00
|
|
|
++ map (file: " CertificateFile ${file}") cf.certificateFile
|
2019-08-20 13:20:39 +02:00
|
|
|
++ map (f: " LocalForward" + addressPort f.bind + addressPort f.host) cf.localForwards
|
|
|
|
++ map (f: " RemoteForward" + addressPort f.bind + addressPort f.host) cf.remoteForwards
|
|
|
|
++ map (f: " DynamicForward" + addressPort f) cf.dynamicForwards
|
2018-01-10 16:40:07 +01:00
|
|
|
++ mapAttrsToList (n: v: " ${n} ${v}") cf.extraOptions
|
2017-05-09 05:30:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2017-09-26 23:40:31 +02:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2017-05-09 05:30:37 +02:00
|
|
|
options.programs.ssh = {
|
|
|
|
enable = mkEnableOption "SSH client configuration";
|
|
|
|
|
2023-05-27 14:11:50 +02:00
|
|
|
package = mkPackageOption pkgs "openssh" {
|
|
|
|
nullable = true;
|
|
|
|
default = null;
|
|
|
|
extraDescription = "By default, the client provided by your system is used.";
|
|
|
|
};
|
2023-02-10 21:55:17 +01:00
|
|
|
|
2017-05-09 05:30:37 +02:00
|
|
|
forwardAgent = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
2018-11-24 23:40:25 +01:00
|
|
|
Whether the connection to the authentication agent (if any)
|
|
|
|
will be forwarded to the remote machine.
|
2017-05-09 05:30:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-01-06 01:41:44 +01:00
|
|
|
compression = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = "Specifies whether to use compression.";
|
|
|
|
};
|
|
|
|
|
|
|
|
serverAliveInterval = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
description = ''
|
|
|
|
Set default timeout in seconds after which response will be requested.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-06-01 16:50:34 +02:00
|
|
|
serverAliveCountMax = mkOption {
|
|
|
|
type = types.ints.positive;
|
|
|
|
default = 3;
|
|
|
|
description = ''
|
|
|
|
Sets the default number of server alive messages which may be
|
|
|
|
sent without SSH receiving any messages back from the server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-01-06 01:41:44 +01:00
|
|
|
hashKnownHosts = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Indicates that
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>ssh</refentrytitle>
|
|
|
|
<manvolnum>1</manvolnum>
|
|
|
|
</citerefentry>
|
|
|
|
should hash host names and addresses when they are added to
|
|
|
|
the known hosts file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
userKnownHostsFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "~/.ssh/known_hosts";
|
|
|
|
description = ''
|
|
|
|
Specifies one or more files to use for the user host key
|
|
|
|
database, separated by whitespace. The default is
|
|
|
|
<filename>~/.ssh/known_hosts</filename>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-05-09 05:30:37 +02:00
|
|
|
controlMaster = mkOption {
|
|
|
|
default = "no";
|
|
|
|
type = types.enum ["yes" "no" "ask" "auto" "autoask"];
|
|
|
|
description = ''
|
|
|
|
Configure sharing of multiple sessions over a single network connection.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
controlPath = mkOption {
|
2017-05-13 12:23:59 +02:00
|
|
|
type = types.str;
|
2018-11-28 15:24:19 +01:00
|
|
|
default = "~/.ssh/master-%r@%n:%p";
|
2017-05-09 05:30:37 +02:00
|
|
|
description = ''
|
|
|
|
Specify path to the control socket used for connection sharing.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-07-29 17:47:18 +02:00
|
|
|
controlPersist = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "no";
|
|
|
|
example = "10m";
|
|
|
|
description = ''
|
|
|
|
Whether control socket should remain open in the background.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-01-10 16:40:07 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-23 19:32:02 +01:00
|
|
|
extraOptionOverrides = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Extra SSH configuration options that take precedence over any
|
|
|
|
host specific configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-11-16 19:51:10 +01:00
|
|
|
includes = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
File globs of ssh config files that should be included via the
|
|
|
|
<literal>Include</literal> directive.
|
|
|
|
</para><para>
|
|
|
|
See
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>ssh_config</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum>
|
|
|
|
</citerefentry>
|
|
|
|
for more information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-05-09 05:30:37 +02:00
|
|
|
matchBlocks = mkOption {
|
2020-04-13 22:02:08 +02:00
|
|
|
type = hm.types.listOrDagOf matchBlockModule;
|
2018-03-23 19:32:02 +01:00
|
|
|
default = {};
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2017-09-10 13:59:59 +02:00
|
|
|
{
|
|
|
|
"john.example.com" = {
|
|
|
|
hostname = "example.com";
|
|
|
|
user = "john";
|
|
|
|
};
|
2020-04-13 22:02:08 +02:00
|
|
|
foo = lib.hm.dag.entryBefore ["john.example.com"] {
|
2017-09-10 13:59:59 +02:00
|
|
|
hostname = "example.com";
|
|
|
|
identityFile = "/home/john/.ssh/foo_rsa";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
2017-05-09 05:30:37 +02:00
|
|
|
description = ''
|
2017-09-10 13:59:59 +02:00
|
|
|
Specify per-host settings. Note, if the order of rules matter
|
2020-04-13 22:02:08 +02:00
|
|
|
then use the DAG functions to express the dependencies as
|
|
|
|
shown in the example.
|
|
|
|
</para><para>
|
|
|
|
See
|
2017-09-10 13:59:59 +02:00
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>ssh_config</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum>
|
2020-04-13 22:02:08 +02:00
|
|
|
</citerefentry>
|
|
|
|
for more information.
|
2017-05-09 05:30:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-08-20 13:20:39 +02:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion =
|
|
|
|
let
|
|
|
|
# `builtins.any`/`lib.lists.any` does not return `true` if there are no elements.
|
|
|
|
any' = pred: items: if items == [] then true else any pred items;
|
|
|
|
# Check that if `entry.address` is defined, and is a path, that `entry.port` has not
|
|
|
|
# been defined.
|
2021-04-27 23:16:33 +02:00
|
|
|
noPathWithPort = entry: entry.address != null && isPath entry.address -> entry.port == null;
|
2019-08-20 13:20:39 +02:00
|
|
|
checkDynamic = block: any' noPathWithPort block.dynamicForwards;
|
|
|
|
checkBindAndHost = fwd: noPathWithPort fwd.bind && noPathWithPort fwd.host;
|
|
|
|
checkLocal = block: any' checkBindAndHost block.localForwards;
|
|
|
|
checkRemote = block: any' checkBindAndHost block.remoteForwards;
|
|
|
|
checkMatchBlock = block: all (fn: fn block) [ checkLocal checkRemote checkDynamic ];
|
2020-04-13 22:02:08 +02:00
|
|
|
in any' checkMatchBlock (map (block: block.data) (builtins.attrValues cfg.matchBlocks));
|
2019-08-20 13:20:39 +02:00
|
|
|
message = "Forwarded paths cannot have ports.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-05-27 14:11:50 +02:00
|
|
|
home.packages = optional (cfg.package != null) cfg.package;
|
2023-02-10 21:55:17 +01:00
|
|
|
|
2020-04-13 22:02:08 +02:00
|
|
|
home.file.".ssh/config".text =
|
|
|
|
let
|
|
|
|
sortedMatchBlocks = hm.dag.topoSort cfg.matchBlocks;
|
|
|
|
sortedMatchBlocksStr = builtins.toJSON sortedMatchBlocks;
|
|
|
|
matchBlocks =
|
|
|
|
if sortedMatchBlocks ? result
|
|
|
|
then sortedMatchBlocks.result
|
|
|
|
else abort "Dependency cycle in SSH match blocks: ${sortedMatchBlocksStr}";
|
|
|
|
in ''
|
2018-03-23 19:32:02 +01:00
|
|
|
${concatStringsSep "\n" (
|
2021-11-16 19:51:10 +01:00
|
|
|
(mapAttrsToList (n: v: "${n} ${v}") cfg.extraOptionOverrides)
|
|
|
|
++ (optional (cfg.includes != [ ]) ''
|
|
|
|
Include ${concatStringsSep " " cfg.includes}
|
|
|
|
'')
|
2022-11-27 16:15:32 +01:00
|
|
|
++ (map (block: matchBlockStr block.name block.data) matchBlocks)
|
2021-11-16 19:51:10 +01:00
|
|
|
)}
|
2018-03-23 19:32:02 +01:00
|
|
|
|
|
|
|
Host *
|
2022-04-08 06:36:13 +02:00
|
|
|
ForwardAgent ${lib.hm.booleans.yesNo cfg.forwardAgent}
|
|
|
|
Compression ${lib.hm.booleans.yesNo cfg.compression}
|
2018-03-23 19:32:02 +01:00
|
|
|
ServerAliveInterval ${toString cfg.serverAliveInterval}
|
2020-06-01 16:50:34 +02:00
|
|
|
ServerAliveCountMax ${toString cfg.serverAliveCountMax}
|
2022-04-08 06:36:13 +02:00
|
|
|
HashKnownHosts ${lib.hm.booleans.yesNo cfg.hashKnownHosts}
|
2018-03-23 19:32:02 +01:00
|
|
|
UserKnownHostsFile ${cfg.userKnownHostsFile}
|
|
|
|
ControlMaster ${cfg.controlMaster}
|
|
|
|
ControlPath ${cfg.controlPath}
|
|
|
|
ControlPersist ${cfg.controlPersist}
|
|
|
|
|
|
|
|
${replaceStrings ["\n"] ["\n "] cfg.extraConfig}
|
2017-05-09 05:30:37 +02:00
|
|
|
'';
|
2022-11-27 16:15:32 +01:00
|
|
|
|
|
|
|
warnings = mapAttrsToList
|
|
|
|
(n: v: "The SSH config match block `programs.ssh.matchBlocks.${n}` sets both of the host and match options.\nThe match option takes precedence.")
|
|
|
|
(filterAttrs (n: v: v.data.host != null && v.data.match != null) cfg.matchBlocks);
|
2017-05-09 05:30:37 +02:00
|
|
|
};
|
|
|
|
}
|