diff options
Diffstat (limited to 'example')
-rw-r--r-- | example/boot-raid1.nix | 117 | ||||
-rw-r--r-- | example/btrfs-subvolumes.nix | 52 | ||||
-rw-r--r-- | example/complex.nix | 199 | ||||
-rw-r--r-- | example/config.nix | 112 | ||||
-rw-r--r-- | example/default.nix | 9 | ||||
-rw-r--r-- | example/gpt-bios-compat.nix | 37 | ||||
-rw-r--r-- | example/luks-lvm.nix | 76 | ||||
-rw-r--r-- | example/lvm-raid.nix | 110 | ||||
-rw-r--r-- | example/mdadm.nix | 83 | ||||
-rw-r--r-- | example/multi-device-no-deps.nix | 50 | ||||
-rw-r--r-- | example/negative-size.nix | 27 | ||||
-rw-r--r-- | example/simple-efi.nix | 40 | ||||
-rw-r--r-- | example/stand-alone/configuration.nix | 55 | ||||
-rw-r--r-- | example/stand-alone/tsp-disk.json | 22 | ||||
-rw-r--r-- | example/swap.nix | 50 | ||||
-rw-r--r-- | example/tmpfs.nix | 48 | ||||
-rw-r--r-- | example/with-lib.nix | 35 | ||||
-rw-r--r-- | example/zfs-over-legacy.nix | 66 | ||||
-rw-r--r-- | example/zfs.nix | 95 |
19 files changed, 1189 insertions, 94 deletions
diff --git a/example/boot-raid1.nix b/example/boot-raid1.nix new file mode 100644 index 0000000..dfd2e6c --- /dev/null +++ b/example/boot-raid1.nix @@ -0,0 +1,117 @@ +{ 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"; + 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"; + 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"; + }; + }; + 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 new file mode 100644 index 0000000..25994df --- /dev/null +++ b/example/btrfs-subvolumes.nix @@ -0,0 +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" = {}; + }; + }; + } + ]; + }; + }; + }; +} + diff --git a/example/complex.nix b/example/complex.nix new file mode 100644 index 0000000..939f71e --- /dev/null +++ b/example/complex.nix @@ -0,0 +1,199 @@ +{ 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"; + extraArgs = [ + "--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"; + extraArgs = [ + "--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%"; + 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_on_lvm"; + mountOptions = [ + "defaults" + ]; + }; + }; + 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"; + }; + }; + 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"; + }; + }; + }; + }; + }; + 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"; + }; + }; + }; + }; + }; +} diff --git a/example/config.nix b/example/config.nix index 199412d..58edb1e 100644 --- a/example/config.nix +++ b/example/config.nix @@ -1,66 +1,70 @@ # usage: nix-instantiate --eval --json --strict example/config.nix | jq . { - type = "devices"; - content = { - sda = { - type = "table"; - format = "gpt"; - partitions = [ - { - type = "partition"; - part-type = "ESP"; - start = "1MiB"; - end = "1024MiB"; - fs-type = "fat32"; - bootable = true; + lvm_vg = { + pool = { + type = "lvm_vg"; + lvs = { + root = { + type = "lv"; + size = "10G"; content = { type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; + format = "ext4"; + mountpoint = "/"; }; - } - { - type = "partition"; - part-type = "primary"; - start = "1024MiB"; - end = "100%"; + }; + home = { + type = "lv"; + size = "10G"; content = { - type = "luks"; - algo = "aes-xts..."; - name = "crypted"; - keyfile = "/tmp/secret.key"; - extraArgs = [ - "--hash sha512" - "--iter-time 5000" - ]; + type = "filesystem"; + format = "ext4"; + mountpoint = "/home"; + }; + }; + }; + }; + }; + disk = { + sda = { + device = "/dev/sda"; + content = { + type = "table"; + format = "gpt"; + partitions = [ + { + name = "boot"; + type = "partition"; + part-type = "ESP"; + 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 = "lvm"; - name = "pool"; - lvs = { - root = { - type = "lv"; - size = "10G"; - mountpoint = "/"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; - }; - }; - home = { - type = "lv"; - size = "10G"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/home"; - }; - }; + type = "luks"; + name = "crypted"; + keyFile = "/tmp/secret.key"; + content = { + type = "lvm_pv"; + vg = "pool"; }; }; - }; - } - ]; + } + ]; + }; }; }; } diff --git a/example/default.nix b/example/default.nix deleted file mode 100644 index aa03d27..0000000 --- a/example/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -# usage: nix-instantiate --eval --json --strict example | jq -r . - -with import ../lib; - -{ - config = config (import ./config.nix); - create = create (import ./config.nix); - mount = mount (import ./config.nix); -} diff --git a/example/gpt-bios-compat.nix b/example/gpt-bios-compat.nix new file mode 100644 index 0000000..7275e26 --- /dev/null +++ b/example/gpt-bios-compat.nix @@ -0,0 +1,37 @@ +# 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 = "/"; + }; + } + ]; + }; + }; + }; +} diff --git a/example/luks-lvm.nix b/example/luks-lvm.nix new file mode 100644 index 0000000..a6879ce --- /dev/null +++ b/example/luks-lvm.nix @@ -0,0 +1,76 @@ +{ 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; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ + "defaults" + ]; + }; + } + { + type = "partition"; + name = "luks"; + start = "100MiB"; + end = "100%"; + content = { + type = "luks"; + name = "crypted"; + keyFile = "/tmp/secret.key"; + content = { + type = "lvm_pv"; + vg = "pool"; + }; + }; + } + ]; + }; + }; + }; + lvm_vg = { + pool = { + type = "lvm_vg"; + lvs = { + root = { + type = "lvm_lv"; + size = "100M"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + mountOptions = [ + "defaults" + ]; + }; + }; + home = { + type = "lvm_lv"; + size = "10M"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/home"; + }; + }; + raw = { + type = "lvm_lv"; + size = "10M"; + }; + }; + }; + }; +} diff --git a/example/lvm-raid.nix b/example/lvm-raid.nix new file mode 100644 index 0000000..70ea197 --- /dev/null +++ b/example/lvm-raid.nix @@ -0,0 +1,110 @@ +{ 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"; + 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" + ]; + }; + }; + 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 new file mode 100644 index 0000000..132ead5 --- /dev/null +++ b/example/mdadm.nix @@ -0,0 +1,83 @@ +{ 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"; + }; + } + ]; + }; + }; + 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 = "/"; + }; + } + ]; + }; + }; + }; +} diff --git a/example/multi-device-no-deps.nix b/example/multi-device-no-deps.nix new file mode 100644 index 0000000..2ad5f47 --- /dev/null +++ b/example/multi-device-no-deps.nix @@ -0,0 +1,50 @@ +{ 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"; + }; + } + ]; + }; + }; + 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 new file mode 100644 index 0000000..e41bae6 --- /dev/null +++ b/example/negative-size.nix @@ -0,0 +1,27 @@ +{ 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 = "/"; + }; + } + ]; + }; + }; + }; +} diff --git a/example/simple-efi.nix b/example/simple-efi.nix new file mode 100644 index 0000000..c69c847 --- /dev/null +++ b/example/simple-efi.nix @@ -0,0 +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 = "/"; + }; + } + ]; + }; + }; + }; +} + diff --git a/example/stand-alone/configuration.nix b/example/stand-alone/configuration.nix index 2ee1597..67576a0 100644 --- a/example/stand-alone/configuration.nix +++ b/example/stand-alone/configuration.nix @@ -1,17 +1,54 @@ -{ pkgs, ... }: -let - disko = (builtins.fetchGit { - url = https://cgit.lassul.us/disko/; - rev = "88f56a0b644dd7bfa8438409bea5377adef6aef4"; - }) + "/lib"; - cfg = builtins.fromJSON ./tsp-disk.json; +{ + pkgs, + lib, + ... +}: let + # We just import from the repository for testing here: + disko = import ../../. { + inherit lib; + }; + # In your own system use something like this: + #import (builtins.fetchGit { + # url = "https://github.com/nix-community/disko"; + # ref = "master"; + #}) { + # inherit lib; + #}; + cfg = { + disk = { + sda = { + device = "/dev/sda"; + type = "device"; + content = { + type = "table"; + format = "msdos"; + partitions = [ + { + name = "root"; + type = "partition"; + part-type = "primary"; + start = "1M"; + end = "100%"; + bootable = true; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + } + ]; + }; + }; + }; + }; in { imports = [ (disko.config cfg) ]; - environment.systemPackages = with pkgs;[ + boot.loader.grub.devices = [ "/dev/sda" ]; + system.stateVersion = "22.05"; + environment.systemPackages = with pkgs; [ (pkgs.writeScriptBin "tsp-create" (disko.create cfg)) (pkgs.writeScriptBin "tsp-mount" (disko.mount cfg)) ]; } - diff --git a/example/stand-alone/tsp-disk.json b/example/stand-alone/tsp-disk.json deleted file mode 100644 index 1d82c13..0000000 --- a/example/stand-alone/tsp-disk.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "type": "devices", - "content": { - "sda": { - "type": "table", - "format": "msdos", - "partitions": [ - { "type": "partition", - "start": "1M", - "end": "100%", - "bootable": true, - "content": { - "type": "filesystem", - "format": "ext4", - "mountpoint": "/" - } - } - ] - } - } -} - diff --git a/example/swap.nix b/example/swap.nix new file mode 100644 index 0000000..13393fe --- /dev/null +++ b/example/swap.nix @@ -0,0 +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; + }; + } + ]; + }; + }; + }; +} + diff --git a/example/tmpfs.nix b/example/tmpfs.nix new file mode 100644 index 0000000..fb45f8a --- /dev/null +++ b/example/tmpfs.nix @@ -0,0 +1,48 @@ +{ disks ? [ "/dev/vdb" ], ... }: { + disk = { + vdb = { + |