tests: pass lib to examples

This commit is contained in:
lassulus 2022-10-21 14:43:55 +02:00
parent c96ccd7d9f
commit 8666475b74
12 changed files with 59 additions and 13 deletions

View File

@ -1,4 +1,4 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disk = {
one = { one = {
type = "disk"; type = "disk";

View File

@ -1,4 +1,4 @@
{ disks ? [ "/dev/vdb" ] }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disk = {
vdb = { vdb = {
type = "disk"; type = "disk";

View File

@ -1,4 +1,4 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disk = {
disk0 = { disk0 = {
type = "disk"; type = "disk";

View File

@ -1,5 +1,5 @@
# Example to create a bios compatible gpt partition # Example to create a bios compatible gpt partition
{ disks ? [ "/dev/vdb" ] }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disk = {
vdb = { vdb = {
device = builtins.elemAt disks 0; device = builtins.elemAt disks 0;

View File

@ -1,4 +1,4 @@
{ disks ? [ "/dev/vdb" ] }: { { disks ? [ "/dev/vdb" ], ... }: {
disk = { disk = {
vdb = { vdb = {
type = "disk"; type = "disk";

View File

@ -1,4 +1,4 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disk = {
one = { one = {
type = "disk"; type = "disk";

View File

@ -1,4 +1,4 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disk = {
vdb = { vdb = {
type = "disk"; type = "disk";

35
example/with-lib.nix Normal file
View File

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

View File

@ -1,4 +1,4 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disk = {
vdb = { vdb = {
type = "disk"; type = "disk";

View File

@ -1,4 +1,4 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: { { disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = { disk = {
x = { x = {
type = "disk"; type = "disk";

View File

@ -21,10 +21,10 @@
inherit (pkgs) system; inherit (pkgs) system;
}; };
disks = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf" ]; disks = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf" ];
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create (disko-config { disks = builtins.tail disks; })); tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create (disko-config { disks = builtins.tail disks; inherit lib; }));
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount (disko-config { disks = builtins.tail disks; })); tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount (disko-config { disks = builtins.tail disks; inherit lib; }));
tsp-config = (pkgs.callPackage ../. { }).config (disko-config { inherit disks; }); tsp-config = (pkgs.callPackage ../. { }).config (disko-config { inherit disks; inherit lib; });
num-disks = builtins.length (lib.attrNames (disko-config {}).disk); num-disks = builtins.length (lib.attrNames (disko-config { inherit lib; }).disk);
installed-system = { modulesPath, ... }: { installed-system = { modulesPath, ... }: {
imports = [ imports = [
tsp-config tsp-config

11
tests/with-lib.nix Normal file
View File

@ -0,0 +1,11 @@
{ pkgs ? (import <nixpkgs> { })
, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
}:
makeDiskoTest {
disko-config = import ../example/with-lib.nix;
extraTestScript = ''
machine.succeed("mountpoint /");
'';
efi = false;
grub-devices = [ "/dev/vdb" ];
}