ssh: allow attrset matchBlock

This commit is contained in:
Silvan Mosberger 2017-09-10 13:59:59 +02:00 committed by Robert Helgesson
parent cda222d2ec
commit fc1d4f5362
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -8,7 +8,7 @@ let
yn = flag: if flag then "yes" else "no"; yn = flag: if flag then "yes" else "no";
matchBlockModule = types.submodule { matchBlockModule = types.submodule ({ name, ... }: {
options = { options = {
host = mkOption { host = mkOption {
type = types.str; type = types.str;
@ -96,7 +96,9 @@ let
description = "The command to use to connect to the server."; description = "The command to use to connect to the server.";
}; };
}; };
};
config.host = mkDefault name;
});
matchBlockStr = cf: concatStringsSep "\n" ( matchBlockStr = cf: concatStringsSep "\n" (
["Host ${cf.host}"] ["Host ${cf.host}"]
@ -154,10 +156,27 @@ in
}; };
matchBlocks = mkOption { matchBlocks = mkOption {
type = types.listOf matchBlockModule; type = types.loaOf matchBlockModule;
default = []; default = [];
example = literalExample ''
{
"john.example.com" = {
hostname = "example.com";
user = "john";
};
foo = {
hostname = "example.com";
identityFile = "/home/john/.ssh/foo_rsa";
};
};
'';
description = '' description = ''
Specify per-host settings. Specify per-host settings. Note, if the order of rules matter
then this must be a list. See
<citerefentry>
<refentrytitle>ssh_config</refentrytitle>
<manvolnum>5</manvolnum>
</citerefentry>.
''; '';
}; };
}; };
@ -169,7 +188,9 @@ in
ControlPath ${cfg.controlPath} ControlPath ${cfg.controlPath}
ControlPersist ${cfg.controlPersist} ControlPersist ${cfg.controlPersist}
${concatStringsSep "\n\n" (map matchBlockStr cfg.matchBlocks)} ${concatStringsSep "\n\n" (
map matchBlockStr (
builtins.attrValues cfg.matchBlocks))}
''; '';
}; };
} }