Merge pull request #162 from nix-community/examples-config

This commit is contained in:
Lassulus 2023-04-06 09:48:07 +02:00 committed by GitHub
commit 8891df7029
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 1170 additions and 1200 deletions

View file

@ -1,3 +1,11 @@
2023-03-22 2624af6
disk config now needs to be inside a disko.devices attrset always
2023-03-22 0577409
the extraArgs option in the luks type was renamed to extraFormatArgs
2023-02-14 6d630b8 2023-02-14 6d630b8
btrfs, btrfs_subvol filesystem and lvm_lv extraArgs are now lists btrfs, btrfs_subvol filesystem and lvm_lv extraArgs are now lists

View file

@ -7,9 +7,9 @@ let
eval = cfg: lib.evalModules { eval = cfg: lib.evalModules {
modules = lib.singleton { modules = lib.singleton {
# _file = toString input; # _file = toString input;
imports = lib.singleton { devices = cfg; }; imports = lib.singleton { disko.devices = cfg.disko.devices; };
options = { options = {
devices = lib.mkOption { disko.devices = lib.mkOption {
type = types.devices; type = types.devices;
}; };
}; };
@ -18,30 +18,30 @@ let
in in
{ {
types = types; types = types;
create = cfg: types.diskoLib.create (eval cfg).config.devices; create = cfg: types.diskoLib.create (eval cfg).config.disko.devices;
createScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-create" '' createScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-create" ''
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}:$PATH export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
${types.diskoLib.create (eval cfg).config.devices} ${types.diskoLib.create (eval cfg).config.disko.devices}
''; '';
createScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-create" '' createScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-create" ''
${types.diskoLib.create (eval cfg).config.devices} ${types.diskoLib.create (eval cfg).config.disko.devices}
''; '';
mount = cfg: types.diskoLib.mount (eval cfg).config.devices; mount = cfg: types.diskoLib.mount (eval cfg).config.disko.devices;
mountScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" '' mountScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}:$PATH export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
${types.diskoLib.mount (eval cfg).config.devices} ${types.diskoLib.mount (eval cfg).config.disko.devices}
''; '';
mountScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-mount" '' mountScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-mount" ''
${types.diskoLib.mount (eval cfg).config.devices} ${types.diskoLib.mount (eval cfg).config.disko.devices}
''; '';
zapCreateMount = cfg: types.diskoLib.zapCreateMount (eval cfg).config.devices; zapCreateMount = cfg: types.diskoLib.zapCreateMount (eval cfg).config.disko.devices;
zapCreateMountScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-zap-create-mount" '' zapCreateMountScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-zap-create-mount" ''
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}:$PATH export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
${types.diskoLib.zapCreateMount (eval cfg).config.devices} ${types.diskoLib.zapCreateMount (eval cfg).config.disko.devices}
''; '';
zapCreateMountScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-zap-create-mount" '' zapCreateMountScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-zap-create-mount" ''
${types.diskoLib.zapCreateMount (eval cfg).config.devices} ${types.diskoLib.zapCreateMount (eval cfg).config.disko.devices}
''; '';
config = cfg: { imports = types.diskoLib.config (eval cfg).config.devices; }; config = cfg: { imports = types.diskoLib.config (eval cfg).config.disko.devices; };
packages = cfg: types.diskoLib.packages (eval cfg).config.devices; packages = cfg: types.diskoLib.packages (eval cfg).config.disko.devices;
} }

View file

@ -106,10 +106,10 @@ imports =
[ # Include the results of the hardware scan. [ # Include the results of the hardware scan.
./hardware-configuration.nix ./hardware-configuration.nix
"${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix" "${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix"
(import ./disko-config.nix {
disks = [ "/dev/<disk-name>" ]; # replace this with your disk name i.e. /dev/nvme0n1
})
]; ];
disko.devices = pkgs.callPackage ./disko-config.nix {
disks = [ "/dev/<disk-name>" ]; # replace this with your disk name i.e. /dev/nvme0n1
};
``` ```
If you went for the hybrid-partition scheme, than choose grub as a bootloader. If you went for the hybrid-partition scheme, than choose grub as a bootloader.

View file

@ -1,37 +1,39 @@
{ disks ? [ "/dev/vdb" ], ... }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disko.devices = {
vdb = { disk = {
device = builtins.elemAt disks 0; vdb = {
type = "disk"; device = builtins.elemAt disks 0;
content = { type = "disk";
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
type = "partition"; {
name = "ESP"; type = "partition";
start = "1MiB"; name = "ESP";
end = "100MiB"; start = "1MiB";
bootable = true; end = "100MiB";
content = { bootable = true;
type = "filesystem"; content = {
format = "vfat"; type = "filesystem";
mountpoint = "/boot"; format = "vfat";
}; mountpoint = "/boot";
} };
{ }
name = "root"; {
type = "partition"; name = "root";
start = "100MiB"; type = "partition";
end = "100%"; start = "100MiB";
part-type = "primary"; end = "100%";
content = { part-type = "primary";
type = "filesystem"; content = {
format = "bcachefs"; type = "filesystem";
mountpoint = "/"; format = "bcachefs";
}; mountpoint = "/";
} };
]; }
];
};
}; };
}; };
}; };

View file

