disko/lib/types/nodev.nix
Bert Proesmans fa7a23d0ef fix(nodev); Set device default to fstype config
The value for device is copied into the SOURCE column of findmnt.
By default this is "none". The mount and unmount scripts
branch on SOURCE=fsType specifically, and the existence of "none"
in the SOURCE column causes wrong branches to be executed.
For a list of special filesystems, the default value "none"
is replaced by the value for fsType.
2025-11-20 14:10:46 +00:00

103 lines
2.8 KiB
Nix

{
lib,
config,
options,
diskoLib,
rootMountPoint,
...
}:
let
# REF; nixos/modules/tasks/filesystems.nix
specialFSTypes = [
"proc"
"sysfs"
"tmpfs"
"ramfs"
"devtmpfs"
"devpts"
];
in
{
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 {
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
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 = "";
};
_mount = diskoLib.mkMountOption {
inherit config options;
default = lib.optionalAttrs (config.mountpoint != null) {
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
'';
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default = lib.optionalAttrs (config.mountpoint != null) {
fs.${config.mountpoint} = ''
if findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
umount "${rootMountPoint}${config.mountpoint}"
fi
'';
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
default = lib.optional (config.mountpoint != null) {
fileSystems.${config.mountpoint} = {
device = config.device;
fsType = config.fsType;
options = config.mountOptions;
};
};
description = "NixOS configuration";
};
_pkgs = lib.mkOption {
internal = true;
readOnly = true;
type = lib.types.functionTo (lib.types.listOf lib.types.package);
default = _pkgs: [ ];
description = "Packages";
};
};
config = {
device = lib.mkIf (lib.elem config.fsType specialFSTypes) (lib.mkDefault config.fsType);
};
}