nixos filesystems: move special filesystems to a dedicated option

Fixes #18159.

Changed files
+34 -28
nixos
modules
+34 -28
nixos/modules/tasks/filesystems.nix
···
specialFSTypes = [ "proc" "sysfs" "tmpfs" "devtmpfs" "devpts" ];
-
fileSystemOpts = { name, config, ... }: {
+
coreFileSystemOpts = { name, config, ... }: {
options = {
···
description = "Location of the device.";
};
-
label = mkOption {
-
default = null;
-
example = "root-partition";
-
type = types.nullOr types.str;
-
description = "Label of the device (if any).";
-
};
-
fsType = mkOption {
default = "auto";
example = "ext3";
···
apply = x: if isList x then x else lib.strings.splitString "," (builtins.trace "warning: passing a comma-separated string for filesystem options is deprecated; use a list of strings instead. This will become a hard error in 16.09." x);
});
+
};
+
+
config = {
+
mountPoint = mkDefault name;
+
device = mkIf (elem config.fsType specialFSTypes) (mkDefault config.fsType);
+
};
+
+
};
+
+
fileSystemOpts = { config, ... }: {
+
+
options = {
+
+
label = mkOption {
+
default = null;
+
example = "root-partition";
+
type = types.nullOr types.str;
+
description = "Label of the device (if any).";
+
};
+
autoFormat = mkOption {
default = false;
type = types.bool;
···
description = "Disable running fsck on this filesystem.";
};
-
early = mkOption {
-
default = false;
-
type = types.bool;
-
internal = true;
-
description = ''
-
Mount this filesystem very early during boot. At the moment of
-
mounting no disks are exposed, so this option is primarily for
-
special file systems.
-
'';
-
};
-
};
config = {
-
mountPoint = mkDefault name;
-
device = mkIf (elem config.fsType specialFSTypes) (mkDefault config.fsType);
options = mkIf config.autoResize [ "x-nixos.autoresize" ];
# -F needed to allow bare block device without partitions
···
"/bigdisk".label = "bigdisk";
}
'';
-
type = types.loaOf (types.submodule fileSystemOpts);
+
type = types.loaOf (types.submodule [coreFileSystemOpts fileSystemOpts]);
description = ''
The file systems to be mounted. It must include an entry for
the root directory (<literal>mountPoint = "/"</literal>). Each
···
description = "Names of supported filesystem types.";
};
+
boot.specialFileSystems = mkOption {
+
default = {};
+
type = types.loaOf (types.submodule coreFileSystemOpts);
+
internal = true;
+
description = ''
+
Special filesystems that are mounted very early during boot.
+
'';
+
};
+
};
···
{ assertion = ! (fileSystems' ? "cycle");
message = "The ‘fileSystems’ option can't be topologically sorted: mountpoint dependency path ${ls " -> " fileSystems'.cycle} loops to ${ls ", " fileSystems'.loops}";
}
-
{ assertion = all (x: !x.early || (x.label == null && !x.autoFormat && !x.autoResize)) fileSystems;
-
message = "Early filesystems don't support mounting by label, auto formatting and resizing";
-
}
];
# Export for use in other modules
system.build.fileSystems = fileSystems;
-
system.build.earlyMountScript = makeSpecialMounts (filter (fs: fs.early) fileSystems);
+
system.build.earlyMountScript = makeSpecialMounts (toposort fsBefore (attrValues config.boot.specialFileSystems)).result;
boot.supportedFilesystems = map (fs: fs.fsType) fileSystems;
···
+ " " + (if skipCheck fs then "0" else
if fs.mountPoint == "/" then "1" else "2")
+ "\n"
-
) (filter (fs: !fs.early) fileSystems)}
+
) fileSystems}
# Swap devices.
${flip concatMapStrings config.swapDevices (sw:
···
in listToAttrs (map formatDevice (filter (fs: fs.autoFormat) fileSystems));
# Sync mount options with systemd's src/core/mount-setup.c: mount_table.
-
fileSystems = mapAttrs (n: fs: fs // { early = true; }) {
+
boot.specialFileSystems = {
"/proc" = { fsType = "proc"; options = [ "nosuid" "noexec" "nodev" ]; };
"/sys" = { fsType = "sysfs"; options = [ "nosuid" "noexec" "nodev" ]; };
"/run" = { fsType = "tmpfs"; options = [ "nosuid" "nodev" "strictatime" "mode=755" "size=${config.boot.runSize}" ]; };