2024-02-29 20:09:43 +00:00
|
|
|
# Overlayfs {#sec-overlayfs}
|
|
|
|
|
|
|
|
NixOS offers a convenient abstraction to create both read-only as well writable
|
|
|
|
overlays.
|
|
|
|
|
|
|
|
```nix
|
2024-04-21 15:54:59 +00:00
|
|
|
{
|
|
|
|
fileSystems = {
|
|
|
|
"/writable-overlay" = {
|
|
|
|
overlay = {
|
|
|
|
lowerdir = [ writableOverlayLowerdir ];
|
|
|
|
upperdir = "/.rw-writable-overlay/upper";
|
|
|
|
workdir = "/.rw-writable-overlay/work";
|
|
|
|
};
|
|
|
|
# Mount the writable overlay in the initrd.
|
|
|
|
neededForBoot = true;
|
2024-02-29 20:09:43 +00:00
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
"/readonly-overlay".overlay.lowerdir = [
|
|
|
|
writableOverlayLowerdir
|
|
|
|
writableOverlayLowerdir2
|
|
|
|
];
|
2024-02-29 20:09:43 +00:00
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
}
|
2024-02-29 20:09:43 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
If `upperdir` and `workdir` are not null, they will be created before the
|
|
|
|
overlay is mounted.
|
|
|
|
|
|
|
|
To mount an overlay as read-only, you need to provide at least two `lowerdir`s.
|