Skip to content

Commit 88946fe

Browse files
nixos/ssh: add variant to not set ForwardX11
ssh_config allows a setting to only be set once and if more complex conditions are used than having ForwardX11 already defined can be a problem.
1 parent 7eff362 commit 88946fe

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

nixos/modules/programs/ssh.nix

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ in
5050
};
5151

5252
forwardX11 = mkOption {
53-
type = types.bool;
53+
type = with lib.types; nullOr bool;
5454
default = false;
5555
description = lib.mdDoc ''
5656
Whether to request X11 forwarding on outgoing connections by default.
57+
If set to null, the option is not set at all.
5758
This is useful for running graphical programs on the remote machine and have them display to your local X11 server.
5859
Historically, this value has depended on the value used by the local sshd daemon, but there really isn't a relation between the two.
5960
Note: there are some security risks to forwarding an X11 connection.
@@ -279,10 +280,10 @@ in
279280
config = {
280281

281282
programs.ssh.setXAuthLocation =
282-
mkDefault (config.services.xserver.enable || config.programs.ssh.forwardX11 || config.services.openssh.settings.X11Forwarding);
283+
mkDefault (config.services.xserver.enable || config.programs.ssh.forwardX11 == true || config.services.openssh.settings.X11Forwarding);
283284

284285
assertions =
285-
[ { assertion = cfg.forwardX11 -> cfg.setXAuthLocation;
286+
[ { assertion = cfg.forwardX11 == true -> cfg.setXAuthLocation;
286287
message = "cannot enable X11 forwarding without setting XAuth location";
287288
}
288289
] ++ flip mapAttrsToList cfg.knownHosts (name: data: {
@@ -303,11 +304,8 @@ in
303304
AddressFamily ${if config.networking.enableIPv6 then "any" else "inet"}
304305
GlobalKnownHostsFile ${concatStringsSep " " knownHostsFiles}
305306
306-
${optionalString cfg.setXAuthLocation ''
307-
XAuthLocation ${pkgs.xorg.xauth}/bin/xauth
308-
''}
309-
310-
ForwardX11 ${if cfg.forwardX11 then "yes" else "no"}
307+
${optionalString cfg.setXAuthLocation "XAuthLocation ${pkgs.xorg.xauth}/bin/xauth"}
308+
${lib.optionalString (cfg.forwardX11 != null) "ForwardX11 ${if cfg.forwardX11 then "yes" else "no"}"}
311309
312310
${optionalString (cfg.pubkeyAcceptedKeyTypes != []) "PubkeyAcceptedKeyTypes ${concatStringsSep "," cfg.pubkeyAcceptedKeyTypes}"}
313311
${optionalString (cfg.hostKeyAlgorithms != []) "HostKeyAlgorithms ${concatStringsSep "," cfg.hostKeyAlgorithms}"}

0 commit comments

Comments
 (0)