Skip to content

Latest commit

 

History

History
82 lines (61 loc) · 2.69 KB

use-without-flakes.md

File metadata and controls

82 lines (61 loc) · 2.69 KB

Use without flakes

First, import the disko NixOS module in your NixOS configuration and define disko devices as described in the examples.

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.

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.

  • Generate Configuration: Run the following command on the target machine:

    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

# 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 ];
}

4. Write a NixOS configuration

# 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";
}

5. Build and deploy with nixos-anywhere

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:

nixos-anywhere --store-paths $(nix-build -A config.system.build.disko -A config.system.build.toplevel --no-out-link) root@machine