From c9d3bc37553140444ad51df29a231aece29f97ea Mon Sep 17 00:00:00 2001 From: dylan madisetti Date: Mon, 26 Aug 2024 14:00:44 -0400 Subject: [PATCH] fix: properly apply oneOf --- example/zfs-with-vdevs.nix | 2 +- example/zfs.nix | 1 + lib/types/zfs.nix | 1 - lib/types/zpool.nix | 131 +++++++++++++++++++------------------ 4 files changed, 69 insertions(+), 66 deletions(-) diff --git a/example/zfs-with-vdevs.nix b/example/zfs-with-vdevs.nix index caaa4a0..a61680a 100644 --- a/example/zfs-with-vdevs.nix +++ b/example/zfs-with-vdevs.nix @@ -90,7 +90,7 @@ special = { members = [ "z" ]; }; - cache = "cache"; + cache = [ "cache" ]; }; }; diff --git a/example/zfs.nix b/example/zfs.nix index 4d09061..933386a 100644 --- a/example/zfs.nix +++ b/example/zfs.nix @@ -100,3 +100,4 @@ }; }; } + diff --git a/lib/types/zfs.nix b/lib/types/zfs.nix index 2b43623..9aa8577 100644 --- a/lib/types/zfs.nix +++ b/lib/types/zfs.nix @@ -53,4 +53,3 @@ }; }; } - diff --git a/lib/types/zpool.nix b/lib/types/zpool.nix index 858f456..2ddbb0e 100644 --- a/lib/types/zpool.nix +++ b/lib/types/zpool.nix @@ -25,72 +25,75 @@ in }; mode = lib.mkOption { default = ""; - type = (lib.types.enum modeOptions) // (lib.types.attrsOf (diskoLib.subType { - types = { - topology = - let - vdev = lib.types.submodule ({ name, ... }: { - options = { - mode = lib.mkOption { - type = lib.types.enum modeOptions; - default = ""; - description = "Mode of the zfs vdev"; + type = (lib.types.oneOf [ + (lib.types.enum modeOptions) + (lib.types.attrsOf (diskoLib.subType { + types = { + topology = + let + vdev = lib.types.submodule ({ name, ... }: { + options = { + mode = lib.mkOption { + type = lib.types.enum modeOptions; + default = ""; + description = "Mode of the zfs vdev"; + }; + members = lib.mkOption { + type = lib.types.listOf lib.types.str; + description = "Members of the vdev"; + }; }; - members = lib.mkOption { - type = lib.types.listOf lib.types.str; - description = "Members of the vdev"; + }); + parent = config; + in + lib.types.submodule + ({ config, name, ... }: { + options = { + type = lib.mkOption { + type = lib.types.enum [ "topology" ]; + default = "topology"; + internal = true; + description = "Type"; + }; + # zfs device types + vdev = lib.mkOption { + type = lib.types.listOf vdev; + default = [ ]; + description = '' + A list of storage vdevs. See + https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Virtual_Devices_(vdevs) + for details. + ''; + example = [{ + mode = "mirror"; + members = [ "x" "y" "/dev/sda1" ]; + }]; + }; + special = lib.mkOption { + type = lib.types.nullOr vdev; + default = null; + description = '' + A vdev definition for a special device. See + https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#special + for details. + ''; + }; + cache = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = null; + description = '' + A dedicated zfs cache device (L2ARC). See + https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Cache_Devices + for details. + ''; + }; + # TODO: Consider supporting log, spare, and dedup options. }; - }; - }); - parent = config; - in - lib.types.submodule - ({ config, name, ... }: { - options = { - type = lib.mkOption { - type = lib.types.enum [ "topology" ]; - default = "topology"; - internal = true; - description = "Type"; - }; - # zfs device types - vdev = lib.mkOption { - type = lib.types.listOf vdev; - default = [ ]; - description = '' - A list of storage vdevs. See - https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Virtual_Devices_(vdevs) - for details. - ''; - example = [{ - mode = "mirror"; - members = [ "x" "y" "/dev/sda1" ]; - }]; - }; - special = lib.mkOption { - type = lib.types.nullOr vdev; - default = null; - description = '' - A vdev definition for a special device. See - https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#special - for details. - ''; - }; - cache = lib.mkOption { - type = lib.types.listOf lib.types.str; - default = null; - description = '' - A dedicated zfs cache device (L2ARC). See - https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Cache_Devices - for details. - ''; - }; - # TODO: Consider supporting log, spare, and dedup options. - }; - }); - }; - extraArgs.parent = config; - })); + }); + }; + extraArgs.parent = config; + })) + ]); description = "Mode of the ZFS pool"; }; options = lib.mkOption {