nixos-installer/lib/setup-scripts/README.md

36 lines
2.4 KiB
Markdown
Raw Normal View History

2022-05-09 13:20:43 +02:00
# Host Setup Scripts
This is a library of bash functions, mostly for NixOS system installation.
The (paths to these) scripts are meant to be (and by default are) set as `config.wip.setup.scripts.*` (see [`../flakes.nix`](../flakes.nix)), which makes their functions available in the per-host [`devShells`/`apps`](../flakes.nix#mkSystemsFlake).
2022-05-09 13:20:43 +02:00
Host-specific nix variables are available to the bash functions as `@{...}` through [`substituteImplicit`](../scripts.nix#substituteImplicit) with the respective host as root context.
Any script passed later in `scripts` can overwrite the functions of these (earlier) default scripts.
2022-05-09 13:20:43 +02:00
With the functions from here, [a simple three-liner](../install.sh) is enough to do a completely automated NixOS installation:
2022-05-09 13:20:43 +02:00
```bash
function install-system {( set -eu # 1: diskPaths
2022-05-09 13:20:43 +02:00
prepare-installer "$@"
do-disk-setup "${argv[0]}"
install-system-to $mnt
2022-05-09 13:20:43 +02:00
)}
```
# `install-system` Documentation
The above function performs the mostly automated installation of any `$HOST` from [`../../hosts/`](../../hosts/) to the local disk(s) (or image file(s)) `$DISK`.
On a NixOS host, this can be run by root as: `#` `nix run .#"$HOST" -- install-system "$DISK"`.
2022-05-09 13:20:43 +02:00
Doing an installation on non-NixOS (but Linux), where nix isn't installed for root, is a bit of a hack, but works as well.
In this case, all `nix` commands will be run as `$SUDO_USER`, but this script and some other user-owned (or user-generated) code will (need to) be run as root.
If that is acceptable, run with `sudo` as first argument: `$` `nix run .#"$HOST" -- sudo install-system "$DISK"` (And then maybe `sudo bash -c 'chown $SUDO_USER: '"$DISK"` afterwards.)
2022-05-09 13:20:43 +02:00
If `$DISK` points to something in `/dev/`, then it is directly formatted and written to as block device, otherwise `$DISK` is (re-)created as raw image and then used as loop device.
For hosts that install to multiple disks, pass a `:`-separated list of `<disk-name>=<path>` pairs (the name may be omitted only for the "`default`" disk).
2022-05-09 13:20:43 +02:00
Once done, the disk can be transferred -- or the image be copied -- to the final system, and should boot there.
If the host's hardware target allows, a resulting image can also be passed to [`register-vbox`](../maintenance.sh#register-vbox) to create a bootable VirtualBox instance for the current user, or to [`run-qemu`](../maintenance.sh#run-qemu) to start it in a qemu VM.
2022-05-09 13:20:43 +02:00
The "Installation" section of each host's documentation should contain host specific details, if any.