···
1
-
{ 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.
7
-
if config.boot.initrd.systemd.enable && fs.overlay.useStage1BaseDirectories && (utils.fsNeededForBoot fs) then
15
+
config.boot.initrd.systemd.enable
16
+
&& fs.overlay.useStage1BaseDirectories
17
+
&& (utils.fsNeededForBoot fs)
# Returns a service that creates the required directories before the mount is
14
-
preMountService = _name: fs:
prefix = sysrootPrefix fs;
···
upperdir = prefix + fs.overlay.upperdir;
workdir = prefix + fs.overlay.workdir;
24
-
lib.mkIf (fs.overlay.upperdir != null)
26
-
"rw-${escapedMountpoint}" = {
27
-
requiredBy = [ mountUnit ];
28
-
before = [ mountUnit ];
30
-
DefaultDependencies = false;
31
-
RequiresMountsFor = "${upperdir} ${workdir}";
35
-
ExecStart = "${pkgs.coreutils}/bin/mkdir -p -m 0755 ${upperdir} ${workdir}";
36
+
lib.mkIf (fs.overlay.upperdir != null) {
37
+
"rw-${escapedMountpoint}" = {
38
+
requiredBy = [ mountUnit ];
39
+
before = [ mountUnit ];
41
+
DefaultDependencies = false;
42
+
RequiresMountsFor = "${upperdir} ${workdir}";
46
+
ExecStart = "${pkgs.coreutils}/bin/mkdir -p -m 0755 ${upperdir} ${workdir}";
40
-
overlayOpts = { config, ... }: {
58
+
lowerdir = lib.mkOption {
59
+
type = with lib.types; nullOr (nonEmptyListOf (either str pathInStore));
62
+
The list of path(s) to the lowerdir(s).
64
+
To create a writable overlay, you MUST provide an `upperdir` and a
44
-
lowerdir = lib.mkOption {
45
-
type = with lib.types; nullOr (nonEmptyListOf (either str pathInStore));
48
-
The list of path(s) to the lowerdir(s).
67
+
You can create a read-only overlay when you provide multiple (at
68
+
least 2!) lowerdirs and neither an `upperdir` nor a `workdir`.
50
-
To create a writable overlay, you MUST provide an `upperdir` and a
72
+
upperdir = lib.mkOption {
73
+
type = lib.types.nullOr lib.types.str;
76
+
The path to the upperdir.
53
-
You can create a read-only overlay when you provide multiple (at
54
-
least 2!) lowerdirs and neither an `upperdir` nor a `workdir`.
78
+
If this is null, a read-only overlay is created using the lowerdir.
80
+
If the filesystem is `neededForBoot`, this will be prefixed with `/sysroot`,
81
+
unless `useStage1BaseDirectories` is set to `true`.
58
-
upperdir = lib.mkOption {
59
-
type = lib.types.nullOr lib.types.str;
62
-
The path to the upperdir.
83
+
If you set this to some value you MUST also set `workdir`.
64
-
If this is null, a read-only overlay is created using the lowerdir.
87
+
workdir = lib.mkOption {
88
+
type = lib.types.nullOr lib.types.str;
91
+
The path to the workdir.
66
-
If the filesystem is `neededForBoot`, this will be prefixed with `/sysroot`,
67
-
unless `useStage1BaseDirectories` is set to `true`.
93
+
If the filesystem is `neededForBoot`, this will be prefixed with `/sysroot`,
94
+
unless `useStage1BaseDirectories` is set to `true`.
69
-
If you set this to some value you MUST also set `workdir`.
96
+
This MUST be set if you set `upperdir`.
73
-
workdir = lib.mkOption {
74
-
type = lib.types.nullOr lib.types.str;
77
-
The path to the workdir.
100
+
useStage1BaseDirectories = lib.mkOption {
101
+
type = lib.types.bool;
104
+
If enabled, `lowerdir`, `upperdir` and `workdir` will be prefixed with `/sysroot`.
79
-
If the filesystem is `neededForBoot`, this will be prefixed with `/sysroot`,
80
-
unless `useStage1BaseDirectories` is set to `true`.
106
+
Disabling this can be useful to create an overlay over directories which aren't on the real root.
82
-
This MUST be set if you set `upperdir`.
108
+
Disabling this does not work with the scripted (i.e. non-systemd) initrd.
86
-
useStage1BaseDirectories = lib.mkOption {
87
-
type = lib.types.bool;
90
-
If enabled, `lowerdir`, `upperdir` and `workdir` will be prefixed with `/sysroot`.
113
+
config = lib.mkIf (config.overlay.lowerdir != null) {
114
+
fsType = "overlay";
115
+
device = lib.mkDefault "overlay";
116
+
depends = map (x: "${x}") (
117
+
config.overlay.lowerdir
118
+
++ lib.optionals (config.overlay.upperdir != null) [
119
+
config.overlay.upperdir
120
+
config.overlay.workdir
92
-
Disabling this can be useful to create an overlay over directories which aren't on the real root.
126
+
prefix = sysrootPrefix config;
94
-
Disabling this does not work with the scripted (i.e. non-systemd) initrd.
128
+
lowerdir = map (s: prefix + s) config.overlay.lowerdir;
129
+
upperdir = prefix + config.overlay.upperdir;
130
+
workdir = prefix + config.overlay.workdir;
133
+
"lowerdir=${lib.concatStringsSep ":" lowerdir}"
135
+
++ lib.optionals (config.overlay.upperdir != null) [
136
+
"upperdir=${upperdir}"
137
+
"workdir=${workdir}"
99
-
config = lib.mkIf (config.overlay.lowerdir != null) {
100
-
fsType = "overlay";
101
-
device = lib.mkDefault "overlay";
102
-
depends = map (x: "${x}") (config.overlay.lowerdir ++ lib.optionals (config.overlay.upperdir != null) [
103
-
config.overlay.upperdir
104
-
config.overlay.workdir
109
-
prefix = sysrootPrefix config;
111
-
lowerdir = map (s: prefix + s) config.overlay.lowerdir;
112
-
upperdir = prefix + config.overlay.upperdir;
113
-
workdir = prefix + config.overlay.workdir;
116
-
"lowerdir=${lib.concatStringsSep ":" lowerdir}"
117
-
] ++ lib.optionals (config.overlay.upperdir != null) [
118
-
"upperdir=${upperdir}"
119
-
"workdir=${workdir}"