@ -1,116 +1,118 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disko.devices = {
one = { disk = {
type = "disk"; one = {
device = builtins.elemAt disks 0; type = "disk";
content = { device = builtins.elemAt disks 0;
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
name = "boot"; {
type = "partition";
start = "0";
end = "1M";
part-type = "primary";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "128MiB";
fs-type = "fat32";
bootable = true;
content = {
type = "mdraid";
name = "boot"; name = "boot";
}; type = "partition";
} start = "0";
{ end = "1M";
type = "partition"; part-type = "primary";
name = "mdadm"; flags = [ "bios_grub" ];
start = "128MiB"; }
end = "100%"; {
content = { type = "partition";
type = "mdraid"; name = "ESP";
name = "raid1"; start = "1MiB";
}; end = "128MiB";
} fs-type = "fat32";
]; bootable = true;
content = {
type = "mdraid";
name = "boot";
};
}
{
type = "partition";
name = "mdadm";
start = "128MiB";
end = "100%";
content = {
type = "mdraid";
name = "raid1";
};
}
];
};
}; };
}; two = {
two = { type = "disk";
type = "disk"; device = builtins.elemAt disks 1;
device = builtins.elemAt disks 1; content = {
content = { type = "table";
type = "table"; format = "gpt";
format = "gpt"; partitions = [
partitions = [ {
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
part-type = "primary";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "128MiB";
fs-type = "fat32";
bootable = true;
content = {
type = "mdraid";
name = "boot"; name = "boot";
}; type = "partition";
} start = "0";
{ end = "1M";
type = "partition"; part-type = "primary";
name = "mdadm"; flags = [ "bios_grub" ];
start = "128MiB"; }
end = "100%"; {
content = { type = "partition";
type = "mdraid"; name = "ESP";
name = "raid1"; start = "1MiB";
}; end = "128MiB";
} fs-type = "fat32";
]; bootable = true;
content = {
type = "mdraid";
name = "boot";
};
}
{
type = "partition";
name = "mdadm";
start = "128MiB";
end = "100%";
content = {
type = "mdraid";
name = "raid1";
};
}
];
};
}; };
}; };
}; mdadm = {
mdadm = { boot = {
boot = { type = "mdadm";
type = "mdadm"; level = 1;
level = 1; metadata = "1.0";
metadata = "1.0"; content = {
content = { type = "filesystem";
type = "filesystem"; format = "vfat";
format = "vfat"; mountpoint = "/boot";
mountpoint = "/boot"; };
}; };
}; raid1 = {
raid1 = { type = "mdadm";
type = "mdadm"; level = 1;
level = 1; content = {
content = { type = "table";
type = "table"; format = "gpt";
format = "gpt"; partitions = [
partitions = [ {
{ type = "partition";
type = "partition"; name = "primary";
name = "primary"; start = "1MiB";
start = "1MiB"; end = "100%";
end = "100%"; content = {
content = { type = "filesystem";
type = "filesystem"; format = "ext4";
format = "ext4"; mountpoint = "/";
mountpoint = "/"; };
}; }
} ];
]; };
}; };
}; };
}; };

View file

@ -1,50 +1,52 @@
{ disks ? [ "/dev/vdb" ], ... }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disko.devices = {
vdb = { disk = {
type = "disk"; vdb = {
device = builtins.elemAt disks 0; type = "disk";
content = { device = builtins.elemAt disks 0;
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
type = "partition"; {
name = "ESP"; type = "partition";
start = "1MiB"; name = "ESP";
end = "128MiB"; start = "1MiB";
fs-type = "fat32"; end = "128MiB";
bootable = true; fs-type = "fat32";
content = { bootable = true;
type = "filesystem"; content = {
format = "vfat"; type = "filesystem";
mountpoint = "/boot"; format = "vfat";
}; mountpoint = "/boot";
}
{
name = "root";
type = "partition";
start = "128MiB";
end = "100%";
content = {
type = "btrfs";
extraArgs = [ "-f" ]; # Override existing partition
subvolumes = {
# Subvolume name is different from mountpoint
"/rootfs" = {
mountpoint = "/";
};
# Mountpoints inferred from subvolume name
"/home" = {
mountOptions = [ "compress=zstd" ];
};
"/nix" = {
mountOptions = [ "compress=zstd" "noatime" ];
};
"/test" = { };
}; };
}; }
} {
]; name = "root";
type = "partition";
start = "128MiB";
end = "100%";
content = {
type = "btrfs";
extraArgs = [ "-f" ]; # Override existing partition
subvolumes = {
# Subvolume name is different from mountpoint
"/rootfs" = {
mountpoint = "/";
};
# Mountpoints inferred from subvolume name
"/home" = {
mountOptions = [ "compress=zstd" ];
};
"/nix" = {
mountOptions = [ "compress=zstd" "noatime" ];
};
"/test" = { };
};
};
}
];
};
}; };
}; };
}; };

View file

