fully automated NixOS CLI installer
Go to file
Niklas Gollenstede 65c1691644 update to nixos-24.05,
make installation in VM more versatile,
allow imports in host config file based on `name`
2024-05-31 22:41:35 +02:00
.vscode update to nixos-24.05, 2024-05-31 22:41:35 +02:00
example nixos-23.11: fileSystems.*.format{Options->Args}, 2023-11-27 17:15:44 +01:00
hosts add support for config.boot.initrd.systemd.enable 2024-02-27 16:36:01 +01:00
lib update to nixos-24.05, 2024-05-31 22:41:35 +02:00
modules update to nixos-24.05, 2024-05-31 22:41:35 +02:00
overlays update to nixos-24.05, 2024-05-31 22:41:35 +02:00
patches (re-)move generic-arg-*, more concise default.nix 2023-12-04 19:30:01 +01:00
.gitattributes init 2022-05-09 14:36:47 +02:00
.gitignore init 2022-05-09 14:36:47 +02:00
flake.lock update to nixos-24.05, 2024-05-31 22:41:35 +02:00
flake.nix update to nixos-24.05, 2024-05-31 22:41:35 +02:00
LICENSE init 2022-05-09 14:36:47 +02:00
README.md remove nofail mount option, import/export things 2023-09-01 17:01:13 +02:00

Automated NixOS CLI Installer

NixOS is traditionally either installed by creating and populating filesystems by hand, or by scripts that each only support one or a limited set of filesystem setups (the graphical installer falls somewhere between the two). The mounted filesystems and some hardware aspects are then be captured in a hardware-configuration.nix. This both completely contradicts the declarative nature and flexibility of Nix(OS).

In contrast to that, this flake implements a very flexible, declaratively driven and fully automated NixOS installer (framework). Hosts can define any number of disks and partitions on them. If the fileSystems use partlabels to identify their devices, then they can be associated with their partitions even before they are formatted -- and can thus automatically be formatted during the installation. ZFS pools and datasets, and LUKS and ZFS encryption are also supported. For setups with ephemeral / (root filesystem), modules/setup/temproot.nix.md provides various preconfigured setups. This, together with convenient defaults for most of the options, means that simple setups (see the minimal example) only require a handful of config lines, while complex multi-disk setups (see the raidz example) are just as possible.

A set of composable setup-scripts can then automatically grab this information and perform a completely automated installation. 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, the installation can be started with:

nix run .'#'hostname -- install-system /path/to/disk

Help output with information on available commands and flags is available here or via:

nix run .'#'hostname -- --help

config.installer.commands.* can be used to run host-specific commands at various points of the installation, and additional config.installer.scripts can add or replace new and existing setup commands or functions. This mechanism has been used to, for example, automatically deploy locally built system images tp Hetzner VPSes.

Repo Layout/Contents

This is a nix flake repository, so flake.nix is the entry point and export mechanism for almost everything.

lib/ defines new library functions which are exported as the lib flake output. Other Nix files in this repo use them as inputs.self.lib.
setup-scripts contains the implementation for the default setup (system installation and maintenance) commands.

modules/ contains NixOS configuration modules. bootloader/extlinux enables extlinux as alternative bootloader for legacy BIOS environments, because GRUB refuses top be installed to loop-mounted images. The modules in setup allow defining a NixOS system's disk and filesystem setup in sufficient detail that a fully automatic installation is possible. The installer module composes the setup-scripts and the host's config into its individual installer.

There is currently only one overlay that applies a patch to sgdisk (it allows moving the backup GPT table, see gptfdisk #32).

hosts/example provides some NixOS host definitions that demonstrate different types of disk setups.

example/ contains examples for customizing the installation script for the hosts, and this flake's default config.

License

All files in this repository (nixos-installer), except ./LICENSE, are authored by the authors of this repository, and are copyright 2022 - present Niklas Gollenstede.

See patches/README.md#license for the licensing of the included patches. All other parts of this software may be used under the terms of the MIT license, as detailed in ./LICENSE.

This license applies to the files in this repository only. Any external packages are built from sources that have their own licenses, which should be the ones indicated in the package's metadata.