From 826e5e8ef5ca9ddc9660dbe7172c13974ceaa1e0 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Sun, 5 May 2024 04:29:10 -0400 Subject: [PATCH] lib/disko: init --- lib/default.nix | 4 +++- lib/disko.nix | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 lib/disko.nix diff --git a/lib/default.nix b/lib/default.nix index 7c52ed8..4273baa 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -65,4 +65,6 @@ rec { import ./hosts.nix { inherit lib; } ) // ( import ./options.nix { inherit lib; } -)) +)) // { + disko = import ./disko.nix { inherit lib; }; +} diff --git a/lib/disko.nix b/lib/disko.nix new file mode 100644 index 0000000..10d778e --- /dev/null +++ b/lib/disko.nix @@ -0,0 +1,56 @@ +{ lib }: +rec { + # Constants + + defaultMountOptions = [ + "defaults" + "noatime" + ]; + + # Common + + mkDisk = id: content: { + type = "disk"; + device = "/dev/disk/by-id/${id}"; + content = { + type = "gpt"; + } // content; + }; + + # ZFS + + mkZDisk = id: pool: mkDisk id { + partitions = { + zfs = { + size = "100%"; + content = { + type = "zfs"; + inherit pool; + }; + }; + }; + }; + + mkZPool' = mountOptions: name: options: { + type = "zpool"; + mode = "raidz"; + mountpoint = "/media/${name}"; + rootFsOptions = { + compression = "zstd"; + atime = "off"; + }; + inherit mountOptions; + } // options; + mkZPool = mkZPool' defaultMountOptions; + + mkZfs' = mountOptions: mountpoint: options: { + type = "zfs_fs"; + inherit mountpoint mountOptions options; + }; + mkZfs = mkZfs' defaultMountOptions; + + mkZvol = size: content: { + type = "zfs_volume"; + inherit size content; + }; +}