@ -1,196 +1,198 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" "/dev/vdd" ], ... }: { { disks ? [ "/dev/vdb" "/dev/vdc" "/dev/vdd" ], ... }: {
disk = { disko.devices = {
disk0 = { disk = {
type = "disk"; disk0 = {
device = builtins.elemAt disks 0; type = "disk";
content = { device = builtins.elemAt disks 0;
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
type = "partition"; {
name = "ESP"; type = "partition";
start = "1MiB"; name = "ESP";
end = "128MiB"; start = "1MiB";
fs-type = "fat32"; end = "128MiB";
bootable = true; fs-type = "fat32";
content = { bootable = true;
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
];
};
};
disk1 = {
type = "disk";
device = builtins.elemAt disks 1;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
start = "1M";
end = "100%";
name = "luks";
content = {
type = "luks";
name = "crypted1";
keyFile = "/tmp/secret.key";
extraFormatArgs = [
"--iter-time 1"
];
content = { content = {
type = "lvm_pv"; type = "filesystem";
vg = "pool"; format = "vfat";
mountpoint = "/boot";
}; };
}; }
} ];
]; };
}; };
}; disk1 = {
disk2 = { type = "disk";
type = "disk"; device = builtins.elemAt disks 1;
device = builtins.elemAt disks 2; content = {
content = { type = "table";
type = "table"; format = "gpt";
format = "gpt"; partitions = [
partitions = [ {
{ type = "partition";
type = "partition"; start = "1M";
start = "1M"; end = "100%";
end = "100%"; name = "luks";
name = "luks";
content = {
type = "luks";
name = "crypted2";
keyFile = "/tmp/secret.key";
extraFormatArgs = [
"--iter-time 1"
];
content = { content = {
type = "lvm_pv"; type = "luks";
vg = "pool"; name = "crypted1";
keyFile = "/tmp/secret.key";
extraFormatArgs = [
"--iter-time 1"
];
content = {
type = "lvm_pv";
vg = "pool";
};
}; };
}; }
} ];
]; };
};
disk2 = {
type = "disk";
device = builtins.elemAt disks 2;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
start = "1M";
end = "100%";
name = "luks";
content = {
type = "luks";
name = "crypted2";
keyFile = "/tmp/secret.key";
extraFormatArgs = [
"--iter-time 1"
];
content = {
type = "lvm_pv";
vg = "pool";
};
};
}
];
};
}; };
}; };
}; mdadm = {
mdadm = { raid1 = {
raid1 = { type = "mdadm";
type = "mdadm"; level = 1;
level = 1; content = {
content = { type = "table";
type = "table"; format = "gpt";
format = "gpt"; partitions = [
partitions = [ {
{ type = "partition";
type = "partition"; name = "bla";
name = "bla"; start = "1MiB";
start = "1MiB"; end = "100%";
end = "100%"; content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4_mdadm_lvm";
};
}
];
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "10M";
lvm_type = "mirror";
content = { content = {
type = "filesystem"; type = "filesystem";
format = "ext4"; format = "ext4";
mountpoint = "/ext4_mdadm_lvm"; mountpoint = "/ext4_on_lvm";
mountOptions = [
"defaults"
];
}; };
}
];
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "10M";
lvm_type = "mirror";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4_on_lvm";
mountOptions = [
"defaults"
];
}; };
}; raid1 = {
raid1 = { type = "lvm_lv";
type = "lvm_lv"; size = "30M";
size = "30M"; lvm_type = "raid0";
lvm_type = "raid0"; content = {
content = { type = "mdraid";
type = "mdraid"; name = "raid1";
name = "raid1"; };
}; };
}; raid2 = {
raid2 = { type = "lvm_lv";
type = "lvm_lv"; size = "30M";
size = "30M"; lvm_type = "raid0";
lvm_type = "raid0"; content = {
content = { type = "mdraid";
type = "mdraid"; name = "raid1";
name = "raid1"; };
}; };
}; zfs1 = {
zfs1 = { type = "lvm_lv";
type = "lvm_lv"; size = "128M";
size = "128M"; lvm_type = "raid0";
lvm_type = "raid0"; content = {
content = { type = "zfs";
type = "zfs"; pool = "zroot";
pool = "zroot"; };
}; };
}; zfs2 = {
zfs2 = { type = "lvm_lv";
type = "lvm_lv"; size = "128M";
size = "128M"; lvm_type = "raid0";
lvm_type = "raid0"; content = {
content = { type = "zfs";
type = "zfs"; pool = "zroot";
pool = "zroot"; };
}; };
}; };
}; };
}; };
}; zpool = {
zpool = { zroot = {
zroot = { type = "zpool";
type = "zpool"; mode = "mirror";
mode = "mirror"; rootFsOptions = {
rootFsOptions = { compression = "lz4";
compression = "lz4"; "com.sun:auto-snapshot" = "false";
"com.sun:auto-snapshot" = "false"; };
}; mountpoint = "/";
mountpoint = "/";
datasets = { datasets = {
zfs_fs = { zfs_fs = {
zfs_type = "filesystem"; zfs_type = "filesystem";
mountpoint = "/zfs_fs"; mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true"; options."com.sun:auto-snapshot" = "true";
}; };
zfs_unmounted_fs = { zfs_unmounted_fs = {
zfs_type = "filesystem"; zfs_type = "filesystem";
options.mountpoint = "none"; options.mountpoint = "none";
}; };
zfs_legacy_fs = { zfs_legacy_fs = {
zfs_type = "filesystem"; zfs_type = "filesystem";
options.mountpoint = "legacy"; options.mountpoint = "legacy";
mountpoint = "/zfs_legacy_fs"; mountpoint = "/zfs_legacy_fs";
}; };
zfs_testvolume = { zfs_testvolume = {
zfs_type = "volume"; zfs_type = "volume";
size = "10M"; size = "10M";
content = { content = {
type = "filesystem"; type = "filesystem";
format = "ext4"; format = "ext4";
mountpoint = "/ext4onzfs"; mountpoint = "/ext4onzfs";
};
}; };
}; };
}; };

View file

@ -1,69 +0,0 @@
# usage: nix-instantiate --eval --json --strict example/config.nix | jq .
{
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "10G";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
};
home = {
type = "lvm_lv";
size = "10G";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
};
};
};
};
};
disk = {
sda = {
device = "/dev/sda";
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "ESP";
type = "partition";
start = "1MiB";
end = "1024MiB";
fs-type = "fat32";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "crypt_root";
type = "partition";
part-type = "primary";
start = "1024MiB";
end = "100%";
flags = [ "bios_grub" ];
content = {
type = "luks";
name = "crypted";
keyFile = "/tmp/secret.key";
content = {
type = "lvm_pv";
vg = "pool";
};
};
}
];
};
};
};
}

View file

