mirror of
https://github.com/nix-community/nixos-anywhere.git
synced 2024-10-05 12:17:10 +03:00
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
This commit is contained in:
parent
db2478a9a6
commit
ce18c086d8
@ -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
|
Let's assume that your NixOS configuration lives in `configuration.nix` and your
|
||||||
target machine is called `machine`:
|
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
|
```nix
|
||||||
# configuration.nix
|
# default.nix
|
||||||
{
|
let
|
||||||
sources ? {
|
# replace nixos-24.05 with your preferred nixos version or revision from here: https://status.nixos.org/
|
||||||
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.05";
|
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-24.05.tar.gz";
|
||||||
disko = fetchTarball "https://github.com/nix-community/disko/tarball/v1.6.1";
|
in
|
||||||
},
|
import (nixpkgs + "/nixos/lib/eval-config.nix") {
|
||||||
system ? builtins.currentSystem,
|
modules = [ ./configuration.nix ];
|
||||||
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;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Generate the disk formatting script:
|
## 4. Write a NixOS configuration
|
||||||
|
|
||||||
```bash
|
```nix
|
||||||
disko=$(nix-build configuration.nix -A machine.config.system.build.disko' --no-out-path)
|
# 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
|
## 5. Build and deploy with nixos-anywhere
|
||||||
the NixOS system:
|
|
||||||
|
|
||||||
```bash
|
Your current directory now should contain the following files from the previous
|
||||||
nixos=$(nix-build configuration.nix -A machine.config.system.build.toplevel' --no-out-path)
|
step:
|
||||||
```
|
|
||||||
|
- `configuration.nix`, `default.nix`, `disko-config.nix` and
|
||||||
|
`hardware-configuration.nix`
|
||||||
|
|
||||||
Run `nixos-anywhere` as follows:
|
Run `nixos-anywhere` as follows:
|
||||||
|
|
||||||
```bash
|
```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
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user