@@ -8,45 +8,75 @@ in your NixOS configuration and define disko devices as described in the
8
8
Let's assume that your NixOS configuration lives in ` configuration.nix ` and your
9
9
target machine is called ` machine ` :
10
10
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
+
11
40
``` 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 ];
32
48
}
33
49
```
34
50
35
- Generate the disk formatting script:
51
+ ## 4. Write a NixOS configuration
36
52
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
+ }
39
68
```
40
69
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
43
71
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 `
47
77
48
78
Run ` nixos-anywhere ` as follows:
49
79
50
80
``` 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
52
82
```
0 commit comments