disko/types/disk.nix
2023-01-29 08:10:33 +01:00

53 lines
1.6 KiB
Nix

{ config, options, lib, diskoLib, optionTypes, ... }:
{
options = {
name = lib.mkOption {
type = lib.types.str;
default = config._module.args.name;
description = "Device name";
};
type = lib.mkOption {
type = lib.types.enum [ "disk" ];
default = "disk";
internal = true;
description = "Type";
};
device = lib.mkOption {
type = optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
description = "Device path";
};
content = diskoLib.deviceType;
_meta = lib.mkOption {
internal = true;
readOnly = true;
type = diskoLib.jsonType;
default =
lib.optionalAttrs (!isNull config.content) (config.content._meta [ "disk" config.device ]);
description = "Metadata";
};
_create = diskoLib.mkCreateOption {
inherit config options;
default = {}: config.content._create { dev = config.device; };
};
_mount = diskoLib.mkMountOption {
inherit config options;
default = {}:
lib.optionalAttrs (!isNull config.content) (config.content._mount { dev = config.device; });
};
_config = lib.mkOption {
internal = true;
readOnly = true;
default =
lib.optional (!isNull config.content) (config.content._config config.device);
description = "NixOS configuration";
};
_pkgs = lib.mkOption {
internal = true;
readOnly = true;
type = lib.types.functionTo (lib.types.listOf lib.types.package);
default = pkgs: [ pkgs.jq ] ++ lib.optionals (!isNull config.content) (config.content._pkgs pkgs);
description = "Packages";
};
};
}