Skip to content

Commit

Permalink
deploy_nixos: support concurrency when copying closures
Browse files Browse the repository at this point in the history
  • Loading branch information
denbeigh2000 committed Aug 4, 2024
1 parent 8c2cdd6 commit 227cfbd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions deploy_nixos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ see also:
| config\_pwd | Directory to evaluate the configuration in. This argument is required if 'config' is given | `string` | `""` | no |
| extra\_build\_args | List of arguments to pass to the nix builder | `list(string)` | `[]` | no |
| extra\_eval\_args | List of arguments to pass to the nix evaluation | `list(string)` | `[]` | no |
| closure\_copy\_concurrency | Concurrency used when transferring derivations to the remote host | `number` | `1` | no |
| hermetic | Treat the provided nixos configuration as a hermetic expression and do not evaluate using the ambient system nixpkgs. Useful if you customize eval-modules or use a pinned nixpkgs. | `bool` | false | no |
| flake | Treat the provided nixos_config as the name of the NixOS configuration to use in the flake located in the current directory. Useful if you customize eval-modules or use a pinned nixpkgs. | `bool` | false | no |
| keys | A map of filename to content to upload as secrets in /var/keys | `map(string)` | `{}` | no |
Expand Down
7 changes: 7 additions & 0 deletions deploy_nixos/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ variable "extra_build_args" {
default = []
}

variable "closure_copy_concurrency" {
type = number
description = "Concurrency to apply when copying derivations to the target_host"
default = 1
}

variable "build_on_target" {
type = string
description = "Avoid building on the deployer. Must be true or false. Has no effect when deploying from an incompatible system. Unlike remote builders, this does not require the deploying user to be trusted by its host."
Expand Down Expand Up @@ -198,6 +204,7 @@ resource "null_resource" "deploy_nixos" {
local.ssh_private_key == "" ? "-" : local.ssh_private_key,
"switch",
var.delete_older_than,
var.closure_copy_concurrency,
],
local.extra_build_args
)
Expand Down
7 changes: 4 additions & 3 deletions deploy_nixos/nixos-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# nixos-deploy deploys a nixos-instantiate-generated drvPath to a target host
#
# Usage: nixos-deploy.sh <drvPath> <host> <switch-action> <deleteOlderThan> [<build-opts>] ignoreme
# Usage: nixos-deploy.sh <drvPath> <host> <switch-action> <deleteOlderThan> <copyConcurrency> [<build-opts>] ignoreme
set -euo pipefail

### Defaults ###
Expand Down Expand Up @@ -34,7 +34,8 @@ buildOnTarget="$5"
sshPrivateKey="$6"
action="$7"
deleteOlderThan="$8"
shift 8
copyConcurrency="$9"
shift 9

# remove the last argument
set -- "${@:1:$(($# - 1))}"
Expand All @@ -59,7 +60,7 @@ log() {
}

copyToTarget() {
NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --to "$targetHost" "$@"
NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --max-jobs "$copyConcurrency" --to "$targetHost" "$@"
}

# assumes that passwordless sudo is enabled on the server
Expand Down

0 comments on commit 227cfbd

Please sign in to comment.