turn disk configs into valid nixos configuration

This commit is contained in:
lassulus 2023-03-03 08:09:13 +01:00
parent cd825b85fb
commit 769bde0834
24 changed files with 1152 additions and 1186 deletions

View file

@ -7,9 +7,9 @@ let
eval = cfg: lib.evalModules {
modules = lib.singleton {
# _file = toString input;
imports = lib.singleton { devices = cfg; };
imports = lib.singleton { disko.devices = cfg.disko.devices; };
options = {
devices = lib.mkOption {
disko.devices = lib.mkOption {
type = types.devices;
};
};
@ -18,30 +18,30 @@ let
in
{
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" ''
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}:$PATH
${types.diskoLib.create (eval cfg).config.devices}
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
${types.diskoLib.create (eval cfg).config.disko.devices}
'';
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" ''
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}:$PATH
${types.diskoLib.mount (eval cfg).config.devices}
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
${types.diskoLib.mount (eval cfg).config.disko.devices}
'';
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" ''
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}:$PATH
${types.diskoLib.zapCreateMount (eval cfg).config.devices}
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
${types.diskoLib.zapCreateMount (eval cfg).config.disko.devices}
'';
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; };
packages = cfg: types.diskoLib.packages (eval cfg).config.devices;
config = cfg: { imports = types.diskoLib.config (eval cfg).config.disko.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.
./hardware-configuration.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.

View file

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

View file

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

View file

@ -1,196 +1,198 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" "/dev/vdd" ], ... }: {
disk = {
disk0 = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "128MiB";
fs-type = "fat32";
bootable = true;
content = {
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"
];
disko.devices = {
disk = {
disk0 = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "128MiB";
fs-type = "fat32";
bootable = true;
content = {
type = "lvm_pv";
vg = "pool";
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
}
];
}
];
};
};
};
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"
];
disk1 = {
type = "disk";
device = builtins.elemAt disks 1;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
start = "1M";
end = "100%";
name = "luks";
content = {
type = "lvm_pv";
vg = "pool";
type = "luks";
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 = {
raid1 = {
type = "mdadm";
level = 1;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "bla";
start = "1MiB";
end = "100%";
mdadm = {
raid1 = {
type = "mdadm";
level = 1;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "bla";
start = "1MiB";
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 = {
type = "filesystem";
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 = {
type = "lvm_lv";
size = "30M";
lvm_type = "raid0";
content = {
type = "mdraid";
name = "raid1";
raid1 = {
type = "lvm_lv";
size = "30M";
lvm_type = "raid0";
content = {
type = "mdraid";
name = "raid1";
};
};
};
raid2 = {
type = "lvm_lv";
size = "30M";
lvm_type = "raid0";
content = {
type = "mdraid";
name = "raid1";
raid2 = {
type = "lvm_lv";
size = "30M";
lvm_type = "raid0";
content = {
type = "mdraid";
name = "raid1";
};
};
};
zfs1 = {
type = "lvm_lv";
size = "128M";
lvm_type = "raid0";
content = {
type = "zfs";
pool = "zroot";
zfs1 = {
type = "lvm_lv";
size = "128M";
lvm_type = "raid0";
content = {
type = "zfs";
pool = "zroot";
};
};
};
zfs2 = {
type = "lvm_lv";
size = "128M";
lvm_type = "raid0";
content = {
type = "zfs";
pool = "zroot";
zfs2 = {
type = "lvm_lv";
size = "128M";
lvm_type = "raid0";
content = {
type = "zfs";
pool = "zroot";
};
};
};
};
};
};
zpool = {
zroot = {
type = "zpool";
mode = "mirror";
rootFsOptions = {
compression = "lz4";
"com.sun:auto-snapshot" = "false";
};
mountpoint = "/";
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";
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";
};
};
};
};

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
{ disks ? [ "/dev/vdb" ], ... }: {
disk = {
vdb = {
device = builtins.elemAt disks 0;
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 = "/";
};
}
];
disko.devices = {
disk = {
vdb = {
device = builtins.elemAt disks 0;
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,52 +1,53 @@
{ disks ? [ "/dev/sda" ], ... }:
{
disk.main = {
device = builtins.elemAt disks 0;
type = "disk";
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1M";
end = "512M";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "nix";
type = "partition";
start = "512M";
end = "100%";
part-type = "primary";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/nix";
};
}
{ disks ? [ "/dev/sda" ], ... }: {
disko.devices = {
disk.main = {
device = builtins.elemAt disks 0;
type = "disk";
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1M";
end = "512M";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "nix";
type = "partition";
start = "512M";
end = "100%";
part-type = "primary";
content = {
type = "filesystem";
format = "ext4";
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" ], ... }:
{
disk = {
main = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1M";
end = "512M";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
type = "partition";
name = "root";
start = "512M";
end = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
];
{ disks ? [ "/dev/vda" ], ... }: {
disko.devices = {
disk = {
main = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1M";
end = "512M";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
type = "partition";
name = "root";
start = "512M";
end = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
];
};
};
};
};

View file

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

View file

@ -1,107 +1,109 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = {
one = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "100M";
fs-type = "fat32";
bootable = true;
content = {
type = "mdraid";
disko.devices = {
disk = {
one = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "boot";
};
}
{
type = "partition";
name = "primary";
start = "100M";
end = "100%";
content = {
type = "lvm_pv";
vg = "pool";
};
}
];
};
};
two = {
type = "disk";
device = builtins.elemAt disks 1;
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"
];
};
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";
};
}
];
};
home = {
type = "lvm_lv";
size = "10M";
lvm_type = "raid0";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
};
two = {
type = "disk";
device = builtins.elemAt disks 1;
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";
size = "10M";
lvm_type = "raid0";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
};
};
};
};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,48 +1,50 @@
{ disks ? [ "/dev/vdb" ], ... }: {
disk = {
vdb = {
device = builtins.elemAt disks 0;
type = "disk";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "root";
type = "partition";
start = "100MiB";
end = "100%";
part-type = "primary";
bootable = true;
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
disko.devices = {
disk = {
vdb = {
device = builtins.elemAt disks 0;
type = "disk";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "root";
type = "partition";
start = "100MiB";
end = "100%";
part-type = "primary";
bootable = true;
content = {
type = "filesystem";
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
{ disks ? [ "/dev/vdb" ], lib, ... }: {
disk = 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 = "/";
};
}
];
};
});
disko.devices = {
disk = 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,63 +1,65 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = {
vdb = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [
"defaults"
];
};
}
{
type = "partition";
start = "100MiB";
end = "100%";
name = "primary";
bootable = true;
content = {
type = "filesystem";
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";
disko.devices = {
disk = {
vdb = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [
"defaults"
];
};
}
{
type = "partition";
start = "100MiB";
end = "100%";
name = "primary";
bootable = true;
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
];
};
"root/zfs_fs" = {
zfs_type = "filesystem";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
};
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";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
};
};
};
};

View file

@ -1,107 +1,109 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = {
x = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "0";
end = "64MiB";
fs-type = "fat32";
bootable = true;
disko.devices = {
disk = {
x = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "0";
end = "64MiB";
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 = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
format = "ext4";
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 = {
zfs_type = "filesystem";
size = "20M";
options = {
mountpoint = "none";
encryption = "aes-256-gcm";
keyformat = "passphrase";
keylocation = "file:///tmp/secret.key";
encrypted = {
zfs_type = "filesystem";
size = "20M";
options = {
mountpoint = "none";
encryption = "aes-256-gcm";
keyformat = "passphrase";
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

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

View file

@ -30,16 +30,16 @@
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-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, ... }: {
imports = [
(lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config)
(lib.optionalAttrs (testMode == "module") {
imports = [ ../module.nix ];
disko = {
enableConfig = true;
devices = import disko-config { inherit disks lib; };
};
disko.enableConfig = true;
imports = [
../module.nix
(import disko-config { inherit disks lib; })
];
})
(modulesPath + "/testing/test-instrumentation.nix")
(modulesPath + "/profiles/qemu-guest.nix")
@ -77,11 +77,13 @@
nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [
(lib.optionalAttrs (testMode == "module") {
imports = [ ../module.nix ];
imports = [
../module.nix
];
disko = {
enableConfig = false;
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") {