1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 inherit (lib) literalExpression types;
9in
10{
11 options = {
12 ec2 = {
13 zfs = {
14 enable = lib.mkOption {
15 default = false;
16 internal = true;
17 description = ''
18 Whether the EC2 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 efi = lib.mkOption {
53 default = pkgs.stdenv.hostPlatform.isAarch64;
54 defaultText = literalExpression "pkgs.stdenv.hostPlatform.isAarch64";
55 internal = true;
56 description = ''
57 Whether the EC2 instance is using EFI.
58 '';
59 };
60 hvm = lib.mkOption {
61 description = "Unused legacy option. While support for non-hvm has been dropped, we keep this option around so that NixOps remains compatible with a somewhat recent `nixpkgs` and machines with an old `stateVersion`.";
62 internal = true;
63 default = true;
64 readOnly = true;
65 };
66 };
67 };
68
69 config = lib.mkIf config.ec2.zfs.enable {
70 networking.hostId = lib.mkDefault "00000000";
71
72 fileSystems =
73 let
74 mountable = lib.filterAttrs (_: value: ((value.mount or null) != null)) config.ec2.zfs.datasets;
75 in
76 lib.mapAttrs' (
77 dataset: opts:
78 lib.nameValuePair opts.mount {
79 device = dataset;
80 fsType = "zfs";
81 }
82 ) mountable;
83 };
84}