at 23.05-pre 2.1 kB view raw
1{ config, lib, pkgs, ... }: 2let 3 inherit (lib) literalExpression types; 4in { 5 options = { 6 ec2 = { 7 zfs = { 8 enable = lib.mkOption { 9 default = false; 10 internal = true; 11 description = lib.mdDoc '' 12 Whether the EC2 instance uses a ZFS root. 13 ''; 14 }; 15 16 datasets = lib.mkOption { 17 description = lib.mdDoc '' 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 = lib.mdDoc "Where to mount this dataset."; 31 type = types.nullOr types.string; 32 default = null; 33 }; 34 35 properties = lib.mkOption { 36 description = lib.mdDoc "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 = lib.mdDoc '' 48 Whether the EC2 instance is a HVM instance. 49 ''; 50 }; 51 efi = lib.mkOption { 52 default = pkgs.stdenv.hostPlatform.isAarch64; 53 defaultText = literalExpression "pkgs.stdenv.hostPlatform.isAarch64"; 54 internal = true; 55 description = lib.mdDoc '' 56 Whether the EC2 instance is using EFI. 57 ''; 58 }; 59 }; 60 }; 61 62 config = lib.mkIf config.ec2.zfs.enable { 63 networking.hostId = lib.mkDefault "00000000"; 64 65 fileSystems = let 66 mountable = lib.filterAttrs (_: value: ((value.mount or null) != null)) config.ec2.zfs.datasets; 67 in lib.mapAttrs' 68 (dataset: opts: lib.nameValuePair opts.mount { 69 device = dataset; 70 fsType = "zfs"; 71 }) 72 mountable; 73 }; 74}