From 4b09df1809ad3ae19a3b455363c20b63c621b018 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Sun, 10 Sep 2017 13:59:59 +0200 Subject: [PATCH] ssh: allow attrset matchBlock (cherry picked from commit fc1d4f5362656f161af10be1eba6c68357b66f03) --- modules/programs/ssh.nix | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/modules/programs/ssh.nix b/modules/programs/ssh.nix index e166f49b5..3f1d35db9 100644 --- a/modules/programs/ssh.nix +++ b/modules/programs/ssh.nix @@ -8,7 +8,7 @@ let yn = flag: if flag then "yes" else "no"; - matchBlockModule = types.submodule { + matchBlockModule = types.submodule ({ name, ... }: { options = { host = mkOption { type = types.str; @@ -96,7 +96,9 @@ let description = "The command to use to connect to the server."; }; }; - }; + + config.host = mkDefault name; + }); matchBlockStr = cf: concatStringsSep "\n" ( ["Host ${cf.host}"] @@ -154,10 +156,27 @@ in }; matchBlocks = mkOption { - type = types.listOf matchBlockModule; + type = types.loaOf matchBlockModule; default = []; + example = literalExample '' + { + "john.example.com" = { + hostname = "example.com"; + user = "john"; + }; + foo = { + hostname = "example.com"; + identityFile = "/home/john/.ssh/foo_rsa"; + }; + }; + ''; description = '' - Specify per-host settings. + Specify per-host settings. Note, if the order of rules matter + then this must be a list. See + + ssh_config + 5 + . ''; }; }; @@ -169,7 +188,9 @@ in ControlPath ${cfg.controlPath} ControlPersist ${cfg.controlPersist} - ${concatStringsSep "\n\n" (map matchBlockStr cfg.matchBlocks)} + ${concatStringsSep "\n\n" ( + map matchBlockStr ( + builtins.attrValues cfg.matchBlocks))} ''; }; }