Merge pull request #17822 from abbradar/systemd-mounts

nixos filesystems: unify special filesystems handling
This commit is contained in:
Nikolay Amiantov
2016-08-30 22:42:19 +04:00
committed by GitHub
7 changed files with 75 additions and 59 deletions

View File

@@ -18,6 +18,8 @@ let
prioOption = prio: optionalString (prio != null) " pri=${toString prio}";
specialFSTypes = [ "proc" "sysfs" "tmpfs" "devtmpfs" "devpts" ];
fileSystemOpts = { name, config, ... }: {
options = {
@@ -97,11 +99,22 @@ let
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 (config.fsType == "tmpfs") (mkDefault config.fsType);
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
@@ -110,6 +123,13 @@ let
};
# Makes sequence of `specialMount device mountPoint options fsType` commands.
# `systemMount` should be defined in the sourcing script.
makeSpecialMounts = mounts:
pkgs.writeText "mounts.sh" (concatMapStringsSep "\n" (mount: ''
specialMount "${mount.device}" "${mount.mountPoint}" "${concatStringsSep "," mount.options}" "${mount.fsType}"
'') mounts);
in
{
@@ -131,8 +151,7 @@ in
"/bigdisk".label = "bigdisk";
}
'';
type = types.loaOf types.optionSet;
options = [ fileSystemOpts ];
type = types.loaOf (types.submodule fileSystemOpts);
description = ''
The file systems to be mounted. It must include an entry for
the root directory (<literal>mountPoint = "/"</literal>). Each
@@ -177,10 +196,14 @@ in
{ 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);
boot.supportedFilesystems = map (fs: fs.fsType) fileSystems;
@@ -211,7 +234,7 @@ in
+ " " + (if skipCheck fs then "0" else
if fs.mountPoint == "/" then "1" else "2")
+ "\n"
) fileSystems}
) (filter (fs: !fs.early) fileSystems)}
# Swap devices.
${flip concatMapStrings config.swapDevices (sw:
@@ -258,6 +281,16 @@ in
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; }) {
"/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}" ]; };
"/dev" = { fsType = "devtmpfs"; options = [ "nosuid" "strictatime" "mode=755" "size=${config.boot.devSize}" ]; };
"/dev/shm" = { fsType = "tmpfs"; options = [ "nosuid" "nodev" "strictatime" "mode=1777" "size=${config.boot.devShmSize}" ]; };
"/dev/pts" = { fsType = "devpts"; options = [ "nosuid" "noexec" "mode=620" "gid=${toString config.ids.gids.tty}" ]; };
};
};
}