@ -1,36 +1,38 @@
# Example to create a bios compatible gpt partition # Example to create a bios compatible gpt partition
{ disks ? [ "/dev/vdb" ], ... }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disko.devices = {
vdb = { disk = {
device = builtins.elemAt disks 0; vdb = {
type = "disk"; device = builtins.elemAt disks 0;
content = { type = "disk";
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
name = "boot"; {
type = "partition"; name = "boot";
start = "0"; type = "partition";
end = "1M"; start = "0";
part-type = "primary"; end = "1M";
flags = [ "bios_grub" ]; part-type = "primary";
} flags = [ "bios_grub" ];
{ }
name = "root"; {
type = "partition"; name = "root";
# leave space for the grub aka BIOS boot type = "partition";
start = "1M"; # leave space for the grub aka BIOS boot
end = "100%"; start = "1M";
part-type = "primary"; end = "100%";
bootable = true; part-type = "primary";
content = { bootable = true;
type = "filesystem"; content = {
format = "ext4"; type = "filesystem";
mountpoint = "/"; format = "ext4";
}; mountpoint = "/";
} };
]; }
];
};
}; };
}; };
}; };

View file

@ -1,52 +1,53 @@
{ disks ? [ "/dev/sda" ], ... }: { disks ? [ "/dev/sda" ], ... }: {
{ disko.devices = {
disk.main = { disk.main = {
device = builtins.elemAt disks 0; device = builtins.elemAt disks 0;
type = "disk"; type = "disk";
content = { content = {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
{ {
name = "boot"; name = "boot";
type = "partition"; type = "partition";
start = "0"; start = "0";
end = "1M"; end = "1M";
flags = [ "bios_grub" ]; flags = [ "bios_grub" ];
} }
{ {
type = "partition"; type = "partition";
name = "ESP"; name = "ESP";
start = "1M"; start = "1M";
end = "512M"; end = "512M";
bootable = true; bootable = true;
content = { content = {
type = "filesystem"; type = "filesystem";
format = "vfat"; format = "vfat";
mountpoint = "/boot"; mountpoint = "/boot";
}; };
} }
{ {
name = "nix"; name = "nix";
type = "partition"; type = "partition";
start = "512M"; start = "512M";
end = "100%"; end = "100%";
part-type = "primary"; part-type = "primary";
content = { content = {
type = "filesystem"; type = "filesystem";
format = "ext4"; format = "ext4";
mountpoint = "/nix"; mountpoint = "/nix";
}; };
} }
];
};
};
nodev."/" = {
fsType = "tmpfs";
mountOptions = [
"size=2G"
"defaults"
"mode=755"
]; ];
}; };
}; };
nodev."/" = {
fsType = "tmpfs";
mountOptions = [
"size=2G"
"defaults"
"mode=755"
];
};
} }

View file

@ -1,44 +1,45 @@
{ disks ? [ "/dev/vda" ], ... }: { disks ? [ "/dev/vda" ], ... }: {
{ disko.devices = {
disk = { disk = {
main = { main = {
type = "disk"; type = "disk";
device = builtins.elemAt disks 0; device = builtins.elemAt disks 0;
content = { content = {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
{ {
name = "boot"; name = "boot";
type = "partition"; type = "partition";
start = "0"; start = "0";
end = "1M"; end = "1M";
flags = [ "bios_grub" ]; flags = [ "bios_grub" ];
} }
{ {
type = "partition"; type = "partition";
name = "ESP"; name = "ESP";
start = "1M"; start = "1M";
end = "512M"; end = "512M";
bootable = true; bootable = true;
content = { content = {
type = "filesystem"; type = "filesystem";
format = "vfat"; format = "vfat";
mountpoint = "/boot"; mountpoint = "/boot";
}; };
} }
{ {
type = "partition"; type = "partition";
name = "root"; name = "root";
start = "512M"; start = "512M";
end = "100%"; end = "100%";
content = { content = {
type = "filesystem"; type = "filesystem";
format = "ext4"; format = "ext4";
mountpoint = "/"; mountpoint = "/";
}; };
} }
]; ];
};
}; };
}; };
}; };

View file

@ -1,76 +1,78 @@
{ disks ? [ "/dev/vdb" ], ... }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disko.devices = {
vdb = { disk = {
type = "disk"; vdb = {
device = builtins.elemAt disks 0; type = "disk";
content = { device = builtins.elemAt disks 0;
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
type = "partition"; {
name = "ESP"; type = "partition";
start = "1MiB"; name = "ESP";
end = "100MiB"; start = "1MiB";
bootable = true; end = "100MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [
"defaults"
];
};
}
{
type = "partition";
name = "luks";
start = "100MiB";
end = "100%";
content = {
type = "luks";
name = "crypted";
extraOpenArgs = [ "--allow-discards" ];
keyFile = "/tmp/secret.key";
content = {
type = "lvm_pv";
vg = "pool";
};
};
}
];
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "100M";
content = { content = {
type = "filesystem"; type = "filesystem";
format = "vfat"; format = "ext4";
mountpoint = "/boot"; mountpoint = "/";
mountOptions = [ mountOptions = [
"defaults" "defaults"
]; ];
}; };
} };
{ home = {
type = "partition"; type = "lvm_lv";
name = "luks"; size = "10M";
start = "100MiB";
end = "100%";
content = { content = {
type = "luks"; type = "filesystem";
name = "crypted"; format = "ext4";
extraOpenArgs = [ "--allow-discards" ]; mountpoint = "/home";
keyFile = "/tmp/secret.key";
content = {
type = "lvm_pv";
vg = "pool";
};
}; };
}
];
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "100M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
mountOptions = [
"defaults"
];
}; };
}; raw = {
home = { type = "lvm_lv";
type = "lvm_lv"; size = "10M";
size = "10M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
}; };
}; };
raw = {
type = "lvm_lv";
size = "10M";
};
}; };
}; };
}; };

View file

