Skip to content

Commit 6b25f06

Browse files
authored
Merge pull request #253147 from SuperSandro2000/ssh-forwardx11
nixos/ssh: add variant to not set ForwardX11
2 parents fa5d6d1 + 88946fe commit 6b25f06

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

nixos/modules/programs/ssh.nix

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ let
88

99
cfg = config.programs.ssh;
1010

11-
askPassword = cfg.askPassword;
12-
1311
askPasswordWrapper = pkgs.writeScript "ssh-askpass-wrapper"
1412
''
1513
#! ${pkgs.runtimeShell} -e
1614
export DISPLAY="$(systemctl --user show-environment | ${pkgs.gnused}/bin/sed 's/^DISPLAY=\(.*\)/\1/; t; d')"
1715
export WAYLAND_DISPLAY="$(systemctl --user show-environment | ${pkgs.gnused}/bin/sed 's/^WAYLAND_DISPLAY=\(.*\)/\1/; t; d')"
18-
exec ${askPassword} "$@"
16+
exec ${cfg.askPassword} "$@"
1917
'';
2018

2119
knownHosts = attrValues cfg.knownHosts;
@@ -52,10 +50,11 @@ in
5250
};
5351

5452
forwardX11 = mkOption {
55-
type = types.bool;
53+
type = with lib.types; nullOr bool;
5654
default = false;
5755
description = lib.mdDoc ''
5856
Whether to request X11 forwarding on outgoing connections by default.
57+
If set to null, the option is not set at all.
5958
This is useful for running graphical programs on the remote machine and have them display to your local X11 server.
6059
Historically, this value has depended on the value used by the local sshd daemon, but there really isn't a relation between the two.
6160
Note: there are some security risks to forwarding an X11 connection.
@@ -274,10 +273,10 @@ in
274273
config = {
275274

276275
programs.ssh.setXAuthLocation =
277-
mkDefault (config.services.xserver.enable || config.programs.ssh.forwardX11 || config.services.openssh.settings.X11Forwarding);
276+
mkDefault (config.services.xserver.enable || config.programs.ssh.forwardX11 == true || config.services.openssh.settings.X11Forwarding);
278277

279278
assertions =
280-
[ { assertion = cfg.forwardX11 -> cfg.setXAuthLocation;
279+
[ { assertion = cfg.forwardX11 == true -> cfg.setXAuthLocation;
281280
message = "cannot enable X11 forwarding without setting XAuth location";
282281
}
283282
] ++ flip mapAttrsToList cfg.knownHosts (name: data: {
@@ -298,11 +297,8 @@ in
298297
AddressFamily ${if config.networking.enableIPv6 then "any" else "inet"}
299298
GlobalKnownHostsFile ${concatStringsSep " " knownHostsFiles}
300299
301-
${optionalString cfg.setXAuthLocation ''
302-
XAuthLocation ${pkgs.xorg.xauth}/bin/xauth
303-
''}
304-
305-
ForwardX11 ${if cfg.forwardX11 then "yes" else "no"}
300+
${optionalString cfg.setXAuthLocation "XAuthLocation ${pkgs.xorg.xauth}/bin/xauth"}
301+
${lib.optionalString (cfg.forwardX11 != null) "ForwardX11 ${if cfg.forwardX11 then "yes" else "no"}"}
306302
307303
${optionalString (cfg.pubkeyAcceptedKeyTypes != []) "PubkeyAcceptedKeyTypes ${concatStringsSep "," cfg.pubkeyAcceptedKeyTypes}"}
308304
${optionalString (cfg.hostKeyAlgorithms != []) "HostKeyAlgorithms ${concatStringsSep "," cfg.hostKeyAlgorithms}"}
@@ -344,7 +340,7 @@ in
344340
fi
345341
'';
346342

347-
environment.variables.SSH_ASKPASS = optionalString cfg.enableAskPassword askPassword;
343+
environment.variables.SSH_ASKPASS = optionalString cfg.enableAskPassword cfg.askPassword;
348344

349345
};
350346
}

0 commit comments

Comments
 (0)