From 18ad12d52b8cebbb57013865eec2be5125de050a Mon Sep 17 00:00:00 2001 From: Tad Fisher <129148+tadfisher@users.noreply.github.com> Date: Tue, 27 Apr 2021 14:16:33 -0700 Subject: [PATCH] programs.ssh: Use nullable types for optional forward attrs (#1946) Attempting to build a flake configuration using `ssh.remoteForwards' results in evaluation errors when `port' is undefined, as `!(entry ? port)' evaluates to false. This was verified in the nix repl, and also occurs for `nix flake check'. Set optional attrs in `bindOptions' and `forwardModule' to `null' by default and adjust the assertion to check for `null' instead of attr definitions. --- modules/programs/ssh.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/programs/ssh.nix b/modules/programs/ssh.nix index ae1f2218..b4940cbf 100644 --- a/modules/programs/ssh.nix +++ b/modules/programs/ssh.nix @@ -26,7 +26,8 @@ let }; port = mkOption { - type = types.port; + type = types.nullOr types.port; + default = null; example = 8080; description = "Specifies port number to bind on bind address."; }; @@ -42,13 +43,15 @@ let host = { address = mkOption { - type = types.str; + type = types.nullOr types.str; + default = null; example = "example.org"; description = "The address where to forward the traffic to."; }; port = mkOption { - type = types.port; + type = types.nullOr types.port; + default = null; example = 80; description = "Specifies port number to forward the traffic to."; }; @@ -450,7 +453,7 @@ in any' = pred: items: if items == [] then true else any pred items; # Check that if `entry.address` is defined, and is a path, that `entry.port` has not # been defined. - noPathWithPort = entry: entry ? address && isPath entry.address -> !(entry ? port); + noPathWithPort = entry: entry.address != null && isPath entry.address -> entry.port == null; checkDynamic = block: any' noPathWithPort block.dynamicForwards; checkBindAndHost = fwd: noPathWithPort fwd.bind && noPathWithPort fwd.host; checkLocal = block: any' checkBindAndHost block.localForwards;