programs/ssh: use 'toKeyValue' for 'extraOptions'

A first step towards refactoring the module.

Unfortunately the config is not consistent in using comma-separated
values or repeated keys for lists, since the user can always add commas
by themselves, we should default to repeated keys in the generator.
This commit is contained in:
Bruno BELANYI 2025-12-03 14:25:11 +00:00 committed by Austin Horstman
parent 43173abcb4
commit 28741978a3
7 changed files with 19 additions and 1 deletions

View file

@ -451,7 +451,13 @@ let
++ 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
++ mapAttrsToList (n: v: " ${n} ${v}") cf.extraOptions
++ [
(lib.generators.toKeyValue {
mkKeyValue = lib.generators.mkKeyValueDefault { } " ";
listsAsDuplicateKeys = true;
indent = " ";
} cf.extraOptions)
]
);
in

View file

@ -1,7 +1,9 @@
Host dynamicBindAddressWithPort
DynamicForward [127.0.0.1]:3000
Host dynamicBindPathNoPort
DynamicForward /run/user/1000/gnupg/S.gpg-agent.extra

View file

@ -2,8 +2,10 @@ Host * !github.com
Port 516
IdentityFile file1
IdentityFile file2
Host abc
ProxyJump jump-host
Host xyz
SetEnv BAR="_bar_ 42" FOO="foo12"
ServerAliveInterval 60
@ -13,8 +15,10 @@ Host xyz
RemoteForward [localhost]:8081 [10.0.0.2]:80
RemoteForward /run/user/1000/gnupg/S.gpg-agent.extra /run/user/1000/gnupg/S.gpg-agent
DynamicForward [localhost]:2839
Host ordered
Port 1

View file

@ -1,9 +1,12 @@
Host * !github.com
Port 516
Host abc
Port 2222
Match host xyz canonical
Port 2223

View file

@ -11,4 +11,5 @@ Host *
ControlMaster no
ControlPath ~/.ssh/master-%r@%n:%p
ControlPersist no

View file

@ -11,6 +11,7 @@ Host *
ControlMaster no
ControlPath ~/.ssh/master-%r@%n:%p
ControlPersist no
MyExtraOption no
AnotherOption 3

View file

@ -11,4 +11,5 @@ Host *
ControlMaster yes
ControlPath ~/.ssh/myfile-%r@%n:%p
ControlPersist 10m