Skip to content

Commit

Permalink
programs.ssh: Use nullable types for optional forward attrs (#1946)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tadfisher authored Apr 27, 2021
1 parent d437baa commit 18ad12d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions modules/programs/ssh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
};
Expand All @@ -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.";
};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 18ad12d

Please sign in to comment.