Skip to content

Commit 5f06770

Browse files
authored
Merge pull request #305 from a-kenji/add-password
feat: add copy-password
2 parents a5f5d01 + a2b5fca commit 5f06770

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

docs/quickstart.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ below.
106106
6. On the target machine, make sure you have access as root via ssh by adding
107107
your SSH key to the file `authorized_keys` in the directory `/root/.ssh`
108108

109+
Optionally, bootstrapping can also be performed through password login. For
110+
example through the `image-installer-*` provided by
111+
`nix-community/nixos-images`. Assign your password to the `SSH_PASS`
112+
environment variable and specify `--env-password` as an additional command
113+
line option. This will provide `ssh-copy-id` with the required password.
114+
109115
7. (Optional) Test your nixos and disko configuration:
110116

111117
The following command will automatically test your nixos configuration and

src/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
, gawk
1111
, findutils
1212
, gnused
13+
, sshpass
1314
, terraform-docs
1415
, lib
1516
, makeWrapper
@@ -26,6 +27,7 @@ let
2627
gawk
2728
findutils
2829
gnused # needed by ssh-copy-id
30+
sshpass # used to provide password for ssh-copy-id
2931
rsync # used to upload extra-files
3032
];
3133
in

src/nixos-anywhere.sh

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Options:
1717
set an ssh option
1818
* -L, --print-build-logs
1919
print full build logs
20+
* --env-password
21+
set a password used by ssh-copy-id, the password should be set by
22+
the environment variable SSH_PASS
2023
* -s, --store-paths <disko-script> <nixos-system>
2124
set the store paths to the disko-script and nixos-system directly
2225
if this is given, flake is not needed
@@ -162,6 +165,9 @@ while [[ $# -gt 0 ]]; do
162165
--build-on-remote)
163166
build_on_remote=y
164167
;;
168+
--env-password)
169+
env_password=y
170+
;;
165171
--vm-test)
166172
vm_test=y
167173
;;
@@ -288,14 +294,27 @@ ssh_port=$(echo "$ssh_settings" | awk '/^port / { print $2 }')
288294

289295
step Uploading install SSH keys
290296
until
291-
ssh-copy-id \
292-
-i "$ssh_key_dir"/nixos-anywhere.pub \
293-
-o ConnectTimeout=10 \
294-
-o UserKnownHostsFile=/dev/null \
295-
-o StrictHostKeyChecking=no \
296-
"${ssh_copy_id_args[@]}" \
297-
"${ssh_args[@]}" \
298-
"$ssh_connection"
297+
if [[ -n ${env_password-} ]]; then
298+
sshpass -e \
299+
ssh-copy-id \
300+
-i "$ssh_key_dir"/nixos-anywhere.pub \
301+
-o ConnectTimeout=10 \
302+
-o UserKnownHostsFile=/dev/null \
303+
-o IdentitiesOnly=yes \
304+
-o StrictHostKeyChecking=no \
305+
"${ssh_copy_id_args[@]}" \
306+
"${ssh_args[@]}" \
307+
"$ssh_connection"
308+
else
309+
ssh-copy-id \
310+
-i "$ssh_key_dir"/nixos-anywhere.pub \
311+
-o ConnectTimeout=10 \
312+
-o UserKnownHostsFile=/dev/null \
313+
-o StrictHostKeyChecking=no \
314+
"${ssh_copy_id_args[@]}" \
315+
"${ssh_args[@]}" \
316+
"$ssh_connection"
317+
fi
299318
do
300319
sleep 3
301320
done

0 commit comments

Comments
 (0)