Skip to content

deploy_nixos: parameterise concurrency controls of nix-copy-closure #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> [<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