@ -1,107 +1,109 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disko.devices = {
one = { disk = {
type = "disk"; one = {
device = builtins.elemAt disks 0; type = "disk";
content = { device = builtins.elemAt disks 0;
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
name = "boot"; {
type = "partition";
start = "0";
end = "100M";
fs-type = "fat32";
bootable = true;
content = {
type = "mdraid";
name = "boot"; name = "boot";
}; type = "partition";
} start = "0";
{ end = "100M";
type = "partition"; fs-type = "fat32";
name = "primary"; bootable = true;
start = "100M"; content = {
end = "100%"; type = "mdraid";
content = { name = "boot";
type = "lvm_pv"; };
vg = "pool"; }
}; {
} type = "partition";
]; name = "primary";
}; start = "100M";
}; end = "100%";
two = { content = {
type = "disk"; type = "lvm_pv";
device = builtins.elemAt disks 1; vg = "pool";
content = { };
type = "table"; }
format = "gpt"; ];
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "100M";
fs-type = "fat32";
bootable = true;
content = {
type = "mdraid";
name = "boot";
};
}
{
type = "partition";
name = "primary";
start = "100M";
end = "100%";
content = {
type = "lvm_pv";
vg = "pool";
};
}
];
};
};
};
mdadm = {
boot = {
type = "mdadm";
level = 1;
metadata = "1.0";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "100M";
lvm_type = "mirror";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
mountOptions = [
"defaults"
];
};
}; };
home = { };
type = "lvm_lv"; two = {
size = "10M"; type = "disk";
lvm_type = "raid0"; device = builtins.elemAt disks 1;
content = { content = {
type = "filesystem"; type = "table";
format = "ext4"; format = "gpt";
mountpoint = "/home"; partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "100M";
fs-type = "fat32";
bootable = true;
content = {
type = "mdraid";
name = "boot";
};
}
{
type = "partition";
name = "primary";
start = "100M";
end = "100%";
content = {
type = "lvm_pv";
vg = "pool";
};
}
];
};
};
};
mdadm = {
boot = {
type = "mdadm";
level = 1;
metadata = "1.0";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "100M";
lvm_type = "mirror";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
mountOptions = [
"defaults"
];
};
};
home = {
type = "lvm_lv";
size = "10M";
lvm_type = "raid0";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
};
}; };
}; };
}; };

View file

@ -1,82 +1,84 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disko.devices = {
vdb = { disk = {
type = "disk"; vdb = {
device = builtins.elemAt disks 0; type = "disk";
content = { device = builtins.elemAt disks 0;
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
name = "boot"; {
type = "partition"; name = "boot";
start = "0"; type = "partition";
end = "1M"; start = "0";
part-type = "primary"; end = "1M";
flags = [ "bios_grub" ]; part-type = "primary";
} flags = [ "bios_grub" ];
{ }
type = "partition"; {
name = "mdadm"; type = "partition";
start = "1MiB"; name = "mdadm";
end = "100%"; start = "1MiB";
content = { end = "100%";
type = "mdraid"; content = {
name = "raid1"; type = "mdraid";
}; name = "raid1";
} };
]; }
];
};
};
vdc = {
type = "disk";
device = builtins.elemAt disks 1;
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
part-type = "primary";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "mdadm";
start = "1MiB";
end = "100%";
content = {
type = "mdraid";
name = "raid1";
};
}
];
};
}; };
}; };
vdc = { mdadm = {
type = "disk"; raid1 = {
device = builtins.elemAt disks 1; type = "mdadm";
content = { level = 1;
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
name = "boot"; {
type = "partition"; type = "partition";
start = "0"; name = "primary";
end = "1M"; start = "1MiB";
part-type = "primary"; end = "100%";
flags = [ "bios_grub" ]; content = {
} type = "filesystem";
{ format = "ext4";
type = "partition"; mountpoint = "/";
name = "mdadm"; };
start = "1MiB"; }
end = "100%"; ];
content = { };
type = "mdraid";
name = "raid1";
};
}
];
};
};
};
mdadm = {
raid1 = {
type = "mdadm";
level = 1;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "primary";
start = "1MiB";
end = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
];
}; };
}; };
}; };

View file

@ -1,49 +1,51 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disko.devices = {
disk0 = { disk = {
device = builtins.elemAt disks 0; disk0 = {
type = "disk"; device = builtins.elemAt disks 0;
content = { type = "disk";
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
name = "nix"; {
type = "partition"; name = "nix";
part-type = "primary"; type = "partition";
start = "0%"; part-type = "primary";
end = "100%"; start = "0%";
bootable = true; end = "100%";
content = { bootable = true;
type = "filesystem"; content = {
format = "ext4"; type = "filesystem";
mountpoint = "/a"; format = "ext4";
}; mountpoint = "/a";
} };
]; }
];
};
}; };
}; disk1 = {
disk1 = { device = builtins.elemAt disks 1;
device = builtins.elemAt disks 1; type = "disk";
type = "disk"; content = {
content = { type = "table";
type = "table"; format = "gpt";
format = "gpt"; partitions = [
partitions = [ {
{ name = "root";
name = "root"; type = "partition";
type = "partition"; part-type = "primary";
part-type = "primary"; start = "0%";
start = "0%"; end = "100%";
end = "100%"; bootable = true;
bootable = true; content = {
content = { type = "filesystem";
type = "filesystem"; format = "ext4";
format = "ext4"; mountpoint = "/b";
mountpoint = "/b"; };
}; }
} ];
]; };
}; };
}; };
}; };

View file

@ -1,26 +1,28 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disko.devices = {
disk0 = { disk = {
device = builtins.elemAt disks 0; disk0 = {
type = "disk"; device = builtins.elemAt disks 0;
content = { type = "disk";
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
name = "nix"; {
type = "partition"; name = "nix";
part-type = "primary"; type = "partition";
start = "0%"; part-type = "primary";
end = "-10MiB"; start = "0%";
bootable = true; end = "-10MiB";
content = { bootable = true;
type = "filesystem"; content = {
format = "ext4"; type = "filesystem";
mountpoint = "/"; format = "ext4";
}; mountpoint = "/";
} };
]; }
];
};
}; };
}; };
}; };

