diff --git a/modules/programs/ssh.nix b/modules/programs/ssh.nix index f906d1bc7..ee1f0ef36 100644 --- a/modules/programs/ssh.nix +++ b/modules/programs/ssh.nix @@ -15,6 +15,12 @@ let unwords = builtins.concatStringsSep " "; + mkSetEnvStr = envStr: unwords + (mapAttrsToList + (name: value: ''${name}="${escape [ "\"" "\\" ] (toString value)}"'') + envStr + ); + bindOptions = { address = mkOption { type = types.str; @@ -189,6 +195,14 @@ let ''; }; + setEnv = mkOption { + type = with types; attrsOf (oneOf [ str path int float ]); + default = {}; + description = '' + Environment variables and their value to send to the server. + ''; + }; + compression = mkOption { type = types.nullOr types.bool; default = null; @@ -322,6 +336,7 @@ let ++ optional (cf.hostname != null) " HostName ${cf.hostname}" ++ optional (cf.addressFamily != null) " AddressFamily ${cf.addressFamily}" ++ optional (cf.sendEnv != []) " SendEnv ${unwords cf.sendEnv}" + ++ optional (cf.setEnv != {}) " SetEnv ${mkSetEnvStr cf.setEnv}" ++ optional (cf.serverAliveInterval != 0) " ServerAliveInterval ${toString cf.serverAliveInterval}" ++ optional (cf.serverAliveCountMax != 3) diff --git a/tests/modules/programs/ssh/match-blocks-attrs-expected.conf b/tests/modules/programs/ssh/match-blocks-attrs-expected.conf index 1a197b26f..b6b760ce6 100644 --- a/tests/modules/programs/ssh/match-blocks-attrs-expected.conf +++ b/tests/modules/programs/ssh/match-blocks-attrs-expected.conf @@ -5,6 +5,7 @@ Host * !github.com Host abc ProxyJump jump-host Host xyz + SetEnv BAR="_bar_ 42" FOO="foo12" ServerAliveInterval 60 ServerAliveCountMax 10 IdentityFile file diff --git a/tests/modules/programs/ssh/match-blocks-attrs.nix b/tests/modules/programs/ssh/match-blocks-attrs.nix index eaa20c6e3..d8584e3a0 100644 --- a/tests/modules/programs/ssh/match-blocks-attrs.nix +++ b/tests/modules/programs/ssh/match-blocks-attrs.nix @@ -35,6 +35,10 @@ with lib; } ]; dynamicForwards = [{ port = 2839; }]; + setEnv = { + FOO = "foo12"; + BAR = "_bar_ 42"; + }; }; "* !github.com" = {