|
1 | 1 | # Use without flakes
|
2 | 2 |
|
3 |
| -While `nixos-anywhere` is designed to work optimally with Nix Flakes, it also |
4 |
| -supports the traditional approach without flakes. This document outlines how to |
5 |
| -use `nixos-anywhere` without relying on flakes. You will need to |
6 |
| -[import the disko nixos module](https://github.com/nix-community/disko/blob/master/docs/HowTo.md#installing-nixos-module) |
| 3 | +First, |
| 4 | +[import the disko NixOS module](https://github.com/nix-community/disko/blob/master/docs/HowTo.md#installing-nixos-module) |
7 | 5 | in your NixOS configuration and define disko devices as described in the
|
8 | 6 | [examples](https://github.com/nix-community/disko/tree/master/example).
|
9 | 7 |
|
10 |
| -## Generate Required Store Paths |
11 |
| - |
12 |
| -Before you can use `nixos-anywhere` without flakes, you'll need to manually |
13 |
| -generate the paths for the NixOS system toplevel and disk image. The paths are |
14 |
| -generated using `nix-build` and are necessary for executing `nixos-anywhere`. |
15 |
| - |
16 |
| -### Generating Disk Image without Dependencies: |
| 8 | +Let's assume that your NixOS configuration lives in `configuration.nix` and your |
| 9 | +target machine is called `machine`. |
| 10 | + |
| 11 | +```nix |
| 12 | +# configuration.nix |
| 13 | +{ |
| 14 | + pkgs ? import (fetchTarball channel:nixos-24.05) {}; |
| 15 | +}: |
| 16 | +{ |
| 17 | + config = { config, pkgs, ... }: { /* ... */ }; |
| 18 | + machine = pkgs.nixos config; |
| 19 | +} |
| 20 | +``` |
17 | 21 |
|
18 |
| -To generate the disk image without dependencies, execute: |
| 22 | +Generate the disk formatting script: |
19 | 23 |
|
20 | 24 | ```bash
|
21 |
| -nix-build -I nixos-config=/etc/nixos/configuration.nix -E '(import <nixpkgs/nixos> {}).config.system.build.diskoNoDeps' |
| 25 | +disko=$(nix-build configuration.nix -A machine.config.system.build.disko' --no-out-path) |
22 | 26 | ```
|
23 | 27 |
|
24 |
| -This will output a script path in `/nix/store` that will format your disk. Make |
25 |
| -note of this path for later use. |
26 |
| - |
27 |
| -### Generating NixOS System Toplevel: |
28 |
| - |
29 |
| -Execute the following command to generate the store path for the NixOS system |
30 |
| -toplevel: |
| 28 | +Generate the store path that includes all the software and configurations for |
| 29 | +the NixOS system: |
31 | 30 |
|
32 | 31 | ```bash
|
33 |
| -nix-build -I nixos-config=/etc/nixos/configuration.nix -E '(import <nixpkgs/nixos> {}).config.system.build.toplevel' |
| 32 | +nixos=$(nix-build configuration.nix -A machine.config.system.build.toplevel' --no-out-path) |
34 | 33 | ```
|
35 | 34 |
|
36 |
| -This will output a path in `/nix/store` that corresponds to the system toplevel, |
37 |
| -which includes all the software and configurations for the system. Keep this |
38 |
| -path handy as well. |
39 |
| - |
40 |
| -## Running NixOS-Anywhere |
41 |
| - |
42 |
| -With both paths in hand, you can execute `nixos-anywhere` as follows: |
| 35 | +Run `nixos-anywhere` as follows: |
43 | 36 |
|
44 | 37 | ```bash
|
45 |
| -nixos-anywhere --store-paths /nix/store/[your-disk-image-path] /nix/store/[your-toplevel-path] |
| 38 | +nixos-anywhere --store-paths $disko $nixos root@machine |
46 | 39 | ```
|
47 |
| - |
48 |
| -Replace `[your-disk-image-path]` and `[your-toplevel-path]` with the |
49 |
| -corresponding store paths you generated earlier. |
0 commit comments