|
234 | 234 |
|
235 | 235 | # ssh wrapper
|
236 | 236 | runSshTimeout() {
|
237 |
| - timeout 10 ssh -i "$ssh_key_dir"/nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${sshArgs[@]}" "$sshConnection" "$@" |
| 237 | + timeout 10 ssh -i "$sshKeyDir"/nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${sshArgs[@]}" "$sshConnection" "$@" |
238 | 238 | }
|
239 | 239 | runSsh() {
|
240 |
| - ssh "$sshTtyParam" -i "$ssh_key_dir"/nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${sshArgs[@]}" "$sshConnection" "$@" |
| 240 | + ssh "$sshTtyParam" -i "$sshKeyDir"/nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${sshArgs[@]}" "$sshConnection" "$@" |
241 | 241 | }
|
242 | 242 |
|
243 | 243 | nixCopy() {
|
244 |
| - NIX_SSHOPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $ssh_key_dir/nixos-anywhere ${sshArgs[*]}" nix copy \ |
| 244 | + NIX_SSHOPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $sshKeyDir/nixos-anywhere ${sshArgs[*]}" nix copy \ |
245 | 245 | "${nixOptions[@]}" \
|
246 | 246 | "${nixCopyOptions[@]}" \
|
247 | 247 | "$@"
|
248 | 248 | }
|
249 | 249 | nixBuild() {
|
250 |
| - NIX_SSHOPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $ssh_key_dir/nixos-anywhere ${sshArgs[*]}" nix build \ |
| 250 | + NIX_SSHOPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $sshKeyDir/nixos-anywhere ${sshArgs[*]}" nix build \ |
251 | 251 | --print-out-paths \
|
252 | 252 | --no-link \
|
253 | 253 | "${nixOptions[@]}" \
|
@@ -281,58 +281,10 @@ runVmTest() {
|
281 | 281 | "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.installTest"
|
282 | 282 | }
|
283 | 283 |
|
284 |
| - |
285 |
| -if [[ -z ${sshConnection-} ]]; then |
286 |
| - abort "ssh-host must be set" |
287 |
| -fi |
288 |
| - |
289 |
| -if [[ -n ${flake-} ]]; then |
290 |
| - if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then |
291 |
| - flake="${BASH_REMATCH[1]}" |
292 |
| - flakeAttr="${BASH_REMATCH[2]}" |
293 |
| - fi |
294 |
| - if [[ -z ${flakeAttr-} ]]; then |
295 |
| - echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri." >&2 |
296 |
| - echo 'For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.' >&2 |
297 |
| - exit 1 |
298 |
| - fi |
299 |
| -fi |
300 |
| - |
301 |
| -if [[ -n ${vmTest-} ]]; then |
302 |
| - runVmTest |
303 |
| -fi |
304 |
| - |
305 |
| -# parse flake nixos-install style syntax, get the system attr |
306 |
| -if [[ -n ${flake-} ]]; then |
307 |
| - if [[ ${buildOnRemote} == "n" ]]; then |
308 |
| - diskoScript=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.diskoScript") |
309 |
| - nixosSystem=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.toplevel") |
310 |
| - fi |
311 |
| -elif [[ -n ${diskoScript-} ]] && [[ -n ${nixosSystem-} ]]; then |
312 |
| - if [[ ! -e ${diskoScript} ]] || [[ ! -e ${nixosSystem} ]]; then |
313 |
| - abort "${diskoScript} and ${nixosSystem} must be existing store-paths" |
314 |
| - fi |
315 |
| -else |
316 |
| - abort "--flake or --store-paths must be set" |
317 |
| -fi |
318 |
| - |
319 |
| -if [[ -n ${SSH_PRIVATE_KEY} ]] && [[ -z ${sshPrivateKeyFile-} ]]; then |
320 |
| - # $ssh_key_dir is getting deleted on trap EXIT |
321 |
| - sshPrivateKeyFile="$ssh_key_dir/from-env" |
322 |
| - ( |
323 |
| - umask 077 |
324 |
| - printf '%s\n' "$SSH_PRIVATE_KEY" >"$sshPrivateKeyFile" |
325 |
| - ) |
326 |
| -fi |
327 |
| - |
328 |
| -sshSettings=$(ssh "${sshArgs[@]}" -G "${sshConnection}") |
329 |
| -sshUser=$(echo "$sshSettings" | awk '/^user / { print $2 }') |
330 |
| -sshHost=$(echo "$sshSettings" | awk '/^hostname / { print $2 }') |
331 |
| - |
332 | 284 | uploadSshKey() {
|
333 | 285 | # we generate a temporary ssh keypair that we can use during nixos-anywhere
|
334 | 286 | sshKeyDir=$(mktemp -d)
|
335 |
| - trap 'rm -rf "$ssh_key_dir"' EXIT |
| 287 | + trap 'rm -rf "$sshKeyDir"' EXIT |
336 | 288 | mkdir -p "$sshKeyDir"
|
337 | 289 | # ssh-copy-id requires this directory
|
338 | 290 | mkdir -p "$HOME/.ssh/"
|
|
532 | 484 | }
|
533 | 485 |
|
534 | 486 | main() {
|
| 487 | + if [[ -z ${sshConnection-} ]]; then |
| 488 | + abort "ssh-host must be set" |
| 489 | + fi |
| 490 | + |
| 491 | + if [[ -n ${flake-} ]]; then |
| 492 | + if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then |
| 493 | + flake="${BASH_REMATCH[1]}" |
| 494 | + flakeAttr="${BASH_REMATCH[2]}" |
| 495 | + fi |
| 496 | + if [[ -z ${flakeAttr-} ]]; then |
| 497 | + echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri." >&2 |
| 498 | + echo 'For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.' >&2 |
| 499 | + exit 1 |
| 500 | + fi |
| 501 | + fi |
| 502 | + |
| 503 | + if [[ -n ${vmTest-} ]]; then |
| 504 | + runVmTest |
| 505 | + fi |
| 506 | + |
| 507 | + # parse flake nixos-install style syntax, get the system attr |
| 508 | + if [[ -n ${flake-} ]]; then |
| 509 | + if [[ ${buildOnRemote} == "n" ]]; then |
| 510 | + diskoScript=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.diskoScript") |
| 511 | + nixosSystem=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.toplevel") |
| 512 | + fi |
| 513 | + elif [[ -n ${diskoScript-} ]] && [[ -n ${nixosSystem-} ]]; then |
| 514 | + if [[ ! -e ${diskoScript} ]] || [[ ! -e ${nixosSystem} ]]; then |
| 515 | + abort "${diskoScript} and ${nixosSystem} must be existing store-paths" |
| 516 | + fi |
| 517 | + else |
| 518 | + abort "--flake or --store-paths must be set" |
| 519 | + fi |
| 520 | + |
| 521 | + if [[ -n ${SSH_PRIVATE_KEY} ]] && [[ -z ${sshPrivateKeyFile-} ]]; then |
| 522 | + # $sshKeyDir is getting deleted on trap EXIT |
| 523 | + sshPrivateKeyFile="$sshKeyDir/from-env" |
| 524 | + ( |
| 525 | + umask 077 |
| 526 | + printf '%s\n' "$SSH_PRIVATE_KEY" >"$sshPrivateKeyFile" |
| 527 | + ) |
| 528 | + fi |
| 529 | + |
| 530 | + sshSettings=$(ssh "${sshArgs[@]}" -G "${sshConnection}") |
| 531 | + sshUser=$(echo "$sshSettings" | awk '/^user / { print $2 }') |
| 532 | + sshHost=$(echo "$sshSettings" | awk '/^hostname / { print $2 }') |
| 533 | + |
535 | 534 | uploadSshKey
|
536 | 535 |
|
537 | 536 | importFacts
|
|
0 commit comments