From 769bde0834470f3c7316554863931350e8598b93 Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 3 Mar 2023 08:09:13 +0100 Subject: [PATCH] turn disk configs into valid nixos configuration --- default.nix | 32 +-- docs/quickstart.md | 6 +- example/bcachefs.nix | 68 ++--- example/boot-raid1.nix | 214 ++++++++-------- example/btrfs-subvolumes.nix | 92 +++---- example/complex.nix | 346 +++++++++++++------------- example/config.nix | 69 ----- example/gpt-bios-compat.nix | 64 ++--- example/hybrid-tmpfs-on-root.nix | 97 ++++---- example/hybrid.nix | 83 +++--- example/luks-lvm.nix | 124 ++++----- example/lvm-raid.nix | 204 +++++++-------- example/mdadm.nix | 154 ++++++------ example/multi-device-no-deps.nix | 90 +++---- example/negative-size.nix | 46 ++-- example/simple-efi.nix | 70 +++--- example/stand-alone/configuration.nix | 2 +- example/swap.nix | 90 +++---- example/tmpfs.nix | 84 ++++--- example/with-lib.nix | 66 ++--- example/zfs-over-legacy.nix | 118 ++++----- example/zfs.nix | 198 +++++++-------- tests/default.nix | 3 +- tests/lib.nix | 18 +- 24 files changed, 1152 insertions(+), 1186 deletions(-) delete mode 100644 example/config.nix diff --git a/default.nix b/default.nix index c352481..c6a8700 100644 --- a/default.nix +++ b/default.nix @@ -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; } diff --git a/docs/quickstart.md b/docs/quickstart.md index 56f9e77..5046528 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -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/" ]; # replace this with your disk name i.e. /dev/nvme0n1 + }) ]; - disko.devices = pkgs.callPackage ./disko-config.nix { - disks = [ "/dev/" ]; # replace this with your disk name i.e. /dev/nvme0n1 - }; ``` If you went for the hybrid-partition scheme, than choose grub as a bootloader. diff --git a/example/bcachefs.nix b/example/bcachefs.nix index a98c42a..e1df20e 100644 --- a/example/bcachefs.nix +++ b/example/bcachefs.nix @@ -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 = "/"; + }; + } + ]; + }; }; }; }; diff --git a/example/boot-raid1.nix b/example/boot-raid1.nix index e0f26ae..139922d 100644 --- a/example/boot-raid1.nix +++ b/example/boot-raid1.nix @@ -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 = "/"; + }; + } + ]; + }; }; }; }; diff --git a/example/btrfs-subvolumes.nix b/example/btrfs-subvolumes.nix index a574570..7484961 100644 --- a/example/btrfs-subvolumes.nix +++ b/example/btrfs-subvolumes.nix @@ -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" = { }; + }; + }; + } + ]; + }; }; }; }; diff --git a/example/complex.nix b/example/complex.nix index 1c02ef9..e222339 100644 --- a/example/complex.nix +++ b/example/complex.nix @@ -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"; + }; }; }; }; diff --git a/example/config.nix b/example/config.nix deleted file mode 100644 index 6117506..0000000 --- a/example/config.nix +++ /dev/null @@ -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"; - }; - }; - } - ]; - }; - }; - }; -} diff --git a/example/gpt-bios-compat.nix b/example/gpt-bios-compat.nix index 6d2ae68..c64930e 100644 --- a/example/gpt-bios-compat.nix +++ b/example/gpt-bios-compat.nix @@ -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 = "/"; + }; + } + ]; + }; }; }; }; diff --git a/example/hybrid-tmpfs-on-root.nix b/example/hybrid-tmpfs-on-root.nix index 4f48101..8eef875 100644 --- a/example/hybrid-tmpfs-on-root.nix +++ b/example/hybrid-tmpfs-on-root.nix @@ -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" - ]; - }; } diff --git a/example/hybrid.nix b/example/hybrid.nix index 341cec1..92aacf3 100644 --- a/example/hybrid.nix +++ b/example/hybrid.nix @@ -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 = "/"; + }; + } + ]; + }; }; }; }; diff --git a/example/luks-lvm.nix b/example/luks-lvm.nix index 51cd24c..733333e 100644 --- a/example/luks-lvm.nix +++ b/example/luks-lvm.nix @@ -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"; - }; }; }; }; diff --git a/example/lvm-raid.nix b/example/lvm-raid.nix index 70ea197..cf20b21 100644 --- a/example/lvm-raid.nix +++ b/example/lvm-raid.nix @@ -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"; + }; }; }; }; diff --git a/example/mdadm.nix b/example/mdadm.nix index f5a1d2e..efe95c6 100644 --- a/example/mdadm.nix +++ b/example/mdadm.nix @@ -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 = "/"; + }; + } + ]; + }; }; }; }; diff --git a/example/multi-device-no-deps.nix b/example/multi-device-no-deps.nix index 2ad5f47..a01644b 100644 --- a/example/multi-device-no-deps.nix +++ b/example/multi-device-no-deps.nix @@ -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"; + }; + } + ]; + }; }; }; }; diff --git a/example/negative-size.nix b/example/negative-size.nix index e41bae6..9ec27ab 100644 --- a/example/negative-size.nix +++ b/example/negative-size.nix @@ -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 = "/"; + }; + } + ]; + }; }; }; }; diff --git a/example/simple-efi.nix b/example/simple-efi.nix index c69c847..0a5f2d1 100644 --- a/example/simple-efi.nix +++ b/example/simple-efi.nix @@ -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 = "/"; + }; + } + ]; + }; }; }; }; diff --git a/example/stand-alone/configuration.nix b/example/stand-alone/configuration.nix index 9a1f298..973f3f2 100644 --- a/example/stand-alone/configuration.nix +++ b/example/stand-alone/configuration.nix @@ -14,7 +14,7 @@ let #}) { # inherit lib; #}; - cfg = { + cfg.disko.devices = { disk = { sda = { device = "/dev/sda"; diff --git a/example/swap.nix b/example/swap.nix index 13393fe..e442b9c 100644 --- a/example/swap.nix +++ b/example/swap.nix @@ -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; + }; + } + ]; + }; }; }; }; diff --git a/example/tmpfs.nix b/example/tmpfs.nix index fb45f8a..8942e9f 100644 --- a/example/tmpfs.nix +++ b/example/tmpfs.nix @@ -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" - ]; - }; - }; } diff --git a/example/with-lib.nix b/example/with-lib.nix index 78bb50d..4500f3e 100644 --- a/example/with-lib.nix +++ b/example/with-lib.nix @@ -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 = "/"; + }; + } + ]; + }; + }); + }; } diff --git a/example/zfs-over-legacy.nix b/example/zfs-over-legacy.nix index 1a6bbd3..9ca67a8 100644 --- a/example/zfs-over-legacy.nix +++ b/example/zfs-over-legacy.nix @@ -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"; + }; }; }; }; diff --git a/example/zfs.nix b/example/zfs.nix index 0db9ee7..aebb6a3 100644 --- a/example/zfs.nix +++ b/example/zfs.nix @@ -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"; }; }; }; diff --git a/tests/default.nix b/tests/default.nix index 3a9e072..a365e61 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 diff --git a/tests/lib.nix b/tests/lib.nix index b2f2d2e..e67eb5b 100644 --- a/tests/lib.nix +++ b/tests/lib.nix @@ -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") {