Skip to content

Commit 653f13c

Browse files
zimbatmmergify[bot]
authored andcommitted
nixos-anywhere: add --target-host option
Mirror the option from nixos-rebuild, so both have the same signature: * Bootstrap: `nixos-anywhere --flake .#targethost --target-host root@1.2.3.4` * Deploy: `nixos-rebuild --flake .#targethost --target-host root@1.2.3.4 switch`
1 parent b7e91fa commit 653f13c

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

docs/cli.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# CLI
22

33
```
4-
Usage: nixos-anywhere [options] <ssh-host>
4+
Usage: nixos-anywhere [options] [<ssh-host>]
55
66
Options:
77
88
* -f, --flake <flake_uri>
99
set the flake to install the system from.
10+
* --target-host <ssh-host>
11+
specified the SSH target host to deploy onto.
1012
* -i <identity_file>
1113
selects which SSH private key file to use.
1214
* -p, --ssh-port <ssh_port>

docs/howtos/disko-modes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To only mount existing filesystems, add `--disko-mode mount` to
1010
`nixos-anywhere`:
1111

1212
```
13-
nix run github:nix-community/nixos-anywhere -- --disko-mode mount --flake <path to configuration>#<configuration name> root@<ip address>
13+
nix run github:nix-community/nixos-anywhere -- --disko-mode mount --flake <path to configuration>#<configuration name> --target-host root@<ip address>
1414
```
1515

1616
1. This will first boot into a nixos-installer

docs/howtos/no-os.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ssh -v nixos@fec0::5054:ff:fe12:3456
6464
You can then use the IP address to run `nixos-anywhere` like this:
6565

6666
```
67-
nix run github:nix-community/nixos-anywhere -- --flake '.#myconfig' nixos@fec0::5054:ff:fe12:3456
67+
nix run github:nix-community/nixos-anywhere -- --flake '.#myconfig' --target-host nixos@fec0::5054:ff:fe12:3456
6868
```
6969

7070
This example assumes a flake in the current directory containing a configuration

docs/howtos/secrets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pass ssh_host_ed25519_key > "$temp/etc/ssh/ssh_host_ed25519_key"
3535
chmod 600 "$temp/etc/ssh/ssh_host_ed25519_key"
3636

3737
# Install NixOS to the host system with our secrets
38-
nixos-anywhere --extra-files "$temp" --flake '.#your-host' root@yourip
38+
nixos-anywhere --extra-files "$temp" --flake '.#your-host' --target-host root@yourip
3939
```
4040

4141
## Example: Uploading Disk Encryption Secrets

docs/quickstart.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,28 +217,28 @@ You can now run **nixos-anywhere** from the command line as shown below, where:
217217
- `<ip address>` is the IP address of the target machine.
218218

219219
```
220-
nix run github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> root@<ip address>
220+
nix run github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> --target-host root@<ip address>
221221
```
222222

223223
The command would look  like this if you had created your files in a directory
224224
named `/home/mydir/test` and the IP address of your target machine is
225225
`37.27.18.135`:
226226

227227
```
228-
nix run github:nix-community/nixos-anywhere -- --flake /home/mydir/test#hetzner-cloud root@37.27.18.135
228+
nix run github:nix-community/nixos-anywhere -- --flake /home/mydir/test#hetzner-cloud --target-host root@37.27.18.135
229229
```
230230

231231
If you also need to generate hardware configuration amend flags for
232232
nixos-generate-config:
233233

234234
```
235-
nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-generate-config ./hardware-configuration.nix --flake <path to configuration>#<configuration name> root@<ip address>
235+
nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-generate-config ./hardware-configuration.nix --flake <path to configuration>#<configuration name> --target-host root@<ip address>
236236
```
237237

238238
Or these flags if you are using nixos-facter instead:
239239

240240
```
241-
nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-facter ./facter.json --flake <path to configuration>#<configuration name> root@<ip address>
241+
nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-facter ./facter.json --flake <path to configuration>#<configuration name> --target-host root@<ip address>
242242
```
243243

244244
Adjust the location of `./hardware-configuration.nix` and `./facter.json`

src/nixos-anywhere.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ declare -a sshArgs=()
6262

6363
showUsage() {
6464
cat <<USAGE
65-
Usage: nixos-anywhere [options] <ssh-host>
65+
Usage: nixos-anywhere [options] [<ssh-host>]
6666
6767
Options:
6868
6969
* -f, --flake <flake_uri>
7070
set the flake to install the system from.
71+
* --target-host <ssh-host>
72+
specified the SSH target host to deploy onto.
7173
* -i <identity_file>
7274
selects which SSH private key file to use.
7375
* -p, --ssh-port <ssh_port>
@@ -143,6 +145,10 @@ parseArgs() {
143145
flake=$2
144146
shift
145147
;;
148+
--target-host)
149+
sshConnection=$2
150+
shift
151+
;;
146152
-i)
147153
sshPrivateKeyFile=$2
148154
shift

0 commit comments

Comments
 (0)