View file

@ -1,38 +1,40 @@
{ disks ? [ "/dev/vdb" ], ... }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disko.devices = {
vdb = { disk = {
device = builtins.elemAt disks 0; vdb = {
type = "disk"; device = builtins.elemAt disks 0;
content = { type = "disk";
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
type = "partition"; {
name = "ESP"; type = "partition";
start = "1MiB"; name = "ESP";
end = "100MiB"; start = "1MiB";
bootable = true; end = "100MiB";
content = { bootable = true;
type = "filesystem"; content = {
format = "vfat"; type = "filesystem";
mountpoint = "/boot"; format = "vfat";
}; mountpoint = "/boot";
} };
{ }
name = "root"; {
type = "partition"; name = "root";
start = "100MiB"; type = "partition";
end = "100%"; start = "100MiB";
part-type = "primary"; end = "100%";
bootable = true; part-type = "primary";
content = { bootable = true;
type = "filesystem"; content = {
format = "ext4"; type = "filesystem";
mountpoint = "/"; format = "ext4";
}; mountpoint = "/";
} };
]; }
];
};
}; };
}; };
}; };

View file

@ -14,7 +14,7 @@ let
#}) { #}) {
# inherit lib; # inherit lib;
#}; #};
cfg = { cfg.disko.devices = {
disk = { disk = {
sda = { sda = {
device = "/dev/sda"; device = "/dev/sda";

View file

@ -1,48 +1,50 @@
{ disks ? [ "/dev/vdb" ], ... }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disko.devices = {
vdb = { disk = {
device = builtins.elemAt disks 0; vdb = {
type = "disk"; device = builtins.elemAt disks 0;
content = { type = "disk";
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
type = "partition"; {
name = "ESP"; type = "partition";
start = "1MiB"; name = "ESP";
end = "100MiB"; start = "1MiB";
bootable = true; end = "100MiB";
content = { bootable = true;
type = "filesystem"; content = {
format = "vfat"; type = "filesystem";
mountpoint = "/boot"; format = "vfat";
}; mountpoint = "/boot";
} };
{ }
name = "root"; {
type = "partition"; name = "root";
start = "100MiB"; type = "partition";
end = "-1G"; start = "100MiB";
part-type = "primary"; end = "-1G";
content = { part-type = "primary";
type = "filesystem"; content = {
format = "ext4"; type = "filesystem";
mountpoint = "/"; format = "ext4";
}; mountpoint = "/";
} };
{ }
name = "swap"; {
type = "partition"; name = "swap";
start = "-1G"; type = "partition";
end = "100%"; start = "-1G";
part-type = "primary"; end = "100%";
content = { part-type = "primary";
type = "swap"; content = {
randomEncryption = true; type = "swap";
}; randomEncryption = true;
} };
]; }
];
};
}; };
}; };
}; };

View file

@ -1,48 +1,50 @@
{ disks ? [ "/dev/vdb" ], ... }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disko.devices = {
vdb = { disk = {
device = builtins.elemAt disks 0; vdb = {
type = "disk"; device = builtins.elemAt disks 0;
content = { type = "disk";
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
type = "partition"; {
name = "ESP"; type = "partition";
start = "1MiB"; name = "ESP";
end = "100MiB"; start = "1MiB";
bootable = true; end = "100MiB";
content = { bootable = true;
type = "filesystem"; content = {
format = "vfat"; type = "filesystem";
mountpoint = "/boot"; format = "vfat";
}; mountpoint = "/boot";
} };
{ }
name = "root"; {
type = "partition"; name = "root";
start = "100MiB"; type = "partition";
end = "100%"; start = "100MiB";
part-type = "primary"; end = "100%";
bootable = true; part-type = "primary";
content = { bootable = true;
type = "filesystem"; content = {
format = "ext4"; type = "filesystem";
mountpoint = "/"; format = "ext4";
}; mountpoint = "/";
} };
}
];
};
};
};
nodev = {
"/tmp" = {
fsType = "tmpfs";
mountOptions = [
"size=200M"
]; ];
}; };
}; };
}; };
nodev = {
"/tmp" = {
fsType = "tmpfs";
mountOptions = [
"size=200M"
];
};
};
} }

View file

@ -1,35 +1,37 @@
# Example to create a bios compatible gpt partition # Example to create a bios compatible gpt partition
{ disks ? [ "/dev/vdb" ], lib, ... }: { { disks ? [ "/dev/vdb" ], lib, ... }: {
disk = lib.genAttrs [ (lib.head disks) ] (device: { disko.devices = {
device = device; disk = lib.genAttrs [ (lib.head disks) ] (device: {
type = "disk"; device = device;
content = { type = "disk";
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
name = "boot"; {
type = "partition"; name = "boot";
start = "0"; type = "partition";
end = "1M"; start = "0";
part-type = "primary"; end = "1M";
flags = [ "bios_grub" ]; part-type = "primary";
} flags = [ "bios_grub" ];
{ }
name = "root"; {
type = "partition"; name = "root";
# leave space for the grub aka BIOS boot type = "partition";
start = "1M"; # leave space for the grub aka BIOS boot
end = "100%"; start = "1M";
part-type = "primary"; end = "100%";
bootable = true; part-type = "primary";
content = { bootable = true;
type = "filesystem"; content = {
format = "ext4"; type = "filesystem";
mountpoint = "/"; format = "ext4";
}; mountpoint = "/";
} };
]; }
}; ];
}); };
});
};
} }

View file

