Skip to content

Commit

Permalink
nixos-anywhere: add --target-host option
Browse files Browse the repository at this point in the history
Mirror the option from nixos-rebuild, so both have the same signature:

* Bootstrap: `nixos-anywhere --flake .#targethost --target-host [email protected]`

* Deploy: `nixos-rebuild --flake .#targethost --target-host [email protected] switch`
  • Loading branch information
zimbatm authored and mergify[bot] committed Dec 12, 2024
1 parent b7e91fa commit 653f13c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# CLI

```
Usage: nixos-anywhere [options] <ssh-host>
Usage: nixos-anywhere [options] [<ssh-host>]
Options:
* -f, --flake <flake_uri>
set the flake to install the system from.
* --target-host <ssh-host>
specified the SSH target host to deploy onto.
* -i <identity_file>
selects which SSH private key file to use.
* -p, --ssh-port <ssh_port>
Expand Down
2 changes: 1 addition & 1 deletion docs/howtos/disko-modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To only mount existing filesystems, add `--disko-mode mount` to
`nixos-anywhere`:

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

1. This will first boot into a nixos-installer
Expand Down
2 changes: 1 addition & 1 deletion docs/howtos/no-os.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ssh -v nixos@fec0::5054:ff:fe12:3456
You can then use the IP address to run `nixos-anywhere` like this:

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

This example assumes a flake in the current directory containing a configuration
Expand Down
2 changes: 1 addition & 1 deletion docs/howtos/secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pass ssh_host_ed25519_key > "$temp/etc/ssh/ssh_host_ed25519_key"
chmod 600 "$temp/etc/ssh/ssh_host_ed25519_key"

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

## Example: Uploading Disk Encryption Secrets
Expand Down
8 changes: 4 additions & 4 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,28 +217,28 @@ You can now run **nixos-anywhere** from the command line as shown below, where:
- `<ip address>` is the IP address of the target machine.

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

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

```
nix run github:nix-community/nixos-anywhere -- --flake /home/mydir/test#hetzner-cloud [email protected]
nix run github:nix-community/nixos-anywhere -- --flake /home/mydir/test#hetzner-cloud --target-host [email protected]
```

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

```
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>
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>
```

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

```
nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-facter ./facter.json --flake <path to configuration>#<configuration name> root@<ip address>
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>
```

Adjust the location of `./hardware-configuration.nix` and `./facter.json`
Expand Down
8 changes: 7 additions & 1 deletion src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ declare -a sshArgs=()

showUsage() {
cat <<USAGE
Usage: nixos-anywhere [options] <ssh-host>
Usage: nixos-anywhere [options] [<ssh-host>]
Options:
* -f, --flake <flake_uri>
set the flake to install the system from.
* --target-host <ssh-host>
specified the SSH target host to deploy onto.
* -i <identity_file>
selects which SSH private key file to use.
* -p, --ssh-port <ssh_port>
Expand Down Expand Up @@ -143,6 +145,10 @@ parseArgs() {
flake=$2
shift
;;
--target-host)
sshConnection=$2
shift
;;
-i)
sshPrivateKeyFile=$2
shift
Expand Down

0 comments on commit 653f13c

Please sign in to comment.