Skip to content

Commit

Permalink
corrections pre nix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sedlund committed Dec 19, 2024
1 parent f8213c2 commit d50e9b7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Options:
* --stop-after-disko
exit after disko formatting, you can then proceed to install manually or some other way
* --extra-files <path>
contents of local <path> are recursively copied and overwrites root (/) of the new NixOS installation.
contents of local <path> are recursively copied to the root (/) of the new NixOS installation. Existing files are overwritten
Copied files will be owned by root. See documentation for details.
* --disk-encryption-keys <remote_path> <local_path>
copy the contents of the file or pipe in local_path to remote_path in the installer environment,
Expand Down
51 changes: 20 additions & 31 deletions docs/howtos/extra-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ The `--extra-files <path>` option allows copying files to the target host after
installation.

The contents of the `<path>` is recursively copied and overwrites the targets
root (/). The contents *must* be in a structure and permissioned as it
should be on the target.
root (/). The contents _must_ be in a structure and permissioned as it should be
on the target.

In this way, there is no need to repeatedly pass arguments (eg: a fictional
argument: `--copy <source> <dest>`) to `nixos-anywhere` to complete the intended
Expand All @@ -20,14 +20,18 @@ hosts.
## Simple Example

You want `/etc/ssh/ssh_host_*` and `/persist` from the local system on the
target. The `<path>` contents will look like this:
target. The `<path>` contents will look like this:

```console
$ cd /tmp
$ root=$(mktemp -d)
$ sudo cp --verbose --archive --link --parents /etc/ssh/ssh_host_* ${root}
$ cp --verbose --archive --link /persist ${root} # --parents not needed for a full path
$ lsd --tree --long ${root}
$ sudo cp --verbose --archive --parents /etc/ssh/ssh_host_* ${root}
$ cp --verbose --archive --link /persist ${root}
```

The directory structure would look like this:

```console
drwx------ myuser1 users 20 tmp.d6nx5QUwPN
drwxr-xr-x root root 6 ├── etc
drwx------ myuser1 users 160 │ └── ssh
Expand All @@ -47,6 +51,7 @@ drwxr-xr-x myuser1 users 0 ├── blah
**NOTE**: Permissions will be copied, but ownership on the target will be root.

Then pass $root like:

> nixos-anywhere --flake ".#" --extra-files $root --target-host root@newhost
## Programmatic Example
Expand All @@ -70,22 +75,21 @@ during installation.
When the files are extracted on the remote the copied data will be owned by
root.

### Soft links
### Symbolic Links

Do not create soft links to reference data to copy.
Do not create symbolic links to reference data to copy.

GNU `tar` is used to do the copy over ssh. It is an archival tool used to
re/store directory structures as is. Thus `tar` copies soft links (aka:
symbolic links, symlinks) created with `ln -s` by default. It does not follow
them to copy the underlying file.
GNU `tar` is used to do the copy over ssh. It is an archival tool used to
re/store directory structures as is. Thus `tar` copies symbolic links created
with `ln -s` by default. It does not follow them to copy the underlying file.

### Hard links

**NOTE**: hard links can only be created on the same filesystem.

GNU `tar` will copy data referenced by hard links created with `ln`. A hard
link does not create another copy the data. It creates another file path that
points to the same data.
If you have larger peristent data to copy to the target. GNU `tar` will copy
data referenced by hard links created with `ln`. A hard link does not create
another copy the data.

To copy a directory tree to the new target you can use the `cp` command with the
`--link` option which creates hard links.
Expand All @@ -95,24 +99,9 @@ To copy a directory tree to the new target you can use the `cp` command with the
```sh
cd /tmp
root=$(mktemp -d)
cp --verbose --archive --link --parents /etc/ssh/ssh_host* ${root}
cp --verbose --archive --link --parents /persist/home/myuser ${root}
```

`--parents` will create the directory structure of the source at the
destination.

### Copy on Write (COW) file systems

**NOTE**: COW only works on the same underlying filesystem (zpool on zfs).

If the source file system supports copy on write (btrfs, zfs, xfs), you can copy
the files and directories to a containing *path* (while preserving the
structure) to pass to `--extra-files`. This will not use more storage.

#### Example

```console
mkdir target
cp --verbose --archive --parents /etc/ssh/ssh_host* target
```

2 changes: 1 addition & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Options:
* --copy-host-keys
copy over existing /etc/ssh/ssh_host_* host keys to the installation
* --extra-files <path>
contents of local <path> are recursively copied and overwrites root (/) of the new NixOS installation.
contents of local <path> are recursively copied to the root (/) of the new NixOS installation. Existing files are overwritten
Copied files will be owned by root. See documentation for details.
* --disk-encryption-keys <remote_path> <local_path>
copy the contents of the file or pipe in local_path to remote_path in the installer environment,
Expand Down
2 changes: 1 addition & 1 deletion src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Options:
* --copy-host-keys
copy over existing /etc/ssh/ssh_host_* host keys to the installation
* --extra-files <path>
contents of local <path> are recursively copied and overwrites root (/) of the new NixOS installation.
contents of local <path> are recursively copied to the root (/) of the new NixOS installation. Existing files are overwritten
Copied files will be owned by root. See documentation for details.
* --disk-encryption-keys <remote_path> <local_path>
copy the contents of the file or pipe in local_path to remote_path in the installer environment,
Expand Down

0 comments on commit d50e9b7

Please sign in to comment.