···
-
{ config, lib, pkgs, utils, ... }:
# The scripted initrd contains some magic to add the prefix to the
# paths just in time, so we don't add it here.
-
if config.boot.initrd.systemd.enable && fs.overlay.useStage1BaseDirectories && (utils.fsNeededForBoot fs) then
# Returns a service that creates the required directories before the mount is
-
preMountService = _name: fs:
prefix = sysrootPrefix fs;
···
upperdir = prefix + fs.overlay.upperdir;
workdir = prefix + fs.overlay.workdir;
-
lib.mkIf (fs.overlay.upperdir != null)
-
"rw-${escapedMountpoint}" = {
-
requiredBy = [ mountUnit ];
-
before = [ mountUnit ];
-
DefaultDependencies = false;
-
RequiresMountsFor = "${upperdir} ${workdir}";
-
ExecStart = "${pkgs.coreutils}/bin/mkdir -p -m 0755 ${upperdir} ${workdir}";
-
overlayOpts = { config, ... }: {
-
lowerdir = lib.mkOption {
-
type = with lib.types; nullOr (nonEmptyListOf (either str pathInStore));
-
The list of path(s) to the lowerdir(s).
-
To create a writable overlay, you MUST provide an `upperdir` and a
-
You can create a read-only overlay when you provide multiple (at
-
least 2!) lowerdirs and neither an `upperdir` nor a `workdir`.
-
upperdir = lib.mkOption {
-
type = lib.types.nullOr lib.types.str;
-
The path to the upperdir.
-
If this is null, a read-only overlay is created using the lowerdir.
-
If the filesystem is `neededForBoot`, this will be prefixed with `/sysroot`,
-
unless `useStage1BaseDirectories` is set to `true`.
-
If you set this to some value you MUST also set `workdir`.
-
workdir = lib.mkOption {
-
type = lib.types.nullOr lib.types.str;
-
The path to the workdir.
-
If the filesystem is `neededForBoot`, this will be prefixed with `/sysroot`,
-
unless `useStage1BaseDirectories` is set to `true`.
-
This MUST be set if you set `upperdir`.
-
useStage1BaseDirectories = lib.mkOption {
-
If enabled, `lowerdir`, `upperdir` and `workdir` will be prefixed with `/sysroot`.
-
Disabling this can be useful to create an overlay over directories which aren't on the real root.
-
Disabling this does not work with the scripted (i.e. non-systemd) initrd.
-
config = lib.mkIf (config.overlay.lowerdir != null) {
-
device = lib.mkDefault "overlay";
-
depends = map (x: "${x}") (config.overlay.lowerdir ++ lib.optionals (config.overlay.upperdir != null) [
-
config.overlay.upperdir
-
prefix = sysrootPrefix config;
-
lowerdir = map (s: prefix + s) config.overlay.lowerdir;
-
upperdir = prefix + config.overlay.upperdir;
-
workdir = prefix + config.overlay.workdir;
-
"lowerdir=${lib.concatStringsSep ":" lowerdir}"
-
] ++ lib.optionals (config.overlay.upperdir != null) [