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