at 23.11-pre 2.2 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.str; 32 default = null; 33 }; 34 35 properties = lib.mkOption { 36 description = lib.mdDoc "Properties to set on this dataset."; 37 type = types.attrsOf types.str; 38 default = {}; 39 }; 40 }; 41 }); 42 }; 43 }; 44 efi = lib.mkOption { 45 default = pkgs.stdenv.hostPlatform.isAarch64; 46 defaultText = literalExpression "pkgs.stdenv.hostPlatform.isAarch64"; 47 internal = true; 48 description = lib.mdDoc '' 49 Whether the EC2 instance is using EFI. 50 ''; 51 }; 52 hvm = lib.mkOption { 53 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`."; 54 internal = true; 55 default = true; 56 readOnly = true; 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}