diff --git a/docs/howtos/use-without-flakes.md b/docs/howtos/use-without-flakes.md index 162a507..3f61bdc 100644 --- a/docs/howtos/use-without-flakes.md +++ b/docs/howtos/use-without-flakes.md @@ -8,45 +8,75 @@ in your NixOS configuration and define disko devices as described in the Let's assume that your NixOS configuration lives in `configuration.nix` and your target machine is called `machine`: +## 1. Download your favourite disk layout: + +See https://github.com/nix-community/disko-templates/ for more examples: + +The example below will work with both UEFI and BIOS-based systems. + +```bash +curl https://raw.githubusercontent.com/nix-community/disko-templates/main/single-disk-ext4/disko-config.nix > ./disko-config.nix +``` + +## 2. Get a hardware-configuration.nix from on the target machine + +- **Option 1**: If NixOS is not installed, boot into an installer without first + installing NixOS. +- **Option 2**: Use the kexec tarball method, as described + [here](https://github.com/nix-community/nixos-images#kexec-tarballs). + +- **Generate Configuration**: Run the following command on the target machine: + + ```bash + nixos-generate-config --no-filesystems --dir /tmp/config + ``` + +This creates the necessary configuration files under `/tmp/config/`. Copy +`/tmp/config/nixos/hardware-configuration.nix` to your local machine into the +same directory as `disko-config.nix`. + +## 3. Set NixOS version to use + ```nix -# configuration.nix -{ - sources ? { - nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.05"; - disko = fetchTarball "https://github.com/nix-community/disko/tarball/v1.6.1"; - }, - system ? builtins.currentSystem, - pkgs ? import sources.nixpkgs { inherit system; config = {}; overlays = []; }, -}: -rec { - machine = pkgs.nixos config; - config = { config, pkgs, ... }: { - system.stateVersion = "24.05"; - imports = [ - "${sources.disko}/module.nix" - "${sources.disko}/example/hybrid.nix" - ]; - disko.devices.disk.main.device = "/dev/sda"; - boot.loader.systemd-boot.enable = true; - }; +# default.nix +let + # replace nixos-24.05 with your preferred nixos version or revision from here: https://status.nixos.org/ + nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-24.05.tar.gz"; +in +import (nixpkgs + "/nixos/lib/eval-config.nix") { + modules = [ ./configuration.nix ]; } ``` -Generate the disk formatting script: +## 4. Write a NixOS configuration -```bash -disko=$(nix-build configuration.nix -A machine.config.system.build.disko' --no-out-path) +```nix +# configuration.nix +{ + imports = [ + "${fetchTarball "https://github.com/nix-community/disko/tarball/master"}/module.nix" + ./disko-config.nix + ./hardware-configuration.nix + ]; + # Replace this with the system of the installation target you want to install!!! + disko.devices.disk.main.device = "/dev/sda"; + + # Set this to the NixOS version that you have set in the previous step. + # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion . + system.stateVersion = "24.05"; +} ``` -Generate the store path that includes all the software and configurations for -the NixOS system: +## 5. Build and deploy with nixos-anywhere -```bash -nixos=$(nix-build configuration.nix -A machine.config.system.build.toplevel' --no-out-path) -``` +Your current directory now should contain the following files from the previous +step: + +- `configuration.nix`, `default.nix`, `disko-config.nix` and + `hardware-configuration.nix` Run `nixos-anywhere` as follows: ```bash -nixos-anywhere --store-paths $disko $nixos root@machine +nixos-anywhere --store-paths $(nix-build -A config.system.build.disko -A config.system.build.toplevel --no-out-link) root@machine ```