@ -1,63 +1,65 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disko.devices = {
vdb = { disk = {
type = "disk"; vdb = {
device = builtins.elemAt disks 0; type = "disk";
content = { device = builtins.elemAt disks 0;
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
type = "partition"; {
name = "ESP"; type = "partition";
start = "1MiB"; name = "ESP";
end = "100MiB"; start = "1MiB";
bootable = true; end = "100MiB";
content = { bootable = true;
type = "filesystem"; content = {
format = "vfat"; type = "filesystem";
mountpoint = "/boot"; format = "vfat";
mountOptions = [ mountpoint = "/boot";
"defaults" mountOptions = [
]; "defaults"
}; ];
} };
{ }
type = "partition"; {
start = "100MiB"; type = "partition";
end = "100%"; start = "100MiB";
name = "primary"; end = "100%";
bootable = true; name = "primary";
content = { bootable = true;
type = "filesystem"; content = {
format = "ext4"; type = "filesystem";
mountpoint = "/"; format = "ext4";
}; mountpoint = "/";
} };
]; }
}; ];
};
vdc = {
type = "disk";
device = builtins.elemAt disks 1;
content = {
type = "zfs";
pool = "zroot";
};
};
};
zpool = {
zroot = {
type = "zpool";
datasets = {
"root" = {
zfs_type = "filesystem";
options.mountpoint = "none";
}; };
"root/zfs_fs" = { };
zfs_type = "filesystem"; vdc = {
mountpoint = "/zfs_fs"; type = "disk";
options."com.sun:auto-snapshot" = "true"; device = builtins.elemAt disks 1;
content = {
type = "zfs";
pool = "zroot";
};
};
};
zpool = {
zroot = {
type = "zpool";
datasets = {
"root" = {
zfs_type = "filesystem";
options.mountpoint = "none";
};
"root/zfs_fs" = {
zfs_type = "filesystem";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
};
}; };
}; };
}; };

View file

@ -1,107 +1,109 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disko.devices = {
x = { disk = {
type = "disk"; x = {
device = builtins.elemAt disks 0; type = "disk";
content = { device = builtins.elemAt disks 0;
type = "table"; content = {
format = "gpt"; type = "table";
partitions = [ format = "gpt";
{ partitions = [
type = "partition"; {
name = "ESP"; type = "partition";
start = "0"; name = "ESP";
end = "64MiB"; start = "0";
fs-type = "fat32"; end = "64MiB";
bootable = true; fs-type = "fat32";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
type = "partition";
name = "zfs";
start = "128MiB";
end = "100%";
content = {
type = "zfs";
pool = "zroot";
};
}
];
};
};
y = {
type = "disk";
device = builtins.elemAt disks 1;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "zfs";
start = "128MiB";
end = "100%";
content = {
type = "zfs";
pool = "zroot";
};
}
];
};
};
};
zpool = {
zroot = {
type = "zpool";
mode = "mirror";
rootFsOptions = {
compression = "lz4";
"com.sun:auto-snapshot" = "false";
};
mountpoint = "/";
datasets = {
zfs_fs = {
zfs_type = "filesystem";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
};
zfs_unmounted_fs = {
zfs_type = "filesystem";
options.mountpoint = "none";
};
zfs_legacy_fs = {
zfs_type = "filesystem";
options.mountpoint = "legacy";
mountpoint = "/zfs_legacy_fs";
};
zfs_testvolume = {
zfs_type = "volume";
size = "10M";
content = { content = {
type = "filesystem"; type = "filesystem";
format = "vfat"; format = "ext4";
mountpoint = "/boot"; mountpoint = "/ext4onzfs";
}; };
}
{
type = "partition";
name = "zfs";
start = "128MiB";
end = "100%";
content = {
type = "zfs";
pool = "zroot";
};
}
];
};
};
y = {
type = "disk";
device = builtins.elemAt disks 1;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "zfs";
start = "128MiB";
end = "100%";
content = {
type = "zfs";
pool = "zroot";
};
}
];
};
};
};
zpool = {
zroot = {
type = "zpool";
mode = "mirror";
rootFsOptions = {
compression = "lz4";
"com.sun:auto-snapshot" = "false";
};
mountpoint = "/";
datasets = {
zfs_fs = {
zfs_type = "filesystem";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
};
zfs_unmounted_fs = {
zfs_type = "filesystem";
options.mountpoint = "none";
};
zfs_legacy_fs = {
zfs_type = "filesystem";
options.mountpoint = "legacy";
mountpoint = "/zfs_legacy_fs";
};
zfs_testvolume = {
zfs_type = "volume";
size = "10M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4onzfs";
}; };
}; encrypted = {
encrypted = { zfs_type = "filesystem";
zfs_type = "filesystem"; size = "20M";
size = "20M"; options = {
options = { mountpoint = "none";
mountpoint = "none"; encryption = "aes-256-gcm";
encryption = "aes-256-gcm"; keyformat = "passphrase";
keyformat = "passphrase"; keylocation = "file:///tmp/secret.key";
keylocation = "file:///tmp/secret.key"; };
};
"encrypted/test" = {
zfs_type = "filesystem";
size = "2M";
mountpoint = "/zfs_crypted";
}; };
};
"encrypted/test" = {
zfs_type = "filesystem";
size = "2M";
mountpoint = "/zfs_crypted";
}; };
}; };
}; };

View file

