Skip to content
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

nixos-anywhere: add --target-host option #432

Merged
merged 2 commits into from
Dec 12, 2024
Merged
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
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
Loading