Skip to content

Commit fa6ba97

Browse files
authored
deploy_nixos: add var.target_port (#34)
1 parent 4979e66 commit fa6ba97

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

deploy_nixos/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ variable "target_host" {
77
description = "DNS host to deploy to"
88
}
99

10+
variable "target_port" {
11+
description = "SSH port used to connect to the target_host"
12+
type = number
13+
default = 22
14+
}
15+
1016
variable "ssh_private_key_file" {
1117
description = "Path to private key used to connect to the target_host. Ignored if `-` or empty."
1218
default = "-"
@@ -113,6 +119,7 @@ resource "null_resource" "deploy_nixos" {
113119
connection {
114120
type = "ssh"
115121
host = var.target_host
122+
port = var.target_port
116123
user = var.target_user
117124
agent = var.ssh_agent
118125
timeout = "100s"
@@ -155,6 +162,7 @@ resource "null_resource" "deploy_nixos" {
155162
data.external.nixos-instantiate.result["drv_path"],
156163
data.external.nixos-instantiate.result["out_path"],
157164
"${var.target_user}@${var.target_host}",
165+
"${var.target_port}",
158166
local.build_on_target,
159167
local.ssh_private_key_file,
160168
"switch",

deploy_nixos/nixos-deploy.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ sshOpts=(
3030
drvPath="$1"
3131
outPath="$2"
3232
targetHost="$3"
33-
buildOnTarget="$4"
34-
sshPrivateKeyFile="$5"
35-
action="$6"
36-
shift 6
33+
targetPort="$4"
34+
buildOnTarget="$5"
35+
sshPrivateKeyFile="$6"
36+
action="$7"
37+
shift 7
3738

3839
# remove the last argument
3940
set -- "${@:1:$(($# - 1))}"
4041
buildArgs+=("$@")
4142

43+
sshOpts+=( -p "${targetPort}" )
44+
4245
if [[ -n "${sshPrivateKeyFile}" && "${sshPrivateKeyFile}" != "-" ]]; then
4346
sshOpts+=( -o "IdentityFile=${sshPrivateKeyFile}" )
4447
fi

0 commit comments

Comments
 (0)