This commit is contained in:
Qubasa authored and mergify[bot] committed 2024-04-29 14:57:02 +00:00
1 parent 35d4378e74
commit 9f5d4e45cd
11 files changed
+45 -32

No files matched your search

+2 -2
View File
@@ -93,8 +93,8 @@ A simple disko configuration may look like this:
```
If you'd saved this configuration in /tmp/disk-config.nix, and wanted to create
a disk named /dev/sda, you would run the following command to partition,
format and mount the disk.
a disk named /dev/sda, you would run the following command to partition, format
and mount the disk.
```console
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disk-config.nix
+4 -4
View File
@@ -70,8 +70,8 @@ and made a note of its URL.
Your configuration needs to be saved on the new machine for example
as /tmp/disk-config.nix. You can do this using the `curl` command to download
from the url you noted above, using the `-o` option to save the file as
disk-config.nix. Your commands would look like this if you had chosen the
hybrid layout:
disk-config.nix. Your commands would look like this if you had chosen the hybrid
layout:
```console
cd /tmp
@@ -182,8 +182,8 @@ of the NixOS manual. The following configuration for `grub` works for both EFI
and BIOS systems. Add this to your configuration.nix, commenting out the
existing lines that configure `systemd-boot`. The entries will look like this:
**Note:** Its not necessary to set `boot.loader.grub.device` here, since Disko will
take care of that automatically.
**Note:** Its not necessary to set `boot.loader.grub.device` here, since Disko
will take care of that automatically.
```nix
# ...
+14 -11
View File
@@ -51,9 +51,11 @@ generate disk images:
### Generating the `.raw` VM Image
1. **Create a NixOS configuration that includes the disko and the disk configuration of your choice**
1. **Create a NixOS configuration that includes the disko and the disk
configuration of your choice**
In the this example we create a flake containing a nixos configuration for `myhost`.
In the this example we create a flake containing a nixos configuration for
`myhost`.
```nix
# save this as flake.nix
@@ -86,15 +88,15 @@ In the this example we create a flake containing a nixos configuration for `myho
}
```
2. **Build the disko image script:** Replace `myhost` in the command below with your
specific system configuration name:
2. **Build the disko image script:** Replace `myhost` in the command below with
your specific system configuration name:
```console
nix build .#nixosConfigurations.myhost.config.system.build.diskoImagesScript
```
3. **Execute the disko image script:** Execute the generated disko image script. Running
`./result --help` will output the available options:
3. **Execute the disko image script:** Execute the generated disko image script.
Running `./result --help` will output the available options:
```console
./result --help
@@ -124,9 +126,10 @@ In the this example we create a flake containing a nixos configuration for `myho
sudo ./result --build-memory 2048
```
The script will generate the actual image outside of the nix store in the current working directory.
The create image names depend on the names used in `disko.devices.disk` attrset in the NixOS configuration.
In our code example it will produce the following image:
The script will generate the actual image outside of the nix store in the
current working directory. The create image names depend on the names used in
`disko.devices.disk` attrset in the NixOS configuration. In our code example it will
produce the following image:
```
$ ls -la vdb.raw
@@ -142,8 +145,8 @@ In the this example we create a flake containing a nixos configuration for `myho
```
- If the `.raw` image size is not optimal, use `--write-to-disk` to write
directly to a drive. This bypasses the `.raw` file generation, which saves on read/write operations
and is suitable for single disk setups.
directly to a drive. This bypasses the `.raw` file generation, which saves on
read/write operations and is suitable for single disk setups.
### Understanding the Image Generation Process
+1 -1
View File
@@ -29,7 +29,7 @@
{
disko = pkgs.callPackage ./package.nix { };
# alias to make `nix run` more convenient
disko-install = self.packages.${system}.disko.overrideAttrs (old: {
disko-install = self.packages.${system}.disko.overrideAttrs (_old: {
name = "disko-install";
});
default = self.packages.${system}.disko;
+5 -2
View File
@@ -245,14 +245,17 @@ let
internal = true;
readOnly = true;
type = diskoLib.jsonType;
default = lib.mapAttrsRecursive (name: value: if builtins.isString value then ''
default = lib.mapAttrsRecursive
(_name: value:
if builtins.isString value then ''
(
${diskoLib.indent (diskoLib.defineHookVariables { inherit options; })}
${config.preMountHook}
${diskoLib.indent value}
${config.postMountHook}
)
'' else value) attrs.default;
'' else value)
attrs.default;
description = "Mount script";
};
+1 -1
View File
@@ -8,7 +8,7 @@
}:
let
vmTools = pkgs.vmTools.override {
rootModules = ["9p" "9pnet_virtio" "virtio_pci" "virtio_blk"] ++ nixosConfig.config.disko.extraRootModules;
rootModules = [ "9p" "9pnet_virtio" "virtio_pci" "virtio_blk" ] ++ nixosConfig.config.disko.extraRootModules;
kernel = pkgs.aggregateModules
(with nixosConfig.config.boot.kernelPackages; [ kernel ]
++ lib.optional (lib.elem "zfs" nixosConfig.config.disko.extraRootModules) zfs);
+5 -3
View File
@@ -114,7 +114,8 @@ let
};
installedTopLevel = ((if extendModules != null then extendModules else installed-system-eval.extendModules) {
modules = [({config, ...}: {
modules = [
({ config, ... }: {
imports = [
extraSystemConfig
({ modulesPath, ... }: {
@@ -146,7 +147,7 @@ let
assertions = [
{
assertion = builtins.length config.boot.loader.grub.mirroredBoots > 1 -> config.boot.loader.grub.devices == [];
assertion = builtins.length config.boot.loader.grub.mirroredBoots > 1 -> config.boot.loader.grub.devices == [ ];
message = ''
When using `--vm-test` in combination with `mirroredBoots`,
it is necessary to configure `boot.loader.grub.devices` as an empty list by setting `boot.loader.grub.devices = lib.mkForce [];`.
@@ -154,7 +155,8 @@ let
'';
}
];
})];
})
];
}).config.system.build.toplevel;
in
+6 -4
View File
@@ -55,12 +55,14 @@ in
};
label = lib.mkOption {
type = lib.types.str;
default = let
default =
let
# 72 bytes is the maximum length of a GPT partition name
# the labels seem to be in UTF-16, so 2 bytes per character
limit = 36;
label = "${config._parent.type}-${config._parent.name}-${partition.config.name}";
in if (lib.stringLength label) > limit then
in
if (lib.stringLength label) > limit then
builtins.substring 0 limit (builtins.hashString "sha256" label)
else
label;
@@ -76,7 +78,7 @@ in
};
alignment = lib.mkOption {
type = lib.types.int;
default = if (builtins.substring (builtins.stringLength partition.config.start - 1) 1 partition.config.start == "s" || (builtins.substring (builtins.stringLength partition.config.end - 1) 1 partition.config.end == "s" )) then 1 else 0;
default = if (builtins.substring (builtins.stringLength partition.config.start - 1) 1 partition.config.start == "s" || (builtins.substring (builtins.stringLength partition.config.end - 1) 1 partition.config.end == "s")) then 1 else 0;
description = "Alignment of the partition, if sectors are used as start or end it can be aligned to 1";
};
start = lib.mkOption {
@@ -95,7 +97,7 @@ in
};
content = diskoLib.partitionType { parent = config; device = partition.config.device; };
hybrid = lib.mkOption {
type = lib.types.nullOr (lib.types.submodule ({name, ...} @ hp: {
type = lib.types.nullOr (lib.types.submodule ({ ... } @ hp: {
options = {
mbrPartitionType = lib.mkOption {
type = lib.types.nullOr lib.types.str;
+3 -2
View File
@@ -115,11 +115,12 @@
(lv: [
(lib.optional (lv.content != null) lv.content._config)
(lib.optional (lv.lvm_type != null) {
boot.initrd.kernelModules = [(if lv.lvm_type == "mirror" then "dm-mirror" else "dm-raid")]
boot.initrd.kernelModules = [ (if lv.lvm_type == "mirror" then "dm-mirror" else "dm-raid") ]
++ lib.optional (lv.lvm_type == "raid0") "raid0"
++ lib.optional (lv.lvm_type == "raid1") "raid1"
# ++ lib.optional (lv.lvm_type == "raid10") "raid10"
++ lib.optional (lv.lvm_type == "raid4" ||
++ lib.optional
(lv.lvm_type == "raid4" ||
lv.lvm_type == "raid5" ||
lv.lvm_type == "raid6") "raid456";
+2 -1
View File
@@ -6,7 +6,8 @@
If you encounter errors similar to:
"error: The option `disko.devices.disk.disk1.content.partitions."[definition 1-entry 1]".content._config` is read-only, but it's set multiple times,"
this is likely due to the use of the legacy table type.
'' {
''
{
type = lib.mkOption {
type = lib.types.enum [ "table" ];
internal = true;
+2 -1
View File
@@ -52,7 +52,8 @@
description = "Metadata";
};
_create = diskoLib.mkCreateOption {
_create = diskoLib.mkCreateOption
{
inherit config options;
# -u prevents mounting newly created datasets, which is
# important to prevent accidental shadowing of mount points