mirror of
https://github.com/NiklasGollenstede/nixos-installer.git
synced 2024-11-21 15:33:21 +01:00
install-system: remove diskPaths
positional arg, but add default for --disks=
flag
This commit is contained in:
parent
872790aaf0
commit
a937ebf3fc
@ -16,7 +16,7 @@ A set of composable [`setup-scripts`](./lib/setup-scripts/) can then [automatica
|
|||||||
The only thing that the scripts will interactively prompt for are external secrets (e.g., passwords), iff required by the new host.
|
The only thing that the scripts will interactively prompt for are external secrets (e.g., passwords), iff required by the new host.
|
||||||
When using [`mkSystemsFlake`](./lib/nixos.nix#mkSystemsFlake), the installation can be started with:
|
When using [`mkSystemsFlake`](./lib/nixos.nix#mkSystemsFlake), the installation can be started with:
|
||||||
```bash
|
```bash
|
||||||
nix run .'#'hostname -- install-system /path/to/disk
|
nix run .'#'hostname -- install-system --disks=/path/to/disk
|
||||||
```
|
```
|
||||||
Help output with information on available commands and flags is [available here](https://github.com/NiklasGollenstede/nixos-installer/wiki/−−help-Output) or via:
|
Help output with information on available commands and flags is [available here](https://github.com/NiklasGollenstede/nixos-installer/wiki/−−help-Output) or via:
|
||||||
```bash
|
```bash
|
||||||
|
@ -9,11 +9,11 @@ Just to provide an example of what a host configuration using this set of librar
|
|||||||
|
|
||||||
To install the system to a (set of) virtual machine disk images, with `$hostname` as any of the `instances` below, run in `..`:
|
To install the system to a (set of) virtual machine disk images, with `$hostname` as any of the `instances` below, run in `..`:
|
||||||
```bash
|
```bash
|
||||||
nix run .'#'$hostname -- install-system /tmp/$hostname/
|
nix run .'#'$hostname -- install-system --disks=/tmp/$hostname/
|
||||||
```
|
```
|
||||||
Then to boot the system in a qemu VM with KVM:
|
Then to boot the system in a qemu VM with KVM:
|
||||||
```bash
|
```bash
|
||||||
nix run .'#'$hostname -- run-qemu /tmp/$hostname/
|
nix run .'#'$hostname -- run-qemu --disks=/tmp/$hostname/
|
||||||
```
|
```
|
||||||
See `nix run .#$hostname -- --help` for options and more commands.
|
See `nix run .#$hostname -- --help` for options and more commands.
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ in rec {
|
|||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
Install the system »$host« to the image file »/tmp/system-$host.img«:
|
Install the system »$host« to the image file »/tmp/system-$host.img«:
|
||||||
$ nix run .#$host -- install-system /tmp/system-$host.img
|
$ nix run .#$host -- install-system --disks=/tmp/system-$host.img
|
||||||
|
|
||||||
Test a fresh installation of »$host« in a qemu VM:
|
Test a fresh installation of »$host« in a qemu VM:
|
||||||
$ nix run .#$host -- run-qemu --install=always
|
$ nix run .#$host -- run-qemu --install=always
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# NixOS Installation
|
# NixOS Installation
|
||||||
##
|
##
|
||||||
|
|
||||||
declare-command install-system '[--disks=]diskPaths' << 'EOD'
|
declare-command install-system '[--disks=diskPaths]' << 'EOD'
|
||||||
This command installs a NixOS system to local disks or image files.
|
This command installs a NixOS system to local disks or image files.
|
||||||
It gets all the information it needs from the system's NixOS configuration -- except for the path(s) of the target disk(s) / image file(s); see the »--disks=« flag.
|
It gets all the information it needs from the system's NixOS configuration -- except for the path(s) of the target disk(s) / image file(s); see the »--disks=« flag.
|
||||||
|
|
||||||
@ -22,12 +22,16 @@ What the installation does is defined solely by the target host's NixOS configur
|
|||||||
The "Installation" section of each host's documentation should contain host specific details, if any.
|
The "Installation" section of each host's documentation should contain host specific details, if any.
|
||||||
Various »FLAG«s below affect how the installation is performed (in VM, verbosity, debugging, ...).
|
Various »FLAG«s below affect how the installation is performed (in VM, verbosity, debugging, ...).
|
||||||
EOD
|
EOD
|
||||||
declare-flag install-system disks "diskPaths" "The disk(s) (to be) used by this system installation.
|
declare-flag install-system,'*' disks "diskPaths" "The disk(s) (to be) used by this system installation.
|
||||||
If »diskPaths« points to something in »/dev/«, then it is directly used as block device, otherwise »diskPaths« is (re-)created as raw image file and then used as loop device.
|
If »diskPaths« points to something in »/dev/«, then it is directly used as block device, otherwise »diskPaths« is (re-)created as raw image file 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)."
|
For hosts that install to multiple disks, pass a colon-separated list of »<disk-name>=<path>« pairs (the name may be omitted only for the "default" disk).
|
||||||
function install-system {( # 1: diskPaths
|
If a directory path ending in a forward slash is passed, it is expanded to ».img« files in that directory, one per (and named after) declared disk.
|
||||||
|
Defaults to »/tmp/nixos-img-@{config.installer.outputName:-@{config.system.name}}/«."
|
||||||
|
if [[ ! ${args[disks]:-} ]] ; then args[disks]=/tmp/nixos-img-@{config.installer.outputName:-@{config.system.name}}/ ; fi
|
||||||
|
|
||||||
|
function install-system {(
|
||||||
trap - EXIT # start with empty traps for sub-shell
|
trap - EXIT # start with empty traps for sub-shell
|
||||||
prepare-installer "$@" || exit
|
prepare-installer || exit
|
||||||
do-disk-setup || exit
|
do-disk-setup || exit
|
||||||
install-system-to $mnt || exit
|
install-system-to $mnt || exit
|
||||||
)}
|
)}
|
||||||
@ -40,12 +44,10 @@ See also the »--no-vm« and »--vm-shared=« flags."
|
|||||||
declare-flag install-system no-vm "" "Never perform the installation in a VM. Fail if not executed as »root«."
|
declare-flag install-system no-vm "" "Never perform the installation in a VM. Fail if not executed as »root«."
|
||||||
|
|
||||||
## Does some argument validation, performs some sanity checks, includes a hack to make installation work when nix isn't installed for root, and runs the installation in qemu (if requested).
|
## Does some argument validation, performs some sanity checks, includes a hack to make installation work when nix isn't installed for root, and runs the installation in qemu (if requested).
|
||||||
function prepare-installer { # 1: diskPaths
|
function prepare-installer {
|
||||||
|
|
||||||
run-hook-script 'Prepare Installer' @{config.installer.commands.prepareInstaller!writeText.prepareInstallerCommands} || exit
|
run-hook-script 'Prepare Installer' @{config.installer.commands.prepareInstaller!writeText.prepareInstallerCommands} || exit
|
||||||
|
|
||||||
if [[ ! ${args[disks]:-} ]] ; then args[disks]=${1:?"The --disks= flag or the first positional argument must specify the path(s) to the disk(s) and/or image file(s) to install to"} ; shift ; fi
|
|
||||||
|
|
||||||
umask g-w,o-w # Ensure that files created without explicit permissions are not writable for group and other.
|
umask g-w,o-w # Ensure that files created without explicit permissions are not writable for group and other.
|
||||||
|
|
||||||
if [[ "$(id -u)" != '0' ]] ; then
|
if [[ "$(id -u)" != '0' ]] ; then
|
||||||
|
@ -47,16 +47,15 @@ function register-vbox {(
|
|||||||
echo " ssh $(@{native.inetutils}/bin/hostname) VBoxManage controlvm $vmName screenshotpng /dev/stdout | display"
|
echo " ssh $(@{native.inetutils}/bin/hostname) VBoxManage controlvm $vmName screenshotpng /dev/stdout | display"
|
||||||
)}
|
)}
|
||||||
|
|
||||||
declare-command run-qemu '[--disks=]disks' qemuArgs... << 'EOD'
|
declare-command run-qemu '[--disks=diskPaths]' qemuArgs... << 'EOD'
|
||||||
Runs a host in a QEMU VM, directly from its bootable disks, without requiring any change in it's configuration.
|
Runs a host in a QEMU VM, directly from its bootable disks, without requiring any change in it's configuration.
|
||||||
This function infers many qemu options from the target system's configuration and the current host system.
|
This function infers many qemu options from the target system's configuration and the current host system.
|
||||||
»disks« may be passed in the same format as to the installer. Any image files passed are ensured to be loop-mounted. »root« may also pass device paths.
|
|
||||||
EOD
|
EOD
|
||||||
declare-flag run-qemu dry-run "" "Instead of running the (main) qemu (and install) command, only print it."
|
declare-flag run-qemu dry-run "" "Instead of running the (main) qemu (and install) command, only print it."
|
||||||
declare-flag run-qemu efi "" "Treat the target system as EFI system, even if not recognized as such automatically."
|
declare-flag run-qemu efi "" "Treat the target system as EFI system, even if not recognized as such automatically."
|
||||||
declare-flag run-qemu efi-vars "path" "For »--efi« systems, path to a file storing the EFI variables. The default is in »XDG_RUNTIME_DIR«, i.e. it does not persist across host reboots."
|
declare-flag run-qemu efi-vars "path" "For »--efi« systems, path to a file storing the EFI variables. The default is in »XDG_RUNTIME_DIR«, i.e. it does not persist across host reboots."
|
||||||
declare-flag run-qemu graphic "" "Open a graphical window even of the target system logs to serial and not (explicitly) TTY1."
|
declare-flag run-qemu graphic "" "Open a graphical window even of the target system logs to serial and not (explicitly) TTY1."
|
||||||
declare-flag run-qemu install "[1|always]" "If any of the guest system's disk images does not exist, perform the its installation before starting the VM. If set to »always«, always install before starting the VM. With this flag set, »disks« defaults to paths in »/tmp/."
|
declare-flag run-qemu install "[1|always]" "If any of the guest system's disk images does not exist, perform the its installation before starting the VM. If set to »always«, always install before starting the VM."
|
||||||
declare-flag run-qemu no-kvm "" "Do not try to use (or complain about the unavailability of) KVM."
|
declare-flag run-qemu no-kvm "" "Do not try to use (or complain about the unavailability of) KVM."
|
||||||
declare-flag run-qemu nat-fw "forwards" "Port forwards to the guest's NATed NIC. E.g: »--nat-fw=:8000-:8000,:8001-:8001,127.0.0.1:2022-:22«."
|
declare-flag run-qemu nat-fw "forwards" "Port forwards to the guest's NATed NIC. E.g: »--nat-fw=:8000-:8000,:8001-:8001,127.0.0.1:2022-:22«."
|
||||||
declare-flag run-qemu no-nat "" "Do not provide a NATed NIC to the guest."
|
declare-flag run-qemu no-nat "" "Do not provide a NATed NIC to the guest."
|
||||||
@ -70,9 +69,7 @@ $ ... --nic=vde,sock=/tmp/vm-net # multiple times"
|
|||||||
declare-flag run-qemu no-serial "" "Do not connect the calling terminal to a serial adapter the guest can log to and open a terminal on the guests serial, as would be the default if the guests logs to ttyS0."
|
declare-flag run-qemu no-serial "" "Do not connect the calling terminal to a serial adapter the guest can log to and open a terminal on the guests serial, as would be the default if the guests logs to ttyS0."
|
||||||
declare-flag run-qemu share "decls" "Host dirs to make available as network shares for the guest, as space separated list of »name:host-path,options«. E.g. »--share='foo:/home/user/foo,readonly=on bar:/tmp/bar«. In the VM the share can be mounted with: »$ mount -t 9p -o trans=virtio -o version=9p2000.L -o msize=4194304 -o ro foo /foo«."
|
declare-flag run-qemu share "decls" "Host dirs to make available as network shares for the guest, as space separated list of »name:host-path,options«. E.g. »--share='foo:/home/user/foo,readonly=on bar:/tmp/bar«. In the VM the share can be mounted with: »$ mount -t 9p -o trans=virtio -o version=9p2000.L -o msize=4194304 -o ro foo /foo«."
|
||||||
declare-flag run-qemu virtio-blk "" "Pass the system's disks/images as virtio disks, instead of using AHCI+IDE. Default iff »boot.initrd.availableKernelModules« includes »virtio_blk« (because it requires that driver)."
|
declare-flag run-qemu virtio-blk "" "Pass the system's disks/images as virtio disks, instead of using AHCI+IDE. Default iff »boot.initrd.availableKernelModules« includes »virtio_blk« (because it requires that driver)."
|
||||||
function run-qemu { # 1?: disks, ...: qemuArgs
|
function run-qemu { # ...: qemuArgs
|
||||||
if [[ ${args[install]:-} && ! ${1:-} && ! ${args[disks]:-} ]] ; then args[disks]=/tmp/nixos-vm/@{config.installer.outputName:-@{config.system.name}}/ ; fi
|
|
||||||
if [[ ! ${args[disks]:-} ]] ; then args[disks]=${1:?"The --disks= flag or the first positional argument must specify the path(s) to the disk(s) and/or image file(s) to install to, or the --install flag must be set to enable an automatic fallback"} ; shift ; fi
|
|
||||||
|
|
||||||
local qemu=( )
|
local qemu=( )
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ in {
|
|||||||
keystore.keys."luks/swap-${hash}/0" = lib.mkIf cfg.swap.encrypted (lib.mkOptionDefault "random");
|
keystore.keys."luks/swap-${hash}/0" = lib.mkIf cfg.swap.encrypted (lib.mkOptionDefault "random");
|
||||||
};
|
};
|
||||||
swapDevices = [ { inherit device; } ];
|
swapDevices = [ { inherit device; } ];
|
||||||
boot.resumeDevice = device;
|
boot.resumeDevice = lib.mkDefault device;
|
||||||
|
|
||||||
|
|
||||||
})) (lib.mkIf (cfg.swap.size != null && !cfg.swap.asPartition) {
|
})) (lib.mkIf (cfg.swap.size != null && !cfg.swap.asPartition) {
|
||||||
@ -346,7 +346,7 @@ in {
|
|||||||
|
|
||||||
})) (lib.mkIf (cfg.remote.type == "none") {
|
})) (lib.mkIf (cfg.remote.type == "none") {
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [ (lib.fun.mkTmpfile { type = "L+"; path = "/remote"; argument = "/local"; }) ]; # for compatibility (but use a symlink to make clear that this is not actually a separate mount)
|
systemd.tmpfiles.rules = [ (lib.fun.mkTmpfile { type = "L+"; path = "/remote"; argument = "local"; }) ]; # for compatibility (but use a symlink to make clear that this is not actually a separate mount)
|
||||||
|
|
||||||
|
|
||||||
}) ] ++ (map (type: (lib.mkIf (cfg.${type}.type == "bind") {
|
}) ] ++ (map (type: (lib.mkIf (cfg.${type}.type == "bind") {
|
||||||
|
Loading…
Reference in New Issue
Block a user