Merge pull request #171 from nix-community/nullable-mountpoints

This commit is contained in:
Lassulus 2023-03-13 13:22:24 +07:00 committed by GitHub
commit a683b848c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -17,7 +17,8 @@
description = "Options to pass to mount";
};
mountpoint = lib.mkOption {
type = optionTypes.absolute-pathname;
type = lib.types.nullOr optionTypes.absolute-pathname;
default = null;
description = "Path to mount the filesystem to";
};
format = lib.mkOption {
@ -41,7 +42,7 @@
};
_mount = diskoLib.mkMountOption {
inherit config options;
default = { dev }: {
default = { dev }: lib.optionalAttrs (config.mountpoint != null) {
fs.${config.mountpoint} = ''
if ! findmnt ${dev} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
mount ${dev} "${rootMountPoint}${config.mountpoint}" \
@ -55,13 +56,13 @@
_config = lib.mkOption {
internal = true;
readOnly = true;
default = dev: [{
default = dev: lib.optional (config.mountpoint != null) {
fileSystems.${config.mountpoint} = {
device = dev;
fsType = config.format;
options = config.mountOptions;
};
}];
};
description = "NixOS configuration";
};
_pkgs = lib.mkOption {

View File

@ -17,7 +17,7 @@
description = "Device to use";
};
mountpoint = lib.mkOption {
type = optionTypes.absolute-pathname;
type = lib.types.nullOr optionTypes.absolute-pathname;
default = config._module.args.name;
description = "Location to mount the file system at";
};
@ -39,7 +39,7 @@
};
_mount = diskoLib.mkMountOption {
inherit config options;
default = _: {
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}" \
@ -52,13 +52,13 @@
_config = lib.mkOption {
internal = true;
readOnly = true;
default = [{
default = lib.optional (config.mountpoint != null) {
fileSystems.${config.mountpoint} = {
device = config.device;
fsType = config.fsType;
options = config.mountOptions;
};
}];
};
description = "NixOS configuration";
};
_pkgs = lib.mkOption {