This commit is contained in:
Qubasa 2024-04-21 21:25:44 +02:00 committed by mergify[bot]
parent 35d4378e74
commit 9f5d4e45cd
12 changed files with 263 additions and 250 deletions

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 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, a disk named /dev/sda, you would run the following command to partition, format
format and mount the disk. and mount the disk.
```console ```console
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disk-config.nix sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disk-config.nix

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 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 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 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 disk-config.nix. Your commands would look like this if you had chosen the hybrid
hybrid layout: layout:
```console ```console
cd /tmp 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 and BIOS systems. Add this to your configuration.nix, commenting out the
existing lines that configure `systemd-boot`. The entries will look like this: 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 **Note:** Its not necessary to set `boot.loader.grub.device` here, since Disko
take care of that automatically. will take care of that automatically.
```nix ```nix
# ... # ...

View File

@ -51,9 +51,11 @@ generate disk images:
### Generating the `.raw` VM Image ### 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 ```nix
# save this as flake.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 2. **Build the disko image script:** Replace `myhost` in the command below with
specific system configuration name: your specific system configuration name:
```console ```console
nix build .#nixosConfigurations.myhost.config.system.build.diskoImagesScript nix build .#nixosConfigurations.myhost.config.system.build.diskoImagesScript
``` ```
3. **Execute the disko image script:** Execute the generated disko image script. Running 3. **Execute the disko image script:** Execute the generated disko image script.
`./result --help` will output the available options: Running `./result --help` will output the available options:
```console ```console
./result --help ./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 sudo ./result --build-memory 2048
``` ```
The script will generate the actual image outside of the nix store in the current working directory. The script will generate the actual image outside of the nix store in the
The create image names depend on the names used in `disko.devices.disk` attrset in the NixOS configuration. current working directory. The create image names depend on the names used in
In our code example it will produce the following image: `disko.devices.disk` attrset in the NixOS configuration. In our code example it will
produce the following image:
``` ```
$ ls -la vdb.raw $ 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 - 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 directly to a drive. This bypasses the `.raw` file generation, which saves on
and is suitable for single disk setups. read/write operations and is suitable for single disk setups.
### Understanding the Image Generation Process ### Understanding the Image Generation Process

View File

@ -29,7 +29,7 @@
{ {
disko = pkgs.callPackage ./package.nix { }; disko = pkgs.callPackage ./package.nix { };
# alias to make `nix run` more convenient # 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"; name = "disko-install";
}); });
default = self.packages.${system}.disko; default = self.packages.${system}.disko;

View File

@ -245,14 +245,17 @@ let
internal = true; internal = true;
readOnly = true; readOnly = true;
type = diskoLib.jsonType; 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; })} ${diskoLib.indent (diskoLib.defineHookVariables { inherit options; })}
${config.preMountHook} ${config.preMountHook}
${diskoLib.indent value} ${diskoLib.indent value}
${config.postMountHook} ${config.postMountHook}
) )
'' else value) attrs.default; '' else value)
attrs.default;
description = "Mount script"; description = "Mount script";
}; };

View File

@ -114,7 +114,8 @@ let
}; };
installedTopLevel = ((if extendModules != null then extendModules else installed-system-eval.extendModules) { installedTopLevel = ((if extendModules != null then extendModules else installed-system-eval.extendModules) {
modules = [({config, ...}: { modules = [
({ config, ... }: {
imports = [ imports = [
extraSystemConfig extraSystemConfig
({ modulesPath, ... }: { ({ modulesPath, ... }: {
@ -154,7 +155,8 @@ let
''; '';
} }
]; ];
})]; })
];
}).config.system.build.toplevel; }).config.system.build.toplevel;
in in

View File

@ -55,12 +55,14 @@ in
}; };
label = lib.mkOption { label = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = let default =
let
# 72 bytes is the maximum length of a GPT partition name # 72 bytes is the maximum length of a GPT partition name
# the labels seem to be in UTF-16, so 2 bytes per character # the labels seem to be in UTF-16, so 2 bytes per character
limit = 36; limit = 36;
label = "${config._parent.type}-${config._parent.name}-${partition.config.name}"; 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) builtins.substring 0 limit (builtins.hashString "sha256" label)
else else
label; label;
@ -95,7 +97,7 @@ in
}; };
content = diskoLib.partitionType { parent = config; device = partition.config.device; }; content = diskoLib.partitionType { parent = config; device = partition.config.device; };
hybrid = lib.mkOption { hybrid = lib.mkOption {
type = lib.types.nullOr (lib.types.submodule ({name, ...} @ hp: { type = lib.types.nullOr (lib.types.submodule ({ ... } @ hp: {
options = { options = {
mbrPartitionType = lib.mkOption { mbrPartitionType = lib.mkOption {
type = lib.types.nullOr lib.types.str; type = lib.types.nullOr lib.types.str;

View File

@ -119,7 +119,8 @@
++ lib.optional (lv.lvm_type == "raid0") "raid0" ++ lib.optional (lv.lvm_type == "raid0") "raid0"
++ lib.optional (lv.lvm_type == "raid1") "raid1" ++ lib.optional (lv.lvm_type == "raid1") "raid1"
# ++ lib.optional (lv.lvm_type == "raid10") "raid10" # ++ 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 == "raid5" ||
lv.lvm_type == "raid6") "raid456"; lv.lvm_type == "raid6") "raid456";

View File

@ -6,7 +6,8 @@
If you encounter errors similar to: 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," "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. this is likely due to the use of the legacy table type.
'' { ''
{
type = lib.mkOption { type = lib.mkOption {
type = lib.types.enum [ "table" ]; type = lib.types.enum [ "table" ];
internal = true; internal = true;

View File

@ -52,7 +52,8 @@
description = "Metadata"; description = "Metadata";
}; };
_create = diskoLib.mkCreateOption { _create = diskoLib.mkCreateOption
{
inherit config options; inherit config options;
# -u prevents mounting newly created datasets, which is # -u prevents mounting newly created datasets, which is
# important to prevent accidental shadowing of mount points # important to prevent accidental shadowing of mount points