Skip to content

Commit ce18c08

Browse files
Mic92mergify[bot]
authored andcommitted
docs/legacy-nix: make example more standard conform
* add nixos-generate-config as the hardware otherwise might not boot * change configuration.nix so that it can be actually used with nixos-rebuild * refactor nixos-anywhere into a single line for convenience
1 parent db2478a commit ce18c08

File tree

1 file changed

+59
-29
lines changed

1 file changed

+59
-29
lines changed

docs/howtos/use-without-flakes.md

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,75 @@ in your NixOS configuration and define disko devices as described in the
88
Let's assume that your NixOS configuration lives in `configuration.nix` and your
99
target machine is called `machine`:
1010

11+
## 1. Download your favourite disk layout:
12+
13+
See https://github.com/nix-community/disko-templates/ for more examples:
14+
15+
The example below will work with both UEFI and BIOS-based systems.
16+
17+
```bash
18+
curl https://raw.githubusercontent.com/nix-community/disko-templates/main/single-disk-ext4/disko-config.nix > ./disko-config.nix
19+
```
20+
21+
## 2. Get a hardware-configuration.nix from on the target machine
22+
23+
- **Option 1**: If NixOS is not installed, boot into an installer without first
24+
installing NixOS.
25+
- **Option 2**: Use the kexec tarball method, as described
26+
[here](https://github.com/nix-community/nixos-images#kexec-tarballs).
27+
28+
- **Generate Configuration**: Run the following command on the target machine:
29+
30+
```bash
31+
nixos-generate-config --no-filesystems --dir /tmp/config
32+
```
33+
34+
This creates the necessary configuration files under `/tmp/config/`. Copy
35+
`/tmp/config/nixos/hardware-configuration.nix` to your local machine into the
36+
same directory as `disko-config.nix`.
37+
38+
## 3. Set NixOS version to use
39+
1140
```nix
12-
# configuration.nix
13-
{
14-
sources ? {
15-
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.05";
16-
disko = fetchTarball "https://github.com/nix-community/disko/tarball/v1.6.1";
17-
},
18-
system ? builtins.currentSystem,
19-
pkgs ? import sources.nixpkgs { inherit system; config = {}; overlays = []; },
20-
}:
21-
rec {
22-
machine = pkgs.nixos config;
23-
config = { config, pkgs, ... }: {
24-
system.stateVersion = "24.05";
25-
imports = [
26-
"${sources.disko}/module.nix"
27-
"${sources.disko}/example/hybrid.nix"
28-
];
29-
disko.devices.disk.main.device = "/dev/sda";
30-
boot.loader.systemd-boot.enable = true;
31-
};
41+
# default.nix
42+
let
43+
# replace nixos-24.05 with your preferred nixos version or revision from here: https://status.nixos.org/
44+
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-24.05.tar.gz";
45+
in
46+
import (nixpkgs + "/nixos/lib/eval-config.nix") {
47+
modules = [ ./configuration.nix ];
3248
}
3349
```
3450

35-
Generate the disk formatting script:
51+
## 4. Write a NixOS configuration
3652

37-
```bash
38-
disko=$(nix-build configuration.nix -A machine.config.system.build.disko' --no-out-path)
53+
```nix
54+
# configuration.nix
55+
{
56+
imports = [
57+
"${fetchTarball "https://github.com/nix-community/disko/tarball/master"}/module.nix"
58+
./disko-config.nix
59+
./hardware-configuration.nix
60+
];
61+
# Replace this with the system of the installation target you want to install!!!
62+
disko.devices.disk.main.device = "/dev/sda";
63+
64+
# Set this to the NixOS version that you have set in the previous step.
65+
# For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
66+
system.stateVersion = "24.05";
67+
}
3968
```
4069

41-
Generate the store path that includes all the software and configurations for
42-
the NixOS system:
70+
## 5. Build and deploy with nixos-anywhere
4371

44-
```bash
45-
nixos=$(nix-build configuration.nix -A machine.config.system.build.toplevel' --no-out-path)
46-
```
72+
Your current directory now should contain the following files from the previous
73+
step:
74+
75+
- `configuration.nix`, `default.nix`, `disko-config.nix` and
76+
`hardware-configuration.nix`
4777

4878
Run `nixos-anywhere` as follows:
4979

5080
```bash
51-
nixos-anywhere --store-paths $disko $nixos root@machine
81+
nixos-anywhere --store-paths $(nix-build -A config.system.build.disko -A config.system.build.toplevel --no-out-link) root@machine
5282
```

0 commit comments

Comments
 (0)