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 = {
one = {
type = "disk";

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: {
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = {
vdb = {
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 = {
vdb = {
type = "disk";

View file

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

View file

@ -21,10 +21,10 @@
inherit (pkgs) system;
};
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-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount (disko-config { disks = builtins.tail disks; }));
tsp-config = (pkgs.callPackage ../. { }).config (disko-config { inherit disks; });
num-disks = builtins.length (lib.attrNames (disko-config {}).disk);
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; inherit lib; }));
tsp-config = (pkgs.callPackage ../. { }).config (disko-config { inherit disks; inherit lib; });
num-disks = builtins.length (lib.attrNames (disko-config { inherit lib; }).disk);
installed-system = { modulesPath, ... }: {
imports = [
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" ];
}