@ -18,10 +18,9 @@ makeDiskoTest {
machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm"); machine.succeed("mountpoint /ext4_on_lvm");
''; '';
enableOCR = true;
bootCommands = '' bootCommands = ''
machine.wait_for_text("[Pp]assphrase for") machine.wait_for_console_text("vda")
machine.send_chars("secretsecret\n") machine.send_console("secretsecret\n")
''; '';
extraConfig = { extraConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ]; boot.kernelModules = [ "dm-raid" "dm-mirror" ];

View file

@ -17,10 +17,9 @@ makeDiskoTest {
machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm"); machine.succeed("mountpoint /ext4_on_lvm");
''; '';
enableOCR = true;
bootCommands = '' bootCommands = ''
machine.wait_for_text("[Pp]assphrase for") machine.wait_for_console_text("vda")
machine.send_chars("secretsecret\n") machine.send_console("secretsecret\n")
''; '';
extraConfig = { extraConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ]; boot.kernelModules = [ "dm-raid" "dm-mirror" ];

View file

@ -22,8 +22,7 @@ let
(lib.attrNames (builtins.readDir ./.)) (lib.attrNames (builtins.readDir ./.))
); );
allTests = lib.genAttrs allTestFilenames (test: import (./. + "/${test}.nix") { inherit makeDiskoTest pkgs; }) // allTests = lib.genAttrs allTestFilenames (test: import (./. + "/${test}.nix") { inherit makeDiskoTest pkgs; }) // {
evalTest "lvm-luks-example" ../example/config.nix // {
standalone = (pkgs.nixos [ ../example/stand-alone/configuration.nix ]).config.system.build.toplevel; standalone = (pkgs.nixos [ ../example/stand-alone/configuration.nix ]).config.system.build.toplevel;
}; };
in in

View file

@ -30,16 +30,16 @@
tsp-mount = (tsp-generator.mountScript (import disko-config { disks = builtins.tail disks; inherit lib; })) pkgs; tsp-mount = (tsp-generator.mountScript (import disko-config { disks = builtins.tail disks; inherit lib; })) pkgs;
tsp-disko = (tsp-generator.zapCreateMountScript (import disko-config { disks = builtins.tail disks; inherit lib; })) pkgs; tsp-disko = (tsp-generator.zapCreateMountScript (import disko-config { disks = builtins.tail disks; inherit lib; })) pkgs;
tsp-config = tsp-generator.config (import disko-config { inherit disks; inherit lib; }); tsp-config = tsp-generator.config (import disko-config { inherit disks; inherit lib; });
num-disks = builtins.length (lib.attrNames (import disko-config { inherit lib; }).disk); num-disks = builtins.length (lib.attrNames (import disko-config { inherit lib; }).disko.devices.disk);
installed-system = { modulesPath, ... }: { installed-system = { modulesPath, ... }: {
imports = [ imports = [
(lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config) (lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config)
(lib.optionalAttrs (testMode == "module") { (lib.optionalAttrs (testMode == "module") {
imports = [ ../module.nix ]; disko.enableConfig = true;
disko = { imports = [
enableConfig = true; ../module.nix
devices = import disko-config { inherit disks lib; }; (import disko-config { inherit disks lib; })
}; ];
}) })
(modulesPath + "/testing/test-instrumentation.nix") (modulesPath + "/testing/test-instrumentation.nix")
(modulesPath + "/profiles/qemu-guest.nix") (modulesPath + "/profiles/qemu-guest.nix")
@ -55,7 +55,7 @@
documentation.enable = false; documentation.enable = false;
hardware.enableAllFirmware = lib.mkForce false; hardware.enableAllFirmware = lib.mkForce false;
networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs
boot.kernelParams = lib.mkAfter [ "console=tty0" ]; # needed to have serial interaction during boot boot.kernelParams = lib.mkIf enableOCR [ "console=tty0" ]; # needed for OCR
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
boot.consoleLogLevel = lib.mkForce 100; boot.consoleLogLevel = lib.mkForce 100;
@ -77,11 +77,13 @@
nodes.machine = { config, pkgs, modulesPath, ... }: { nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [ imports = [
(lib.optionalAttrs (testMode == "module") { (lib.optionalAttrs (testMode == "module") {
imports = [ ../module.nix ]; imports = [
../module.nix
];
disko = { disko = {
enableConfig = false; enableConfig = false;
checkScripts = true; checkScripts = true;
devices = import disko-config { disks = builtins.tail disks; inherit lib; }; devices = (import disko-config { disks = builtins.tail disks; inherit lib; }).disko.devices;
}; };
}) })
(lib.optionalAttrs (testMode == "cli") { (lib.optionalAttrs (testMode == "cli") {

View file

@ -8,9 +8,8 @@ makeDiskoTest {
machine.succeed("cryptsetup isLuks /dev/vda2"); machine.succeed("cryptsetup isLuks /dev/vda2");
machine.succeed("mountpoint /home"); machine.succeed("mountpoint /home");
''; '';
enableOCR = true;
bootCommands = '' bootCommands = ''
machine.wait_for_text("[Pp]assphrase for") machine.wait_for_console_text("vda")
machine.send_chars("secretsecret\n") machine.send_console("secretsecret\n")
''; '';
} }

View file

@ -18,10 +18,9 @@ makeDiskoTest {
machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm"); machine.succeed("mountpoint /ext4_on_lvm");
''; '';
enableOCR = true;
bootCommands = '' bootCommands = ''
machine.wait_for_text("[Pp]assphrase for") machine.wait_for_console_text("vda")
machine.send_chars("secretsecret\n") machine.send_console("secretsecret\n")
''; '';
extraConfig = { extraConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ]; boot.kernelModules = [ "dm-raid" "dm-mirror" ];

View file

@ -13,7 +13,7 @@ makeDiskoTest {
''; '';
enableOCR = true; enableOCR = true;
bootCommands = '' bootCommands = ''
machine.wait_for_text("(?:passphrase|key) for") machine.wait_for_text("passphrase for")
machine.send_chars("secretsecret\n") machine.send_chars("secretsecret\n")
''; '';
extraTestScript = '' extraTestScript = ''