|
| 1 | +{ config, options, diskoLib, lib, rootMountPoint, parent, device, ... }: |
| 2 | +{ |
| 3 | + options = { |
| 4 | + type = lib.mkOption { |
| 5 | + type = lib.types.enum [ "bcachefs" ]; |
| 6 | + internal = true; |
| 7 | + description = "Type"; |
| 8 | + }; |
| 9 | + device = lib.mkOption { |
| 10 | + type = lib.types.str; |
| 11 | + default = device; |
| 12 | + description = "Device to use"; |
| 13 | + }; |
| 14 | + extraArgs = lib.mkOption { |
| 15 | + type = lib.types.listOf lib.types.str; |
| 16 | + default = [ ]; |
| 17 | + description = "Extra arguments"; |
| 18 | + }; |
| 19 | + keyFile = lib.mkOption { |
| 20 | + type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname; |
| 21 | + default = null; |
| 22 | + description = "Path to the key for encryption"; |
| 23 | + example = "/tmp/disk.key"; |
| 24 | + }; |
| 25 | + mountOptions = lib.mkOption { |
| 26 | + type = lib.types.listOf lib.types.str; |
| 27 | + default = [ "defaults" ]; |
| 28 | + description = "A list of options to pass to mount."; |
| 29 | + }; |
| 30 | + mountpoint = lib.mkOption { |
| 31 | + type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname; |
| 32 | + default = null; |
| 33 | + description = "A path to mount the Bcachefs filesystem to."; |
| 34 | + }; |
| 35 | + _parent = lib.mkOption { |
| 36 | + internal = true; |
| 37 | + default = parent; |
| 38 | + }; |
| 39 | + _meta = lib.mkOption { |
| 40 | + internal = true; |
| 41 | + readOnly = true; |
| 42 | + type = lib.types.functionTo diskoLib.jsonType; |
| 43 | + default = dev: { }; |
| 44 | + description = "Metadata"; |
| 45 | + }; |
| 46 | + _create = diskoLib.mkCreateOption { |
| 47 | + inherit config options; |
| 48 | + default = '' |
| 49 | + bcachefs format ${config.device} ${toString config.extraArgs} |
| 50 | + ''; |
| 51 | + }; |
| 52 | + _mount = diskoLib.mkMountOption { |
| 53 | + inherit config options; |
| 54 | + default = { |
| 55 | + fs = lib.optionalAttrs (config.mountpoint != null) { |
| 56 | + ${config.mountpoint} = '' |
| 57 | + if ! findmnt ${config.device} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then |
| 58 | + mount -t bcachefs ${config.device} "${rootMountPoint}${config.mountpoint}" \ |
| 59 | + ${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ |
| 60 | + -o X-mount.mkdir |
| 61 | + fi |
| 62 | + ''; |
| 63 | + }; |
| 64 | + }; |
| 65 | + }; |
| 66 | + _config = lib.mkOption { |
| 67 | + internal = true; |
| 68 | + readOnly = true; |
| 69 | + default = [ |
| 70 | + (lib.optional (config.mountpoint != null) { |
| 71 | + fileSystems.${config.mountpoint} = { |
| 72 | + device = config.device; |
| 73 | + fsType = "bcachefs"; |
| 74 | + options = config.mountOptions; |
| 75 | + }; |
| 76 | + }) |
| 77 | + ]; |
| 78 | + description = "NixOS configuration"; |
| 79 | + }; |
| 80 | + _pkgs = lib.mkOption { |
| 81 | + internal = true; |
| 82 | + readOnly = true; |
| 83 | + type = lib.types.functionTo (lib.types.listOf lib.types.package); |
| 84 | + default = pkgs: |
| 85 | + [ pkgs.bcachefs-tools pkgs.coreutils ]; |
| 86 | + description = "Packages"; |
| 87 | + }; |
| 88 | + }; |
| 89 | +} |
0 commit comments