Skip to content

Commit 02f0864

Browse files
committed
ssh: fix indentation of generated config
1 parent 211bcaa commit 02f0864

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

modules/common/programs/terminal/tools/ssh/default.nix

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ let
2525
# Assume standard UID 1000 for primary users, or use a default
2626
remote-user-id = "1000";
2727

28-
forward-gpg = lib.optionalString (config.programs.gnupg.agent.enable && remote.gpgAgent) ''
29-
RemoteForward /run/user/${remote-user-id}/gnupg/S.gpg-agent /run/user/${user-id}/gnupg/S.gpg-agent.extra
30-
RemoteForward /run/user/${remote-user-id}/gnupg/S.gpg-agent.ssh /run/user/${user-id}/gnupg/S.gpg-agent.ssh
31-
'';
32-
port-expr = if remote.system == "nixos" then "Port ${builtins.toString cfg.port}" else "";
28+
forward-gpg =
29+
lib.optionalString (config.programs.gnupg.agent.enable && remote.gpgAgent)
30+
" RemoteForward /run/user/${remote-user-id}/gnupg/S.gpg-agent /run/user/${user-id}/gnupg/S.gpg-agent.extra\n RemoteForward /run/user/${remote-user-id}/gnupg/S.gpg-agent.ssh /run/user/${user-id}/gnupg/S.gpg-agent.ssh";
31+
port-expr = lib.optionalString (remote.system == "nixos") " Port ${builtins.toString cfg.port}";
3332
in
34-
''
35-
Host ${name}
36-
Hostname ${remote.hostname}
37-
User ${remote-user-name}
38-
ForwardAgent yes
39-
${port-expr}
40-
${forward-gpg}
41-
''
33+
lib.concatStringsSep "\n" (
34+
lib.filter (x: x != "") [
35+
"Host ${name}"
36+
" Hostname ${remote.hostname}"
37+
" User ${remote-user-name}"
38+
" ForwardAgent yes"
39+
port-expr
40+
forward-gpg
41+
]
42+
)
4243
) (builtins.attrNames other-hosts);
4344
in
4445
{
@@ -51,9 +52,12 @@ in
5152
config = lib.mkIf cfg.enable {
5253
programs.ssh = {
5354
extraConfig = ''
54-
${other-hosts-config}
55+
# Custom options from `extraConfig`, to override generated options
56+
${other-hosts-config}${
57+
lib.optionalString (cfg.extraConfig != "") ''
5558
56-
${cfg.extraConfig}
59+
${cfg.extraConfig}''
60+
}
5761
'';
5862

5963
knownHosts = lib.mapAttrs (_: lib.mkForce) (

0 commit comments

Comments
 (0)