types: refactor into diskoLib

This commit is contained in:
lassulus 2023-05-16 13:40:03 +02:00
parent efb2016c8e
commit 22b33a4fd6
21 changed files with 146 additions and 146 deletions

View file

@ -1,52 +0,0 @@
{ 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 (config.content != null) (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 (config.content != null) (config.content._mount { dev = config.device; });
};
_config = lib.mkOption {
internal = true;
readOnly = true;
default =
lib.optional (config.content != null) (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 (config.content != null) (config.content._pkgs pkgs);
description = "Packages";
};
};
}