summaryrefslogtreecommitdiffstats
path: root/example
diff options
context:
space:
mode:
authorJörg Thalheim <Mic92@users.noreply.github.com>2022-09-04 12:11:54 +0100
committerGitHub <noreply@github.com>2022-09-04 12:11:54 +0100
commitfbc08430d28a65eb3e783feb892659d32abd4551 (patch)
treecba2f7972cb82ff445e68383a46927c8a25ec763 /example
parentadf901d58155ca268d15351fff164d3ef38a0890 (diff)
parent68f950bf2045573b03cd0e1ceebe7131ea999873 (diff)
Merge pull request #31 from nix-community/types
Reimplement using types
Diffstat (limited to 'example')
-rw-r--r--example/btrfs-subvolumes.nix43
-rw-r--r--example/complex.nix194
-rw-r--r--example/config-gpt-bios.nix33
-rw-r--r--example/config.nix117
-rw-r--r--example/gpt-bios-compat.nix37
-rw-r--r--example/luks-lvm.nix130
-rw-r--r--example/lvm-raid.nix112
-rw-r--r--example/mdadm.nix72
-rw-r--r--example/stand-alone/configuration.nix69
-rw-r--r--example/zfs-over-legacy.nix63
-rw-r--r--example/zfs.nix53
11 files changed, 588 insertions, 335 deletions
diff --git a/example/btrfs-subvolumes.nix b/example/btrfs-subvolumes.nix
index 0124c86..83ea71e 100644
--- a/example/btrfs-subvolumes.nix
+++ b/example/btrfs-subvolumes.nix
@@ -1,25 +1,28 @@
{
- type = "devices";
- content = {
+ disk = {
vdb = {
- type = "table";
- format = "gpt";
- partitions = [
- {
- type = "partition";
- part-type = "primary";
- start = "0%";
- end = "100%";
- content = {
- type = "btrfs";
- mountpoint = "/";
- subvolumes = [
- "/home"
- "/test"
- ];
- };
- }
- ];
+ type = "disk";
+ device = "/dev/vdb";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ name = "root";
+ type = "partition";
+ start = "0%";
+ end = "100%";
+ content = {
+ type = "btrfs";
+ mountpoint = "/";
+ subvolumes = [
+ "/home"
+ "/test"
+ ];
+ };
+ }
+ ];
+ };
};
};
}
diff --git a/example/complex.nix b/example/complex.nix
new file mode 100644
index 0000000..078f9c5
--- /dev/null
+++ b/example/complex.nix
@@ -0,0 +1,194 @@
+{
+ disk = {
+ disk1 = {
+ type = "disk";
+ device = "/dev/vdb";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ start = "0";
+ end = "1M";
+ name = "grub";
+ flags = ["bios_grub"];
+ }
+ {
+ type = "partition";
+ start = "1M";
+ end = "100%";
+ name = "luks";
+ bootable = true;
+ content = {
+ type = "luks";
+ name = "crypted1";
+ keyFile = "/tmp/secret.key";
+ extraArgs = [
+ "--hash sha512"
+ "--iter-time 5000"
+ ];
+ content = {
+ type = "lvm_pv";
+ vg = "pool";
+ };
+ };
+ }
+ ];
+ };
+ };
+ disk2 = {
+ type = "disk";
+ device = "/dev/vdc";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ start = "0";
+ end = "1M";
+ name = "grub";
+ flags = ["bios_grub"];
+ }
+ {
+ type = "partition";
+ start = "1M";
+ end = "100%";
+ name = "luks";
+ bootable = true;
+ content = {
+ type = "luks";
+ name = "crypted2";
+ keyFile = "/tmp/secret.key";
+ extraArgs = [
+ "--hash sha512"
+ "--iter-time 5000"
+ ];
+ content = {
+ type = "lvm_pv";
+ vg = "pool";
+ };
+ };
+ }
+ ];
+ };
+ };
+ };
+ mdadm = {
+ raid1 = {
+ type = "mdadm";
+ level = 1;
+ content = {
+ type = "table";
+ format = "msdos";
+ partitions = [
+ {
+ type = "partition";
+ name = "xfs";
+ start = "1MiB";
+ end = "100%";
+ content = {
+ type = "filesystem";
+ format = "xfs";
+ mountpoint = "/xfs_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";
+ options = [
+ "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-gpt-bios.nix b/example/config-gpt-bios.nix
deleted file mode 100644
index 9dfcffa..0000000
--- a/example/config-gpt-bios.nix
+++ /dev/null
@@ -1,33 +0,0 @@
-# Example to create a bios compatible gpt partition
-{
- type = "devices";
- content = {
- sda = {
- type = "table";
- format = "gpt";
- partitions = [
- {
- type = "partition";
- start = "0";
- end = "1M";
- part-type = "primary";
- flags = ["bios_grub"];
- content.type = "noop";
- }
- {
- 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/config.nix b/example/config.nix
index 1a64b1c..f75ec63 100644
--- a/example/config.nix
+++ b/example/config.nix
@@ -1,67 +1,74 @@
# 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%";
- flags = [ "bios_grub" ];
+ };
+ 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";
+ extraArgs = [
+ "--hash sha512"
+ "--iter-time 5000"
+ ];
+ content = {
+ type = "lvm_pv";
+ vg = "pool";
};
};
- };
- }
- ];
+ }
+ ];
+ };
};
};
}
diff --git a/example/gpt-bios-compat.nix b/example/gpt-bios-compat.nix
new file mode 100644
index 0000000..9abe691
--- /dev/null
+++ b/example/gpt-bios-compat.nix
@@ -0,0 +1,37 @@
+# Example to create a bios compatible gpt partition
+{
+ disk = {
+ vdb = {
+ device = "/dev/vdb";
+ 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
index 22c029e..17e18a2 100644
--- a/example/luks-lvm.nix
+++ b/example/luks-lvm.nix
@@ -1,81 +1,81 @@
{
- type = "devices";
- content = {
+ disk = {
vdb = {
- type = "table";
- format = "gpt";
- partitions = [
- {
- type = "partition";
- part-type = "ESP";
- start = "1MiB";
- end = "100MiB";
- fs-type = "FAT32";
- bootable = true;
- content = {
- type = "filesystem";
- format = "vfat";
- mountpoint = "/boot";
- options = [
- "defaults"
- ];
- };
- }
- {
- type = "partition";
- part-type = "primary";
- start = "100MiB";
- end = "100%";
- content = {
- type = "luks";
- algo = "aes-xts...";
- name = "crypted";
- keyfile = "/tmp/secret.key";
- extraArgs = [
- "--hash sha512"
- "--iter-time 5000"
- ];
- content = {
- type = "lvm_pv";
- vg = "pool";
- };
- };
- }
- ];
- };
- pool = {
- type = "lvm_vg";
- lvs = {
- root = {
- type = "lvm_lv";
- size = "100M";
- mountpoint = "/";
+ type = "disk";
+ device = "/dev/vdb";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ name = "ESP";
+ # fs-type = "FAT32";
+ start = "1MiB";
+ end = "100MiB";
+ bootable = true;
content = {
type = "filesystem";
- format = "ext4";
- mountpoint = "/";
+ format = "vfat";
+ mountpoint = "/boot";
options = [
"defaults"
];
};
- };
- home = {
- type = "lvm_lv";
- size = "10M";
+ }
+ {
+ type = "partition";
+ name = "luks";
+ start = "100MiB";
+ end = "100%";
content = {
- type = "filesystem";
- format = "ext4";
- mountpoint = "/home";
+ type = "luks";
+ name = "crypted";
+ keyFile = "/tmp/secret.key";
+ extraArgs = [
+ "--hash sha512"
+ "--iter-time 5000"
+ ];
+ 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 = "/";
+ options = [
+ "defaults"
+ ];
};
- raw = {
- type = "lvm_lv";
- size = "10M";
- content = {
- type = "noop";
- };
+ };
+ 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
index 48930ec..3c5ee69 100644
--- a/example/lvm-raid.nix
+++ b/example/lvm-raid.nix
@@ -1,66 +1,74 @@
{
- type = "devices";
- content = {
+ disk = {
vdb = {
- type = "table";
- format = "gpt";
- partitions = [
- {
- type = "partition";
- part-type = "primary";
- start = "0%";
- end = "100%";
- content = {
- type = "lvm_pv";
- vg = "pool";
- };
- }
- ];
+ type = "disk";
+ device = "/dev/vdb";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ name = "primary";
+ start = "0%";
+ end = "100%";
+ content = {
+ type = "lvm_pv";
+ vg = "pool";
+ };
+ }
+ ];
+ };
};
vdc = {
- type = "table";
- format = "gpt";
- partitions = [
- {
- type = "partition";
- part-type = "primary";
- start = "0%";
- end = "100%";
- content = {
- type = "lvm_pv";
- vg = "pool";
- };
- }
- ];
+ type = "disk";
+ device = "/dev/vdc";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ name = "primary";
+ start = "0%";
+ end = "100%";
+ content = {
+ type = "lvm_pv";
+ vg = "pool";
+ };
+ }
+ ];
+ };
};
+ };
+ lvm_vg = {
pool = {
type = "lvm_vg";
- lvs = {
- root = {
- type = "lvm_lv";
- size = "100M";
+ lvs = {
+ root = {
+ type = "lvm_lv";
+ size = "100M";
+ lvm_type = "mirror";
+ content = {
+ type = "filesystem";
+ format = "ext4";
mountpoint = "/";
- lvm_type = "mirror";
- content = {
- type = "filesystem";
- format = "ext4";
- mountpoint = "/";
- options = [
- "defaults"
- ];
- };
+ options = [
+ "defaults"
+ ];
};
- home = {
- type = "lvm_lv";
- size = "10M";
- lvm_type = "raid0";
- content = {
- type = "filesystem";
- format = "ext4";
- mountpoint = "/home";
- };
+ };
+ 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 cb0ad91..094499d 100644
--- a/example/mdadm.nix
+++ b/example/mdadm.nix
@@ -1,39 +1,47 @@
-# usage: nix-instantiate --eval --json --strict example/config.nix | jq .
{
- type = "devices";
- content = {
+ disk = {
vdb = {
- type = "table";
- format = "gpt";
- partitions = [
- {
- type = "partition";
- part-type = "primary";
- start = "1MiB";
- end = "100%";
- content = {
- type = "mdraid";
- name = "raid1";
- };
- }
- ];
+ type = "disk";
+ device = "/dev/vdb";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ name = "mdadm";
+ start = "1MiB";
+ end = "100%";
+ content = {
+ type = "mdraid";
+ name = "raid1";
+ };
+ }
+ ];
+ };
};
vdc = {
- type = "table";
- format = "gpt";
- partitions = [
- {
- type = "partition";
- part-type = "primary";
- start = "1MiB";
- end = "100%";
- content = {
- type = "mdraid";
- name = "raid1";
- };
- }
- ];
+ type = "disk";
+ device = "/dev/vdc";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ name = "mdadm";
+ start = "1MiB";
+ end = "100%";
+ content = {
+ type = "mdraid";
+ name = "raid1";
+ };
+ }
+ ];
+ };
};
+ };
+ mdadm = {
raid1 = {
type = "mdadm";
level = 1;
@@ -43,7 +51,7 @@
partitions = [
{
type = "partition";
- part-type = "primary";
+ name = "primary";
start = "1MiB";
end = "100%";
content = {
diff --git a/example/stand-alone/configuration.nix b/example/stand-alone/configuration.nix
index 2a15c32..600f6f9 100644
--- a/example/stand-alone/configuration.nix
+++ b/example/stand-alone/configuration.nix
@@ -1,39 +1,58 @@
-{ pkgs, lib, ... }:
-let
- disko = import (builtins.fetchGit {
- url = "https://github.com/nix-community/disko";
- ref = "master";
- }) {
+{
+ pkgs,
+ lib,
+ ...
+}: let
+ # We just import from the repository for testing here:
+ diskoNixos = import ../../. {
inherit lib;
};
+ disko = import ../../. {
+ inherit lib;
+ inherit pkgs;
+ };
+ # In your own system use something like this:
+ #import (builtins.fetchGit {
+ # url = "https://github.com/nix-community/disko";
+ # ref = "master";
+ #}) {
+ # inherit lib;
+ #};
cfg = {
- type = "devices";
- content = {
+ disk = {
sda = {
- type = "table";
- format = "msdos";
- partitions = [{
- type = "partition";
- part-type = "primary";
- start = "1M";
- end = "100%";
- bootable = true;
- content = {
- type = "filesystem";
- format = "ext4";
- mountpoint = "/";
- };
- }];
+ 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)
+ (diskoNixos.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/zfs-over-legacy.nix b/example/zfs-over-legacy.nix
index 8f5a8bc..81a5975 100644
--- a/example/zfs-over-legacy.nix
+++ b/example/zfs-over-legacy.nix
@@ -1,41 +1,46 @@
{
- type = "devices";
- content = {
+ disk = {
vdb = {
- type = "table";
- format = "gpt";
- partitions = [
- {
- type = "partition";
- # leave space for the grub aka BIOS boot
- start = "0%";
- end = "100%";
- part-type = "primary";
- bootable = true;
- content = {
- type = "filesystem";
- format = "ext4";
- mountpoint = "/";
- };
- }
- ];
+ type = "disk";
+ device = "/dev/vdb";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ start = "0%";
+ end = "100%";
+ name = "primary";
+ bootable = true;
+ content = {
+ type = "filesystem";
+ format = "ext4";
+ mountpoint = "/";
+ };
+ }
+ ];
+ };
};
vdc = {
- type = "zfs";
- pool = "zroot";
+ type = "disk";
+ device = "/dev/vdc";
+ content = {
+ type = "zfs";
+ pool = "zroot";
+ };
};
+ };
+ zpool = {
zroot = {
type = "zpool";
- mountpoint = "/";
-
- datasets = [
- {
- type = "zfs_filesystem";
- name = "zfs_fs";
+ datasets = {
+ 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 60e4700..16da367 100644
--- a/example/zfs.nix
+++ b/example/zfs.nix
@@ -1,14 +1,23 @@
{
- type = "devices";
- content = {
+ disk = {
vdb = {
- type = "zfs";
- pool = "zroot";
+ type = "disk";
+ device = "/dev/vdb";
+ content = {
+ type = "zfs";
+ pool = "zroot";
+ };
};
vdc = {
- type = "zfs";
- pool = "zroot";
+ type = "disk";
+ device = "/dev/vdc";
+ content = {
+ type = "zfs";
+ pool = "zroot";
+ };
};
+ };
+ zpool = {
zroot = {
type = "zpool";
mode = "mirror";
@@ -18,35 +27,31 @@
};
mountpoint = "/";
- datasets = [
- {
- type = "zfs_filesystem";
- name = "zfs_fs";
+ datasets = {
+ zfs_fs = {
+ zfs_type = "filesystem";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
- }
- {
- type = "zfs_filesystem";
- name = "zfs_unmounted_fs";
+ };
+ zfs_unmounted_fs = {
+ zfs_type = "filesystem";
options.mountpoint = "none";
- }
- {
- type = "zfs_filesystem";
- name = "zfs_legacy_fs";
+ };
+ zfs_legacy_fs = {
+ zfs_type = "filesystem";
options.mountpoint = "legacy";
mountpoint = "/zfs_legacy_fs";
- }
- {
- type = "zfs_volume";
- name = "zfs_testvolume";
+ };
+ zfs_testvolume = {
+ zfs_type = "volume";
size = "10M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4onzfs";
};
- }
- ];
+ };
+ };
};
};
}