mirror of
https://github.com/nix-community/disko.git
synced 2026-12-01 05:23:28 +01:00
Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff442f5d14 | ||
|
|
6bb82b77ce | ||
|
|
06fb9283ca | ||
|
|
69265ccde5 | ||
|
|
cbc1f418d0 | ||
|
|
aa5d53aee8 | ||
|
|
c7e0b00007 | ||
|
|
aba0ae38df | ||
|
|
b5cfd59e9a | ||
|
|
c4fe2d108b | ||
|
|
78d6a1365c | ||
|
|
8d78963819 | ||
|
|
b5d1320ebc | ||
|
|
7b63642358 |
No files matched your search
@@ -4,3 +4,6 @@ result-*
|
|||||||
|
|
||||||
# Created by the NixOS interactive test driver
|
# Created by the NixOS interactive test driver
|
||||||
.nixos-test-history
|
.nixos-test-history
|
||||||
|
|
||||||
|
# Created by `:bl` in `nix repl`
|
||||||
|
repl-result-out
|
||||||
+74
-8
@@ -1,11 +1,9 @@
|
|||||||
# Generating Disk Images with Secrets Included using Disko
|
# Generating Disk Images with Secrets Included using Disko
|
||||||
|
|
||||||
Using Disko on NixOS allows you to efficiently create `.raw` VM images from a
|
Using Disko on NixOS allows you to efficiently create `.raw` disk images from a system configuration.
|
||||||
system configuration. The generated image can be used as a VM or directly
|
Follow the steps below to generate disk images:
|
||||||
written to a physical drive to create a bootable disk. Follow the steps below to
|
|
||||||
generate disk images:
|
|
||||||
|
|
||||||
## Generating the `.raw` VM Image
|
## Generating the `.raw` Image
|
||||||
|
|
||||||
1. **Create a NixOS configuration that includes the disko and the disk
|
1. **Create a NixOS configuration that includes the disko and the disk
|
||||||
configuration of your choice**
|
configuration of your choice**
|
||||||
@@ -24,16 +22,29 @@ In the this example we create a flake containing a nixos configuration for
|
|||||||
disko.inputs.nixpkgs.follows = "nixpkgs";
|
disko.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, disko, nixpkgs }: {
|
outputs = { self, disko, nixpkgs, ... }: {
|
||||||
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
|
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
modules = [
|
modules = [
|
||||||
# You can get this file from here: https://github.com/nix-community/disko/blob/master/example/simple-efi.nix
|
# You can get this file from here: https://github.com/nix-community/disko/blob/master/example/simple-efi.nix
|
||||||
./simple-efi.nix
|
./simple-efi.nix
|
||||||
disko.nixosModules.disko
|
disko.nixosModules.disko
|
||||||
({ config, ... }: {
|
({ config, modulesPath, ... }: {
|
||||||
|
imports = [
|
||||||
|
# include this line to boot to boot the image inside a VM
|
||||||
|
# "${modulesPath}/profiles/qemu-guest.nix"
|
||||||
|
# On other hardware, you may need a hardware-configuration.nix as generated by nixos-generate-config or use nixos-facter (https://github.com/numtide/nixos-facter)
|
||||||
|
# ./hardware-configuration.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
# Optional. Useful for testing
|
||||||
|
# users.users.root.initialPassword = "root";
|
||||||
|
|
||||||
|
boot.loader.grub.efiSupport = lib.mkDefault true;
|
||||||
|
boot.loader.grub.efiInstallAsRemovable = lib.mkDefault true;
|
||||||
|
|
||||||
# shut up state version warning
|
# shut up state version warning
|
||||||
system.stateVersion = config.system.nixos.version;
|
system.stateVersion = config.system.nixos.release;
|
||||||
# Adjust this to your liking.
|
# Adjust this to your liking.
|
||||||
# WARNING: if you set a too low value the image might be not big enough to contain the nixos installation
|
# WARNING: if you set a too low value the image might be not big enough to contain the nixos installation
|
||||||
disko.devices.disk.main.imageSize = "10G";
|
disko.devices.disk.main.imageSize = "10G";
|
||||||
@@ -141,3 +152,58 @@ In the this example we create a flake containing a nixos configuration for
|
|||||||
|
|
||||||
By following these instructions and understanding the process, you can smoothly
|
By following these instructions and understanding the process, you can smoothly
|
||||||
generate disk images with Disko for your NixOS system configurations.
|
generate disk images with Disko for your NixOS system configurations.
|
||||||
|
|
||||||
|
## Test the image inside a VM
|
||||||
|
|
||||||
|
Make sure you uncommented the `"${modulesPath}/profiles/qemu-guest.nix"` import in the example above!
|
||||||
|
|
||||||
|
Write the following script to `qemu.nix`. Note that it expects an UEFI compatible image!
|
||||||
|
|
||||||
|
```
|
||||||
|
with import <nixpkgs> {};
|
||||||
|
|
||||||
|
writeShellApplication {
|
||||||
|
name = "test-image";
|
||||||
|
runtimeInputs = [ qemu ];
|
||||||
|
text = ''
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <path-to-boot-image>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
tmpFile=$(mktemp /tmp/test-image.XXXXXX)
|
||||||
|
trap 'rm -f $tmpFile' EXIT
|
||||||
|
cp "$1" "$tmpFile"
|
||||||
|
qemu-system-x86_64 \
|
||||||
|
-enable-kvm \
|
||||||
|
-m 2G \
|
||||||
|
-cpu max \
|
||||||
|
-smp 2 \
|
||||||
|
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
|
||||||
|
-device virtio-net-pci,netdev=net0 \
|
||||||
|
-drive if=pflash,format=raw,readonly=on,file=${OVMF.firmware} \
|
||||||
|
-drive if=pflash,format=raw,readonly=on,file=${OVMF.variables} \
|
||||||
|
-drive "if=virtio,format=raw,file=$tmpFile"
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This command will run a qemu vm with your image:
|
||||||
|
|
||||||
|
```
|
||||||
|
$(nix-build ./qemu.nix)/bin/test-image ./main.raw
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace `main.raw` with the image that you build!
|
||||||
|
|
||||||
|
Tip: You can customize memory (`-m` flag) or cpu (`-smp` flag) available to the VM to your liking.
|
||||||
|
|
||||||
|
## Build the image inside the nix sandbox
|
||||||
|
|
||||||
|
Instead of the diskoImagesScript, we can also build the image inside the nix store.
|
||||||
|
This approach is slower because it requires copying the image after the build and
|
||||||
|
we also don't have a secure way to embed secrets this way.
|
||||||
|
|
||||||
|
```
|
||||||
|
nix build .#nixosConfigurations.myhost.config.system.build.diskoImages
|
||||||
|
ls -a ./result/main.raw
|
||||||
|
```
|
||||||
+42
-141
@@ -23,7 +23,7 @@
|
|||||||
content = {
|
content = {
|
||||||
type = "bcachefs";
|
type = "bcachefs";
|
||||||
# This refers to a filesystem in the `bcachefs_filesystems` attrset below.
|
# This refers to a filesystem in the `bcachefs_filesystems` attrset below.
|
||||||
filesystem = "unmounted_subvolumes_in_multi";
|
filesystem = "mounted_subvolumes_in_multi";
|
||||||
label = "group_a.vdb2";
|
label = "group_a.vdb2";
|
||||||
extraFormatArgs = [
|
extraFormatArgs = [
|
||||||
"--discard"
|
"--discard"
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
size = "100%";
|
size = "100%";
|
||||||
content = {
|
content = {
|
||||||
type = "bcachefs";
|
type = "bcachefs";
|
||||||
filesystem = "unmounted_subvolumes_in_multi";
|
filesystem = "mounted_subvolumes_in_multi";
|
||||||
label = "group_a.vdc1";
|
label = "group_a.vdc1";
|
||||||
extraFormatArgs = [
|
extraFormatArgs = [
|
||||||
"--discard"
|
"--discard"
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
size = "100%";
|
size = "100%";
|
||||||
content = {
|
content = {
|
||||||
type = "bcachefs";
|
type = "bcachefs";
|
||||||
filesystem = "unmounted_subvolumes_in_multi";
|
filesystem = "mounted_subvolumes_in_multi";
|
||||||
label = "group_b.vdd1";
|
label = "group_b.vdd1";
|
||||||
extraFormatArgs = [
|
extraFormatArgs = [
|
||||||
"--force"
|
"--force"
|
||||||
@@ -79,87 +79,6 @@
|
|||||||
vde = {
|
vde = {
|
||||||
device = "/dev/vde";
|
device = "/dev/vde";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
|
||||||
type = "gpt";
|
|
||||||
partitions = {
|
|
||||||
vde1 = {
|
|
||||||
size = "100%";
|
|
||||||
content = {
|
|
||||||
type = "bcachefs";
|
|
||||||
filesystem = "mounted_subvolumes_in_multi";
|
|
||||||
label = "group_a.vde1";
|
|
||||||
extraFormatArgs = [
|
|
||||||
"--discard"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
vdf = {
|
|
||||||
device = "/dev/vdf";
|
|
||||||
type = "disk";
|
|
||||||
content = {
|
|
||||||
type = "gpt";
|
|
||||||
partitions = {
|
|
||||||
vdf1 = {
|
|
||||||
size = "100%";
|
|
||||||
content = {
|
|
||||||
type = "bcachefs";
|
|
||||||
filesystem = "mounted_subvolumes_in_multi";
|
|
||||||
label = "group_a.vdf1";
|
|
||||||
extraFormatArgs = [
|
|
||||||
"--discard"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
vdg = {
|
|
||||||
device = "/dev/vdg";
|
|
||||||
type = "disk";
|
|
||||||
content = {
|
|
||||||
type = "gpt";
|
|
||||||
partitions = {
|
|
||||||
vdd1 = {
|
|
||||||
size = "100%";
|
|
||||||
content = {
|
|
||||||
type = "bcachefs";
|
|
||||||
filesystem = "mounted_subvolumes_in_multi";
|
|
||||||
label = "group_b.vdg1";
|
|
||||||
extraFormatArgs = [
|
|
||||||
"--force"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
vdh = {
|
|
||||||
device = "/dev/vdh";
|
|
||||||
type = "disk";
|
|
||||||
content = {
|
|
||||||
type = "gpt";
|
|
||||||
partitions = {
|
|
||||||
vdd1 = {
|
|
||||||
size = "100%";
|
|
||||||
content = {
|
|
||||||
type = "bcachefs";
|
|
||||||
filesystem = "no_reliance_on_external_subvolume";
|
|
||||||
label = "group_a.vdh1";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
vdi = {
|
|
||||||
device = "/dev/vdi";
|
|
||||||
type = "disk";
|
|
||||||
content = {
|
content = {
|
||||||
type = "gpt";
|
type = "gpt";
|
||||||
partitions = {
|
partitions = {
|
||||||
@@ -168,7 +87,7 @@
|
|||||||
content = {
|
content = {
|
||||||
type = "bcachefs";
|
type = "bcachefs";
|
||||||
filesystem = "relies_on_external_subvolume";
|
filesystem = "relies_on_external_subvolume";
|
||||||
label = "group_a.vdi1";
|
label = "group_a.vde1";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -177,72 +96,54 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
bcachefs_filesystems = {
|
bcachefs_filesystems = {
|
||||||
# Example showing unmounted subvolumes in a multi-disk configuration.
|
# Example showing mounted subvolumes in a multi-disk configuration.
|
||||||
unmounted_subvolumes_in_multi = {
|
mounted_subvolumes_in_multi = {
|
||||||
type = "bcachefs_filesystem";
|
type = "bcachefs_filesystem";
|
||||||
passwordFile = "/tmp/secret.key";
|
passwordFile = "/tmp/secret.key";
|
||||||
extraFormatArgs = [
|
extraFormatArgs = [
|
||||||
"--compression=lz4"
|
"--compression=lz4"
|
||||||
"--background_compression=lz4"
|
"--background_compression=lz4"
|
||||||
];
|
];
|
||||||
|
subvolumes = {
|
||||||
|
# Subvolume name is different from mountpoint.
|
||||||
|
"subvolumes/root" = {
|
||||||
|
mountpoint = "/";
|
||||||
|
mountOptions = [
|
||||||
|
"verbose"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
# Subvolume name is the same as the mountpoint.
|
||||||
|
"subvolumes/home" = {
|
||||||
|
mountpoint = "/home";
|
||||||
|
};
|
||||||
|
# Nested subvolume doesn't need a mountpoint as its parent is mounted.
|
||||||
|
"subvolumes/home/user" = {
|
||||||
|
};
|
||||||
|
# Parent is not mounted so the mountpoint must be set.
|
||||||
|
"subvolumes/nix" = {
|
||||||
|
mountpoint = "/nix";
|
||||||
|
};
|
||||||
|
# This subvolume will be created but not mounted.
|
||||||
|
"subvolumes/test" = {
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Example showing a bcachefs filesystem without subvolumes,
|
||||||
|
# which relies on a subvolume in another filesystem being mounted
|
||||||
|
# and uses a hard-coded UUID.
|
||||||
|
relies_on_external_subvolume = {
|
||||||
|
type = "bcachefs_filesystem";
|
||||||
|
mountpoint = "/home/Documents";
|
||||||
|
extraFormatArgs = [
|
||||||
|
"--compression=lz4"
|
||||||
|
"--background_compression=lz4"
|
||||||
|
];
|
||||||
mountOptions = [
|
mountOptions = [
|
||||||
"verbose"
|
"verbose"
|
||||||
];
|
];
|
||||||
mountpoint = "/";
|
uuid = "64e50034-ebe2-eaf8-1f93-cf56266a8d86";
|
||||||
subvolumes = {
|
|
||||||
"subvolumes/rootfs" = { };
|
|
||||||
"subvolumes/home" = { };
|
|
||||||
"subvolumes/home/user" = { };
|
|
||||||
"subvolumes/nix" = { };
|
|
||||||
"subvolumes/test" = { };
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# # Example showing mounted subvolumes in a multi-disk configuration (not yet working).
|
|
||||||
# mounted_subvolumes_in_multi = {
|
|
||||||
# type = "bcachefs_filesystem";
|
|
||||||
# passwordFile = "/tmp/secret.key";
|
|
||||||
# extraFormatArgs = [
|
|
||||||
# "--compression=lz4"
|
|
||||||
# "--background_compression=lz4"
|
|
||||||
# ];
|
|
||||||
# mountOptions = [
|
|
||||||
# "verbose"
|
|
||||||
# ];
|
|
||||||
# subvolumes = {
|
|
||||||
# # Subvolume name is different from mountpoint
|
|
||||||
# "foo" = {
|
|
||||||
# mountpoint = "/bar";
|
|
||||||
# };
|
|
||||||
# # Subvolume name is the same as the mountpoint
|
|
||||||
# "home" = {
|
|
||||||
# mountpoint = "/home";
|
|
||||||
# };
|
|
||||||
# # Sub(sub)volume doesn't need a mountpoint as its parent is mounted
|
|
||||||
# "home/user" = {
|
|
||||||
# };
|
|
||||||
# # Parent is not mounted so the mountpoint must be set
|
|
||||||
# "nix" = {
|
|
||||||
# mountpoint = "/nix";
|
|
||||||
# };
|
|
||||||
# # This subvolume will be created but not mounted
|
|
||||||
# "test" = {
|
|
||||||
# };
|
|
||||||
# };
|
|
||||||
# };
|
|
||||||
|
|
||||||
# Example showing another bcachefs filesystem.
|
|
||||||
no_reliance_on_external_subvolume = {
|
|
||||||
type = "bcachefs_filesystem";
|
|
||||||
mountpoint = "/sometestdir";
|
|
||||||
};
|
|
||||||
|
|
||||||
# # Example showing another bcachefs filesystem that relies on a subvolume
|
|
||||||
# # in another filesystem being mounted (not yet working).
|
|
||||||
# relies_on_external_subvolume = {
|
|
||||||
# type = "bcachefs_filesystem";
|
|
||||||
# mountpoint = "/home/somedir/vdf1";
|
|
||||||
# };
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1744868846,
|
"lastModified": 1746576598,
|
||||||
"narHash": "sha256-5RJTdUHDmj12Qsv7XOhuospjAjATNiTMElplWnJE9Hs=",
|
"narHash": "sha256-FshoQvr6Aor5SnORVvh/ZdJ1Sa2U4ZrIMwKBX5k2wu0=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "ebe4301cbd8f81c4f8d3244b3632338bbeb6d49c",
|
"rev": "b3582c75c7f21ce0b429898980eddbbf05c68e55",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
+10
-3
@@ -875,9 +875,15 @@ let
|
|||||||
umount -Rv "${rootMountPoint}" || :
|
umount -Rv "${rootMountPoint}" || :
|
||||||
|
|
||||||
# shellcheck disable=SC2043,2041
|
# shellcheck disable=SC2043,2041
|
||||||
for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do
|
for dev in ${
|
||||||
|
toString (
|
||||||
|
lib.catAttrs "device" (lib.attrValues (lib.filterAttrs (name: disk: disk.destroy) devices.disk))
|
||||||
|
)
|
||||||
|
};
|
||||||
|
do
|
||||||
$BASH ${../disk-deactivate}/disk-deactivate "$dev"
|
$BASH ${../disk-deactivate}/disk-deactivate "$dev"
|
||||||
done
|
done
|
||||||
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_destroy = lib.mkOption {
|
_destroy = lib.mkOption {
|
||||||
@@ -888,7 +894,8 @@ let
|
|||||||
'';
|
'';
|
||||||
default =
|
default =
|
||||||
let
|
let
|
||||||
selectedDisks = lib.escapeShellArgs (lib.catAttrs "device" (lib.attrValues devices.disk));
|
disksToWipe = lib.attrValues (lib.filterAttrs (name: disk: disk.destroy) devices.disk);
|
||||||
|
selectedDisks = lib.escapeShellArgs (lib.catAttrs "device" disksToWipe);
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
if [ "$1" != "--yes-wipe-all-disks" ]; then
|
if [ "$1" != "--yes-wipe-all-disks" ]; then
|
||||||
@@ -913,7 +920,7 @@ let
|
|||||||
umount -Rv "${rootMountPoint}" || :
|
umount -Rv "${rootMountPoint}" || :
|
||||||
|
|
||||||
# shellcheck disable=SC2043,2041
|
# shellcheck disable=SC2043,2041
|
||||||
for dev in ${selectedDisks}; do
|
for dev in ${toString (lib.catAttrs "device" disksToWipe)}; do
|
||||||
$BASH ${../disk-deactivate}/disk-deactivate "$dev"
|
$BASH ${../disk-deactivate}/disk-deactivate "$dev"
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ let
|
|||||||
|
|
||||||
installer = lib.optionalString cfg.copyNixStore ''
|
installer = lib.optionalString cfg.copyNixStore ''
|
||||||
${binfmtSetup}
|
${binfmtSetup}
|
||||||
|
unset NIX_REMOTE
|
||||||
# populate nix db, so nixos-install doesn't complain
|
# populate nix db, so nixos-install doesn't complain
|
||||||
export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix
|
export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix
|
||||||
nix-store --load-db < "${closureInfo}/registration"
|
nix-store --load-db < "${closureInfo}/registration"
|
||||||
|
|||||||
@@ -113,10 +113,7 @@
|
|||||||
mountpoint = lib.mkOption {
|
mountpoint = lib.mkOption {
|
||||||
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
||||||
default = null;
|
default = null;
|
||||||
description = ''
|
description = "Path to mount the subvolume to.";
|
||||||
Path to mount the subvolume to.
|
|
||||||
DO NOT USE. Currently not working.
|
|
||||||
'';
|
|
||||||
example = "/";
|
example = "/";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -126,7 +123,19 @@
|
|||||||
default = { };
|
default = { };
|
||||||
description = "List of subvolumes to define.";
|
description = "List of subvolumes to define.";
|
||||||
example = {
|
example = {
|
||||||
"subvolumes/home" = { };
|
"subvolumes/root" = {
|
||||||
|
mountpoint = "/";
|
||||||
|
extraFormatArgs = [
|
||||||
|
"--compression=lz4"
|
||||||
|
"--background_compression=lz4"
|
||||||
|
];
|
||||||
|
mountOptions = [
|
||||||
|
"verbose"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
"subvolumes/home" = {
|
||||||
|
mountpoint = "/home";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
_parent = lib.mkOption {
|
_parent = lib.mkOption {
|
||||||
@@ -291,11 +300,10 @@
|
|||||||
_config = lib.mkOption {
|
_config = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
# @todo Check that this implementation is correct:
|
|
||||||
default =
|
default =
|
||||||
(lib.optional (config.mountpoint != null) {
|
(lib.optional (config.mountpoint != null) {
|
||||||
fileSystems.${config.mountpoint} = {
|
fileSystems.${config.mountpoint} = {
|
||||||
device = "UUID=${config.uuid}";
|
device = "/dev/disk/by-uuid/${config.uuid}";
|
||||||
fsType = "bcachefs";
|
fsType = "bcachefs";
|
||||||
options = lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions);
|
options = lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions);
|
||||||
neededForBoot = true;
|
neededForBoot = true;
|
||||||
@@ -303,7 +311,7 @@
|
|||||||
})
|
})
|
||||||
++ (map (subvolume: {
|
++ (map (subvolume: {
|
||||||
fileSystems.${subvolume.mountpoint} = {
|
fileSystems.${subvolume.mountpoint} = {
|
||||||
device = "UUID=${config.uuid}";
|
device = "/dev/disk/by-uuid/${config.uuid}";
|
||||||
fsType = "bcachefs";
|
fsType = "bcachefs";
|
||||||
options = lib.unique (
|
options = lib.unique (
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -22,6 +22,11 @@
|
|||||||
type = diskoLib.optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
|
type = diskoLib.optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
|
||||||
description = "Device path";
|
description = "Device path";
|
||||||
};
|
};
|
||||||
|
destroy = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "If false, disko will not wipe or destroy this disk's contents during the destroy stage";
|
||||||
|
};
|
||||||
imageName = lib.mkOption {
|
imageName = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = config.name;
|
default = config.name;
|
||||||
|
|||||||
+11
-7
@@ -130,7 +130,7 @@ in
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
if ! blkid "${config.device}" >/dev/null || ! (blkid "${config.device}" -o export | grep -q '^TYPE='); then
|
if ! blkid "${config.device}" >/dev/null || ! cryptsetup isLuks "${config.device}"; then
|
||||||
${lib.optionalString config.askPassword ''
|
${lib.optionalString config.askPassword ''
|
||||||
promptSecret() {
|
promptSecret() {
|
||||||
prompt=$1
|
prompt=$1
|
||||||
@@ -158,13 +158,17 @@ in
|
|||||||
done
|
done
|
||||||
''}
|
''}
|
||||||
cryptsetup -q luksFormat "${config.device}" ${toString config.extraFormatArgs} ${keyFileArgs}
|
cryptsetup -q luksFormat "${config.device}" ${toString config.extraFormatArgs} ${keyFileArgs}
|
||||||
${cryptsetupOpen} --persistent
|
|
||||||
${toString (
|
|
||||||
lib.forEach config.additionalKeyFiles (keyFile: ''
|
|
||||||
cryptsetup luksAddKey "${config.device}" ${keyFile} ${keyFileArgs}
|
|
||||||
'')
|
|
||||||
)}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! cryptsetup status "${config.name}" >/dev/null; then
|
||||||
|
${cryptsetupOpen} --persistent
|
||||||
|
fi
|
||||||
|
${toString (
|
||||||
|
lib.forEach config.additionalKeyFiles (keyFile: ''
|
||||||
|
cryptsetup luksAddKey "${config.device}" ${keyFile} ${keyFileArgs}
|
||||||
|
'')
|
||||||
|
)}
|
||||||
|
|
||||||
${lib.optionalString (config.content != null) config.content._create}
|
${lib.optionalString (config.content != null) config.content._create}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
+110
-29
@@ -7,39 +7,120 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
name = "bcachefs";
|
name = "bcachefs";
|
||||||
disko-config = ../example/bcachefs.nix;
|
disko-config = ../example/bcachefs.nix;
|
||||||
enableOCR = true;
|
enableOCR = true;
|
||||||
|
bootCommands = ''
|
||||||
|
machine.wait_for_text("enter passphrase for /");
|
||||||
|
machine.send_chars("secretsecret\n");
|
||||||
|
machine.wait_for_text("enter passphrase for /home");
|
||||||
|
machine.send_chars("secretsecret\n");
|
||||||
|
machine.wait_for_text("enter passphrase for /nix");
|
||||||
|
machine.send_chars("secretsecret\n");
|
||||||
|
'';
|
||||||
|
extraSystemConfig = {
|
||||||
|
environment.systemPackages = [
|
||||||
|
pkgs.jq
|
||||||
|
];
|
||||||
|
};
|
||||||
extraTestScript = ''
|
extraTestScript = ''
|
||||||
machine.succeed("mountpoint /");
|
|
||||||
# @todo Verify all devices are part of the filesystem.
|
|
||||||
# @todo Check device labels and group assignments.
|
|
||||||
# Verify mount options were applied.
|
|
||||||
machine.succeed("mount | grep ' / ' | grep -q 'compression=lz4'");
|
|
||||||
machine.succeed("mount | grep ' / ' | grep -q 'background_compression=lz4'");
|
|
||||||
# @todo Verify mountpoint dependency order was respected.
|
|
||||||
# @todo Add tests for subvolumes.
|
|
||||||
# Print debug information.
|
# Print debug information.
|
||||||
|
machine.succeed("ls -la /subvolumes >&2");
|
||||||
machine.succeed("lsblk >&2");
|
machine.succeed("lsblk >&2");
|
||||||
machine.succeed("lsblk -f >&2");
|
machine.succeed("lsblk -f >&2");
|
||||||
machine.succeed("mount >&2");
|
machine.succeed("mount >&2");
|
||||||
'';
|
machine.succeed("bcachefs show-super /dev/vda2 >&2");
|
||||||
# extraSystemConfig = { pkgs, ... }: {
|
machine.succeed("bcachefs show-super /dev/vdd1 >&2");
|
||||||
# # @todo Do we need to add any attributes here?
|
machine.succeed("findmnt --json >&2");
|
||||||
# boot = {
|
|
||||||
# supportedFilesystems = [ "bcachefs" ];
|
# Verify subvolume structure.
|
||||||
# initrd = {
|
machine.succeed("test -d /subvolumes/root");
|
||||||
# supportedFilesystems = [ "bcachefs" ];
|
machine.succeed("test -d /subvolumes/home");
|
||||||
# # systemd.enable = false;
|
machine.succeed("test -d /subvolumes/home/user");
|
||||||
# };
|
machine.succeed("test -d /subvolumes/nix");
|
||||||
# };
|
machine.succeed("test -d /subvolumes/test");
|
||||||
# environment.systemPackages = [
|
machine.fail("test -d /subvolumes/non-existent");
|
||||||
# pkgs.bcachefs-tools
|
|
||||||
# pkgs.util-linux
|
# Verify existence of mountpoints.
|
||||||
# ];
|
machine.succeed("mountpoint /");
|
||||||
# };
|
machine.succeed("mountpoint /home");
|
||||||
# extraInstallerConfig = {
|
machine.succeed("mountpoint /nix");
|
||||||
# # @todo Do we need to add any attributes here?
|
machine.succeed("mountpoint /home/Documents");
|
||||||
# };
|
machine.fail("mountpoint /non-existent");
|
||||||
bootCommands = ''
|
|
||||||
machine.wait_for_text("enter passphrase for");
|
# Verify device membership and labels.
|
||||||
machine.send_chars("secretsecret\n");
|
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Devices:' | grep -q '3'");
|
||||||
|
machine.succeed("bcachefs show-super /dev/vdd1 | grep 'Devices:' | grep -q '1'");
|
||||||
|
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'vdb2'");
|
||||||
|
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'vdc1'");
|
||||||
|
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'vdd1'");
|
||||||
|
machine.succeed("bcachefs show-super /dev/vdd1 | grep 'Label:' | grep -q 'vde1'");
|
||||||
|
machine.fail("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'non-existent'");
|
||||||
|
|
||||||
|
# @todo Verify format arguments.
|
||||||
|
|
||||||
|
# Verify mount options from configuration.
|
||||||
|
machine.succeed("""
|
||||||
|
findmnt --json \
|
||||||
|
| jq -e ' \
|
||||||
|
.filesystems[] \
|
||||||
|
| select(.target == "/") \
|
||||||
|
| .options \
|
||||||
|
| split(",") \
|
||||||
|
| contains(["verbose", "compression=lz4", "background_compression=lz4"]) \
|
||||||
|
'
|
||||||
|
""");
|
||||||
|
|
||||||
|
machine.succeed("""
|
||||||
|
findmnt --json \
|
||||||
|
| jq -e ' \
|
||||||
|
.filesystems[] \
|
||||||
|
| .. \
|
||||||
|
| select(.target? == "/home/Documents") \
|
||||||
|
| .options \
|
||||||
|
| split(",") \
|
||||||
|
| contains(["verbose"]) \
|
||||||
|
'
|
||||||
|
""");
|
||||||
|
|
||||||
|
machine.fail("""
|
||||||
|
findmnt --json \
|
||||||
|
| jq -e ' \
|
||||||
|
.filesystems[] \
|
||||||
|
| select(.target == "/") \
|
||||||
|
| .options \
|
||||||
|
| split(",") \
|
||||||
|
| contains(["non-existent"]) \
|
||||||
|
'
|
||||||
|
""");
|
||||||
|
|
||||||
|
# Verify device composition of filesystems.
|
||||||
|
machine.succeed("""
|
||||||
|
findmnt --json \
|
||||||
|
| jq -e ' \
|
||||||
|
.filesystems[] \
|
||||||
|
| select(.target == "/") \
|
||||||
|
| .source | split(":") \
|
||||||
|
| contains(["/dev/vda2", "/dev/vdb1", "/dev/vdc1"]) \
|
||||||
|
'
|
||||||
|
""");
|
||||||
|
|
||||||
|
machine.succeed("""
|
||||||
|
findmnt --json \
|
||||||
|
| jq -e ' \
|
||||||
|
.filesystems[] \
|
||||||
|
| .. \
|
||||||
|
| select(.target? == "/home/Documents") \
|
||||||
|
| .source \
|
||||||
|
| contains("/dev/disk/by-uuid/64e50034-ebe2-eaf8-1f93-cf56266a8d86") \
|
||||||
|
'
|
||||||
|
""");
|
||||||
|
|
||||||
|
machine.fail("""
|
||||||
|
findmnt --json \
|
||||||
|
| jq -e ' \
|
||||||
|
.filesystems[] \
|
||||||
|
| select(.target == "/") \
|
||||||
|
| .source | split(":") \
|
||||||
|
| contains(["/dev/non-existent"]) \
|
||||||
|
'
|
||||||
|
""");
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
+1
-4
@@ -1,4 +1 @@
|
|||||||
{
|
{ version = "1.12.0"; released = true; }
|
||||||
version = "1.10.0";
|
|
||||||
released = false;
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user