disko/lib/types/nodev.nix

73 lines
2.1 KiB
Nix
Raw Normal View History

2023-05-16 14:40:03 +03:00
{ lib, config, options, diskoLib, rootMountPoint, ... }:
2023-01-28 18:19:13 +03:00
{
options = {
type = lib.mkOption {
type = lib.types.enum [ "nodev" ];
default = "nodev";
internal = true;
description = "Device type";
};
fsType = lib.mkOption {
type = lib.types.str;
description = "File system type";
};
device = lib.mkOption {
type = lib.types.str;
default = "none";
description = "Device to use";
};
mountpoint = lib.mkOption {
2023-05-16 14:40:03 +03:00
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
2023-01-28 18:19:13 +03:00
default = config._module.args.name;
description = "Location to mount the file system at";
};
mountOptions = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "defaults" ];
description = "Options to pass to mount";
};
_meta = lib.mkOption {
internal = true;
readOnly = true;
type = diskoLib.jsonType;
default = { };
description = "Metadata";
};
_create = diskoLib.mkCreateOption {
inherit config options;
default = "";
2023-01-28 18:19:13 +03:00
};
_mount = diskoLib.mkMountOption {
inherit config options;
default = lib.optionalAttrs (config.mountpoint != null) {
2023-01-28 18:19:13 +03:00
fs.${config.mountpoint} = ''
if ! findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
mount -t ${config.fsType} ${config.device} "${rootMountPoint}${config.mountpoint}" \
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir
fi
'';
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
default = lib.optional (config.mountpoint != null) {
2023-01-28 18:19:13 +03:00
fileSystems.${config.mountpoint} = {
device = config.device;
fsType = config.fsType;
2023-01-28 18:19:13 +03:00
options = config.mountOptions;
};
};
2023-01-28 18:19:13 +03:00
description = "NixOS configuration";
};
_pkgs = lib.mkOption {
internal = true;
readOnly = true;
type = lib.types.functionTo (lib.types.listOf lib.types.package);
2023-06-06 14:32:47 +03:00
default = _pkgs: [ ];
2023-01-28 18:19:13 +03:00
description = "Packages";
};
};
}