<style>
.reveal section.present div {
font-size: 0.8em;
line-height: 1.0em;
vertical-align: top;
}
</style>
# disko + nixos-anywhere workshop
full automatic nixos installations with declarative disk managment
---
# Motivation
- In our work with numtide we are installing NixOS a lot
- We often deal with a wide range of platforms, that provides different ways of bootstrapping,
not all of which supports NixOS as a native method.
- Building and uploading installer images to all these platforms is tedious
- What we want is to be able to bootstrap NixOS *anywhere* in the same way
---
# Background: Installing NixOS
1. Boot & access the NixOS installer on the target system
- highly dependent on the environment (virtual machines, bare-metal server, laptops ...)
2. Partition, format and mount the disks
3. Copy or write nixos configuration
4. Run `nixos-install`
5. Reboot
*Installing NixOS manually can be tedious and unergonomic*
---
# The solution:
## Nixos-anywhere + Disko
1. **disko** is used by importing the nixos module and configuring a disk layout.
2. **nixos-anywhere**
* Takes your nixos configuration with a disko config and automatically installs it over ssh.
* If your target is not yet boot into an installer it can also use "kexec" to load a NixOS installer into memory to replace the current OS
---
# Disko features
- Declarative partitioning (GPT/MBR)
- ZFS with multiple devices
- Raids with mdadm/lvm
- Luks encryption
- Bcachefs
---
# The workflow:
1. Use our flake template
2. Choose a disk layout
3. Optional: Test in a VM
4. Install
---
# Requirements:
- A machine with Linux with SSH access that supports kexec
## Or
- A machine booted into the NixOS installer with ssh (manually) started
---
## Step 1. Use our flake template
Enable flakes:
```shell
mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf
```
Run
```shell
nix flake new --template github:Lassulus/nixos-anywhere-workshop ./workshop
```
<!--`git clone https://github.com/Lassulus/nixos-anywhere-workshop`-->
---
## Step 2. Choose a disk layout
In disk-configs there are a bunch of different layouts, choose one by setting it in the flake.nix like this:
```nix
{
nixosConfigurations.mysystem = nixpkgs.lib.nixosSystem {
...
modules = [
./disk-configs/simple-efi.nix;
...
];
};
}
```
---
## Step 3. Optional: Test in a VM
Run the interactive nixos-vm test:
```shell
nix run github:numtide/nixos-anywhere -- -f '.#mysystem' --vm-test
```
---
## Customizing
You can take a look at the different disk layouts and choose which one you want
Or create your own disk layout by copying stuff from the [disko](https://github.com/nix-community/disko/examples) examples folder
---
## Final Step Install
If vm test was successfull, you can deploy the config to a remote system with:
```shell
nix run github:numtide/nixos-anywhere -- -f '.#mysystem' root@yourhostname
```
Hints:
* Take extra care to add the network config to your configuration and also add your ssh keys
* Otherwise you will lock yourself out
---
## Other cool features of disko/nixos-anywhere
* Secret support:
* nixos-anywhere supports upload secrets to the final system (i.e. bootstrapping agenix/sops-nix) and for disk encryption
* Image creation:
* disko supports generating disk images (including secrets) with arbitrary, commplex disk layouts
---
## Future work
* PXE boot. [Working branch, tests still missing](https://github.com/numtide/nixos-anywhere/pull/50)
* Automatically generating hardware configuration
{"type":"slide","slideOptions":{"transition":"slide","theme":"white","width":960,"height":700}}