1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 inherit (lib) literalExpression types;
9in
10{
11 options = {
12 openstack = {
13 zfs = {
14 enable = lib.mkOption {
15 default = false;
16 internal = true;
17 description = ''
18 Whether the OpenStack instance uses a ZFS root.
19 '';
20 };
21
22 datasets = lib.mkOption {
23 description = ''
24 Datasets to create under the `tank` and `boot` zpools.
25
26 **NOTE:** This option is used only at image creation time, and
27 does not attempt to declaratively create or manage datasets
28 on an existing system.
29 '';
30
31 default = { };
32
33 type = types.attrsOf (
34 types.submodule {
35 options = {
36 mount = lib.mkOption {
37 description = "Where to mount this dataset.";
38 type = types.nullOr types.str;
39 default = null;
40 };
41
42 properties = lib.mkOption {
43 description = "Properties to set on this dataset.";
44 type = types.attrsOf types.str;
45 default = { };
46 };
47 };
48 }
49 );
50 };
51 };
52
53 efi = lib.mkOption {
54 default = pkgs.stdenv.hostPlatform.isAarch64;
55 defaultText = literalExpression "pkgs.stdenv.hostPlatform.isAarch64";
56 internal = true;
57 description = ''
58 Whether the instance is using EFI.
59 '';
60 };
61 };
62 };
63
64 config = lib.mkIf config.openstack.zfs.enable {
65 networking.hostId = lib.mkDefault "00000000";
66
67 fileSystems =
68 let
69 mountable = lib.filterAttrs (
70 _: value: ((value.mount or null) != null)
71 ) config.openstack.zfs.datasets;
72 in
73 lib.mapAttrs' (
74 dataset: opts:
75 lib.nameValuePair opts.mount {
76 device = dataset;
77 fsType = "zfs";
78 }
79 ) mountable;
80 };
81}