mirror of
https://github.com/nix-community/disko.git
synced 2026-12-01 13:33:28 +01:00
nix fmt
This commit is contained in:
1 parent
35d4378e74
commit
9f5d4e45cd
12 files changed
+263
-250
No files matched your search
@@ -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
|
||||||
|
|||||||
+4
-4
@@ -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
|
||||||
# ...
|
# ...
|
||||||
|
|||||||
+14
-11
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
|||||||
+16
-13
@@ -85,7 +85,7 @@ let
|
|||||||
else if match "/dev/mapper/.+" dev != null then
|
else if match "/dev/mapper/.+" dev != null then
|
||||||
"${dev}${toString index}" # /dev/mapper/vg-lv1 style
|
"${dev}${toString index}" # /dev/mapper/vg-lv1 style
|
||||||
else if match "/dev/loop[[:digit:]]+" dev != null
|
else if match "/dev/loop[[:digit:]]+" dev != null
|
||||||
then "${dev}p${toString index}" # /dev/mapper/vg-lv1 style
|
then "${dev}p${toString index}" # /dev/mapper/vg-lv1 style
|
||||||
else
|
else
|
||||||
abort ''
|
abort ''
|
||||||
${dev} seems not to be a supported disk format. Please add this to disko in https://github.com/nix-community/disko/blob/master/lib/default.nix
|
${dev} seems not to be a supported disk format. Please add this to disko in https://github.com/nix-community/disko/blob/master/lib/default.nix
|
||||||
@@ -191,10 +191,10 @@ let
|
|||||||
isAttrsOfSubmodule = o: o.type.name == "attrsOf" && o.type.nestedTypes.elemType.name == "submodule";
|
isAttrsOfSubmodule = o: o.type.name == "attrsOf" && o.type.nestedTypes.elemType.name == "submodule";
|
||||||
isSerializable = n: o: !(
|
isSerializable = n: o: !(
|
||||||
lib.hasPrefix "_" n
|
lib.hasPrefix "_" n
|
||||||
|| lib.hasSuffix "Hook" n
|
|| lib.hasSuffix "Hook" n
|
||||||
|| isAttrsOfSubmodule o
|
|| isAttrsOfSubmodule o
|
||||||
# TODO don't hardcode diskoLib.subType options.
|
# TODO don't hardcode diskoLib.subType options.
|
||||||
|| n == "content" || n == "partitions" || n == "datasets" || n == "swap"
|
|| n == "content" || n == "partitions" || n == "datasets" || n == "swap"
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
lib.toShellVars
|
lib.toShellVars
|
||||||
@@ -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:
|
||||||
${diskoLib.indent (diskoLib.defineHookVariables { inherit options; })}
|
if builtins.isString value then ''
|
||||||
${config.preMountHook}
|
(
|
||||||
${diskoLib.indent value}
|
${diskoLib.indent (diskoLib.defineHookVariables { inherit options; })}
|
||||||
${config.postMountHook}
|
${config.preMountHook}
|
||||||
)
|
${diskoLib.indent value}
|
||||||
'' else value) attrs.default;
|
${config.postMountHook}
|
||||||
|
)
|
||||||
|
'' else value)
|
||||||
|
attrs.default;
|
||||||
description = "Mount script";
|
description = "Mount script";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,10 @@
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
vmTools = pkgs.vmTools.override {
|
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
|
kernel = pkgs.aggregateModules
|
||||||
(with nixosConfig.config.boot.kernelPackages; [ kernel ]
|
(with nixosConfig.config.boot.kernelPackages; [ kernel ]
|
||||||
++ lib.optional (lib.elem "zfs" nixosConfig.config.disko.extraRootModules) zfs);
|
++ lib.optional (lib.elem "zfs" nixosConfig.config.disko.extraRootModules) zfs);
|
||||||
};
|
};
|
||||||
cleanedConfig = diskoLib.testLib.prepareDiskoConfig nixosConfig.config diskoLib.testLib.devices;
|
cleanedConfig = diskoLib.testLib.prepareDiskoConfig nixosConfig.config diskoLib.testLib.devices;
|
||||||
systemToInstall = nixosConfig.extendModules {
|
systemToInstall = nixosConfig.extendModules {
|
||||||
|
|||||||
+39
-37
@@ -114,47 +114,49 @@ 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 = [
|
||||||
imports = [
|
({ config, ... }: {
|
||||||
extraSystemConfig
|
imports = [
|
||||||
({ modulesPath, ... }: {
|
extraSystemConfig
|
||||||
imports = [
|
({ modulesPath, ... }: {
|
||||||
(modulesPath + "/testing/test-instrumentation.nix") # we need these 2 modules always to be able to run the tests
|
imports = [
|
||||||
(modulesPath + "/profiles/qemu-guest.nix")
|
(modulesPath + "/testing/test-instrumentation.nix") # we need these 2 modules always to be able to run the tests
|
||||||
];
|
(modulesPath + "/profiles/qemu-guest.nix")
|
||||||
disko.devices = lib.mkForce testConfigBooted.disko.devices;
|
];
|
||||||
})
|
disko.devices = lib.mkForce testConfigBooted.disko.devices;
|
||||||
];
|
})
|
||||||
|
];
|
||||||
|
|
||||||
# since we boot on a different machine, the efi payload needs to be portable
|
# since we boot on a different machine, the efi payload needs to be portable
|
||||||
boot.loader.grub.efiInstallAsRemovable = efi;
|
boot.loader.grub.efiInstallAsRemovable = efi;
|
||||||
boot.loader.grub.efiSupport = efi;
|
boot.loader.grub.efiSupport = efi;
|
||||||
boot.loader.systemd-boot.graceful = true;
|
boot.loader.systemd-boot.graceful = true;
|
||||||
|
|
||||||
# we always want the bind-mounted nix store. otherwise tests take forever
|
# we always want the bind-mounted nix store. otherwise tests take forever
|
||||||
fileSystems."/nix/store" = lib.mkForce {
|
fileSystems."/nix/store" = lib.mkForce {
|
||||||
device = "nix-store";
|
device = "nix-store";
|
||||||
fsType = "9p";
|
fsType = "9p";
|
||||||
neededForBoot = true;
|
neededForBoot = true;
|
||||||
options = [ "trans=virtio" "version=9p2000.L" "cache=loose" ];
|
options = [ "trans=virtio" "version=9p2000.L" "cache=loose" ];
|
||||||
};
|
};
|
||||||
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
|
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
|
||||||
|
|
||||||
# grub will install to these devices, we need to force those or we are offset by 1
|
# grub will install to these devices, we need to force those or we are offset by 1
|
||||||
# we use mkOveride 70, so that users can override this with mkForce in case they are testing grub mirrored boots
|
# we use mkOveride 70, so that users can override this with mkForce in case they are testing grub mirrored boots
|
||||||
boot.loader.grub.devices = lib.mkOverride 70 testConfigInstall.boot.loader.grub.devices;
|
boot.loader.grub.devices = lib.mkOverride 70 testConfigInstall.boot.loader.grub.devices;
|
||||||
|
|
||||||
assertions = [
|
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 = ''
|
message = ''
|
||||||
When using `--vm-test` in combination with `mirroredBoots`,
|
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 [];`.
|
it is necessary to configure `boot.loader.grub.devices` as an empty list by setting `boot.loader.grub.devices = lib.mkForce [];`.
|
||||||
This adjustment is crucial because the `--vm-test` mechanism automatically overrides the grub boot devices as part of the virtual machine test.
|
This adjustment is crucial because the `--vm-test` mechanism automatically overrides the grub boot devices as part of the virtual machine test.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
})];
|
})
|
||||||
|
];
|
||||||
}).config.system.build.toplevel;
|
}).config.system.build.toplevel;
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|||||||
+3
-3
@@ -32,9 +32,9 @@ let
|
|||||||
lib.concatMapStringsSep
|
lib.concatMapStringsSep
|
||||||
"\n"
|
"\n"
|
||||||
(file: ''
|
(file: ''
|
||||||
if ! test -e "${mountpoint}/${file.path}"; then
|
if ! test -e "${mountpoint}/${file.path}"; then
|
||||||
btrfs filesystem mkswapfile --size ${file.size} "${mountpoint}/${file.path}"
|
btrfs filesystem mkswapfile --size ${file.size} "${mountpoint}/${file.path}"
|
||||||
fi
|
fi
|
||||||
'')
|
'')
|
||||||
(lib.attrValues swap);
|
(lib.attrValues swap);
|
||||||
|
|
||||||
|
|||||||
+13
-11
@@ -55,15 +55,17 @@ in
|
|||||||
};
|
};
|
||||||
label = lib.mkOption {
|
label = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = let
|
default =
|
||||||
# 72 bytes is the maximum length of a GPT partition name
|
let
|
||||||
# the labels seem to be in UTF-16, so 2 bytes per character
|
# 72 bytes is the maximum length of a GPT partition name
|
||||||
limit = 36;
|
# the labels seem to be in UTF-16, so 2 bytes per character
|
||||||
label = "${config._parent.type}-${config._parent.name}-${partition.config.name}";
|
limit = 36;
|
||||||
in if (lib.stringLength label) > limit then
|
label = "${config._parent.type}-${config._parent.name}-${partition.config.name}";
|
||||||
builtins.substring 0 limit (builtins.hashString "sha256" label)
|
in
|
||||||
else
|
if (lib.stringLength label) > limit then
|
||||||
label;
|
builtins.substring 0 limit (builtins.hashString "sha256" label)
|
||||||
|
else
|
||||||
|
label;
|
||||||
};
|
};
|
||||||
size = lib.mkOption {
|
size = lib.mkOption {
|
||||||
type = lib.types.either (lib.types.enum [ "100%" ]) (lib.types.strMatching "[0-9]+[KMGTP]?");
|
type = lib.types.either (lib.types.enum [ "100%" ]) (lib.types.strMatching "[0-9]+[KMGTP]?");
|
||||||
@@ -76,7 +78,7 @@ in
|
|||||||
};
|
};
|
||||||
alignment = lib.mkOption {
|
alignment = lib.mkOption {
|
||||||
type = lib.types.int;
|
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";
|
description = "Alignment of the partition, if sectors are used as start or end it can be aligned to 1";
|
||||||
};
|
};
|
||||||
start = lib.mkOption {
|
start = lib.mkOption {
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -115,13 +115,14 @@
|
|||||||
(lv: [
|
(lv: [
|
||||||
(lib.optional (lv.content != null) lv.content._config)
|
(lib.optional (lv.content != null) lv.content._config)
|
||||||
(lib.optional (lv.lvm_type != null) {
|
(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 == "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 == "raid5" ||
|
(lv.lvm_type == "raid4" ||
|
||||||
lv.lvm_type == "raid6") "raid456";
|
lv.lvm_type == "raid5" ||
|
||||||
|
lv.lvm_type == "raid6") "raid456";
|
||||||
|
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
|
|||||||
+148
-147
@@ -6,155 +6,156 @@
|
|||||||
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.types.enum [ "table" ];
|
type = lib.mkOption {
|
||||||
internal = true;
|
type = lib.types.enum [ "table" ];
|
||||||
description = "Partition table";
|
internal = true;
|
||||||
};
|
description = "Partition table";
|
||||||
device = lib.mkOption {
|
};
|
||||||
type = lib.types.str;
|
device = lib.mkOption {
|
||||||
default = device;
|
type = lib.types.str;
|
||||||
description = "Device to partition";
|
default = device;
|
||||||
};
|
description = "Device to partition";
|
||||||
format = lib.mkOption {
|
};
|
||||||
type = lib.types.enum [ "gpt" "msdos" ];
|
format = lib.mkOption {
|
||||||
default = "gpt";
|
type = lib.types.enum [ "gpt" "msdos" ];
|
||||||
description = "The kind of partition table";
|
default = "gpt";
|
||||||
};
|
description = "The kind of partition table";
|
||||||
partitions = lib.mkOption {
|
};
|
||||||
type = lib.types.listOf (lib.types.submodule ({ name, ... }@partition: {
|
partitions = lib.mkOption {
|
||||||
options = {
|
type = lib.types.listOf (lib.types.submodule ({ name, ... }@partition: {
|
||||||
part-type = lib.mkOption {
|
options = {
|
||||||
type = lib.types.enum [ "primary" "logical" "extended" ];
|
part-type = lib.mkOption {
|
||||||
default = "primary";
|
type = lib.types.enum [ "primary" "logical" "extended" ];
|
||||||
description = "Partition type";
|
default = "primary";
|
||||||
|
description = "Partition type";
|
||||||
|
};
|
||||||
|
fs-type = lib.mkOption {
|
||||||
|
type = lib.types.nullOr (lib.types.enum [ "btrfs" "ext2" "ext3" "ext4" "fat16" "fat32" "hfs" "hfs+" "linux-swap" "ntfs" "reiserfs" "udf" "xfs" ]);
|
||||||
|
default = null;
|
||||||
|
description = "Filesystem type to use";
|
||||||
|
};
|
||||||
|
name = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
description = "Name of the partition";
|
||||||
|
};
|
||||||
|
start = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "0%";
|
||||||
|
description = "Start of the partition";
|
||||||
|
};
|
||||||
|
end = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "100%";
|
||||||
|
description = "End of the partition";
|
||||||
|
};
|
||||||
|
flags = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
description = "Partition flags";
|
||||||
|
};
|
||||||
|
bootable = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Whether to make the partition bootable";
|
||||||
|
};
|
||||||
|
content = diskoLib.partitionType { parent = config; device = diskoLib.deviceNumbering config.device partition.config._index; };
|
||||||
|
_index = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = lib.toInt (lib.head (builtins.match ".*entry ([[:digit:]]+)]" name));
|
||||||
|
};
|
||||||
};
|
};
|
||||||
fs-type = lib.mkOption {
|
}));
|
||||||
type = lib.types.nullOr (lib.types.enum [ "btrfs" "ext2" "ext3" "ext4" "fat16" "fat32" "hfs" "hfs+" "linux-swap" "ntfs" "reiserfs" "udf" "xfs" ]);
|
default = [ ];
|
||||||
default = null;
|
description = "List of partitions to add to the partition table";
|
||||||
description = "Filesystem type to use";
|
};
|
||||||
};
|
_parent = lib.mkOption {
|
||||||
name = lib.mkOption {
|
internal = true;
|
||||||
type = lib.types.nullOr lib.types.str;
|
default = parent;
|
||||||
description = "Name of the partition";
|
};
|
||||||
};
|
_meta = lib.mkOption {
|
||||||
start = lib.mkOption {
|
internal = true;
|
||||||
type = lib.types.str;
|
readOnly = true;
|
||||||
default = "0%";
|
type = lib.types.functionTo diskoLib.jsonType;
|
||||||
description = "Start of the partition";
|
default = dev:
|
||||||
};
|
lib.foldr lib.recursiveUpdate { } (lib.imap
|
||||||
end = lib.mkOption {
|
(_index: partition:
|
||||||
type = lib.types.str;
|
lib.optionalAttrs (partition.content != null) (partition.content._meta dev)
|
||||||
default = "100%";
|
|
||||||
description = "End of the partition";
|
|
||||||
};
|
|
||||||
flags = lib.mkOption {
|
|
||||||
type = lib.types.listOf lib.types.str;
|
|
||||||
default = [ ];
|
|
||||||
description = "Partition flags";
|
|
||||||
};
|
|
||||||
bootable = lib.mkOption {
|
|
||||||
type = lib.types.bool;
|
|
||||||
default = false;
|
|
||||||
description = "Whether to make the partition bootable";
|
|
||||||
};
|
|
||||||
content = diskoLib.partitionType { parent = config; device = diskoLib.deviceNumbering config.device partition.config._index; };
|
|
||||||
_index = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
default = lib.toInt (lib.head (builtins.match ".*entry ([[:digit:]]+)]" name));
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
default = [ ];
|
|
||||||
description = "List of partitions to add to the partition table";
|
|
||||||
};
|
|
||||||
_parent = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
default = parent;
|
|
||||||
};
|
|
||||||
_meta = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
readOnly = true;
|
|
||||||
type = lib.types.functionTo diskoLib.jsonType;
|
|
||||||
default = dev:
|
|
||||||
lib.foldr lib.recursiveUpdate { } (lib.imap
|
|
||||||
(_index: partition:
|
|
||||||
lib.optionalAttrs (partition.content != null) (partition.content._meta dev)
|
|
||||||
)
|
|
||||||
config.partitions);
|
|
||||||
description = "Metadata";
|
|
||||||
};
|
|
||||||
_create = diskoLib.mkCreateOption {
|
|
||||||
inherit config options;
|
|
||||||
default = ''
|
|
||||||
if ! blkid "${config.device}" >/dev/null; then
|
|
||||||
parted -s ${config.device} -- mklabel ${config.format}
|
|
||||||
${lib.concatStrings (map (partition: ''
|
|
||||||
${lib.optionalString (config.format == "gpt") ''
|
|
||||||
parted -s ${config.device} -- mkpart ${partition.name} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
|
||||||
''}
|
|
||||||
${lib.optionalString (config.format == "msdos") ''
|
|
||||||
parted -s ${config.device} -- mkpart ${partition.part-type} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
|
||||||
''}
|
|
||||||
# ensure /dev/disk/by-path/..-partN exists before continuing
|
|
||||||
partprobe ${config.device}
|
|
||||||
udevadm trigger --subsystem-match=block
|
|
||||||
udevadm settle
|
|
||||||
${lib.optionalString partition.bootable ''
|
|
||||||
parted -s ${config.device} -- set ${toString partition._index} boot on
|
|
||||||
''}
|
|
||||||
${lib.concatMapStringsSep "" (flag: ''
|
|
||||||
parted -s ${config.device} -- set ${toString partition._index} ${flag} on
|
|
||||||
'') partition.flags}
|
|
||||||
# ensure further operations can detect new partitions
|
|
||||||
partprobe ${config.device}
|
|
||||||
udevadm trigger --subsystem-match=block
|
|
||||||
udevadm settle
|
|
||||||
'') config.partitions)}
|
|
||||||
fi
|
|
||||||
${lib.concatStrings (map (partition: ''
|
|
||||||
${lib.optionalString (partition.content != null) partition.content._create}
|
|
||||||
'') config.partitions)}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
_mount = diskoLib.mkMountOption {
|
|
||||||
inherit config options;
|
|
||||||
default =
|
|
||||||
let
|
|
||||||
partMounts = lib.foldr lib.recursiveUpdate { } (map
|
|
||||||
(partition:
|
|
||||||
lib.optionalAttrs (partition.content != null) partition.content._mount
|
|
||||||
)
|
)
|
||||||
config.partitions);
|
config.partitions);
|
||||||
in
|
description = "Metadata";
|
||||||
{
|
};
|
||||||
dev = partMounts.dev or "";
|
_create = diskoLib.mkCreateOption {
|
||||||
fs = partMounts.fs or { };
|
inherit config options;
|
||||||
};
|
default = ''
|
||||||
|
if ! blkid "${config.device}" >/dev/null; then
|
||||||
|
parted -s ${config.device} -- mklabel ${config.format}
|
||||||
|
${lib.concatStrings (map (partition: ''
|
||||||
|
${lib.optionalString (config.format == "gpt") ''
|
||||||
|
parted -s ${config.device} -- mkpart ${partition.name} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
||||||
|
''}
|
||||||
|
${lib.optionalString (config.format == "msdos") ''
|
||||||
|
parted -s ${config.device} -- mkpart ${partition.part-type} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
||||||
|
''}
|
||||||
|
# ensure /dev/disk/by-path/..-partN exists before continuing
|
||||||
|
partprobe ${config.device}
|
||||||
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
|
${lib.optionalString partition.bootable ''
|
||||||
|
parted -s ${config.device} -- set ${toString partition._index} boot on
|
||||||
|
''}
|
||||||
|
${lib.concatMapStringsSep "" (flag: ''
|
||||||
|
parted -s ${config.device} -- set ${toString partition._index} ${flag} on
|
||||||
|
'') partition.flags}
|
||||||
|
# ensure further operations can detect new partitions
|
||||||
|
partprobe ${config.device}
|
||||||
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
|
'') config.partitions)}
|
||||||
|
fi
|
||||||
|
${lib.concatStrings (map (partition: ''
|
||||||
|
${lib.optionalString (partition.content != null) partition.content._create}
|
||||||
|
'') config.partitions)}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
_mount = diskoLib.mkMountOption {
|
||||||
|
inherit config options;
|
||||||
|
default =
|
||||||
|
let
|
||||||
|
partMounts = lib.foldr lib.recursiveUpdate { } (map
|
||||||
|
(partition:
|
||||||
|
lib.optionalAttrs (partition.content != null) partition.content._mount
|
||||||
|
)
|
||||||
|
config.partitions);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
dev = partMounts.dev or "";
|
||||||
|
fs = partMounts.fs or { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
_config = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
default =
|
||||||
|
map
|
||||||
|
(partition:
|
||||||
|
lib.optional (partition.content != null) partition.content._config
|
||||||
|
)
|
||||||
|
config.partitions;
|
||||||
|
description = "NixOS configuration";
|
||||||
|
};
|
||||||
|
_pkgs = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||||
|
default = pkgs:
|
||||||
|
[ pkgs.parted pkgs.systemdMinimal ] ++ lib.flatten (map
|
||||||
|
(partition:
|
||||||
|
lib.optional (partition.content != null) (partition.content._pkgs pkgs)
|
||||||
|
)
|
||||||
|
config.partitions);
|
||||||
|
description = "Packages";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
_config = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
readOnly = true;
|
|
||||||
default =
|
|
||||||
map
|
|
||||||
(partition:
|
|
||||||
lib.optional (partition.content != null) partition.content._config
|
|
||||||
)
|
|
||||||
config.partitions;
|
|
||||||
description = "NixOS configuration";
|
|
||||||
};
|
|
||||||
_pkgs = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
readOnly = true;
|
|
||||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
|
||||||
default = pkgs:
|
|
||||||
[ pkgs.parted pkgs.systemdMinimal ] ++ lib.flatten (map
|
|
||||||
(partition:
|
|
||||||
lib.optional (partition.content != null) (partition.content._pkgs pkgs)
|
|
||||||
)
|
|
||||||
config.partitions);
|
|
||||||
description = "Packages";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
+14
-13
@@ -52,19 +52,20 @@
|
|||||||
description = "Metadata";
|
description = "Metadata";
|
||||||
};
|
};
|
||||||
|
|
||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption
|
||||||
inherit config options;
|
{
|
||||||
# -u prevents mounting newly created datasets, which is
|
inherit config options;
|
||||||
# important to prevent accidental shadowing of mount points
|
# -u prevents mounting newly created datasets, which is
|
||||||
# since (create order != mount order)
|
# important to prevent accidental shadowing of mount points
|
||||||
# -p creates parents automatically
|
# since (create order != mount order)
|
||||||
default = ''
|
# -p creates parents automatically
|
||||||
if ! zfs get type ${config._name} >/dev/null 2>&1; then
|
default = ''
|
||||||
zfs create -up ${config._name} \
|
if ! zfs get type ${config._name} >/dev/null 2>&1; then
|
||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
zfs create -up ${config._name} \
|
||||||
fi
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
||||||
'';
|
fi
|
||||||
} // { readOnly = false; };
|
'';
|
||||||
|
} // { readOnly = false; };
|
||||||
|
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
|
|||||||
Reference in new issue
Block a user